Question

Specification Modify a Java application that prints the value of the mathematical constant Pi. Copy the...

Specification

Modify a Java application that prints the value of the mathematical constant Pi.

Copy the PiDay.java program and do the following:

  • implement the abstract methods that are declared in abstract class Number;
  • implement the two methods marked "TBI (To Be Implemented)" in PiDay.java;
  • answer the three questions/exercises presented in the program's file comment block.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

/*
 * PiDay is-a a Number.
 *
 * @creator gdt
 * @created 02017.02.26
 * @updated 02019.01.30
 *
 * Answer the following questions here in this file comment block
 * prior to submitting this file to the instructor.
 *
 * (0) No or Yes: PiDay objects are immutable.  
 *     REPLACE_THIS_TEXT_WITH_YOUR_ANSWER
 *
 * (1) Record what the expression  (new PiDay().getPi() == PiDay.PI)
 *     evaluates to and briefly explain why.
 *     REPLACE_THIS_TEXT_WITH_YOUR_ANSWER
 *
 * (2) Briefly explain why the  byteValue()  and  shortValue()
 *     methods that are defined in abstract class Number
 *     did not need to be implemented in class PiDay.
 *     REPLACE_THIS_TEXT_WITH_YOUR_ANSWER
 */

public class PiDay extends Number {

   private final static double PI = 3.14159265358979323846264338327950;
   private int intValue;        // PI rounded down to nearest int
   private long longValue;      // PI rounded up to nearest int
   private float floatValue;    // PI stored as a float
   private double doubleValue;  


   /*
    * TBI (To Be Implemented)
    * The constructor assigns values to all of the instance 
    * variables defined above. The values that are assigned
    * to the instance variables are documented using comments
    * when the instance variables are defined.
    */
   public PiDay() {
      // the expressions on the right side of each of the following 
      // assignment expression statements must use PI in them...
      intValue = ;
      longValue = ;
      floatValue = ;
      doubleValue = ;
   }

   /*
    * TBI (To Be Implemented)
    * Returns a String representation of this Pi object
    * that is used as the output of this progam.
    */
   public String toString() {
   }

   /*  
    * The main() and getPi() methods cannot be modified.
    */
   public static void main(String[] argv) {
      System.out.println(new PiDay());
   }

   public double getPi() { return doubleValue; }


}

/*
 * the output of your program must match the following
 *

byteValue():  3
shortValue():  3
intValue():  3
longValue():  4
floatValue():  3.1415927
doubleValue():  3.141592653589793

 *
 */

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The output of your program must match the following:

byteValue():  3
shortValue():  3
intValue():  3
longValue():  4
floatValue():  3.1415927
doubleValue():  3.141592653589793
0 0
Add a comment Improve this question Transcribed image text
Answer #1
/*
 * PiDay is-a a Number.
 *
 * @creator gdt
 * @created 02017.02.26
 * @updated 02019.01.30
 *
 * Answer the following questions here in this file comment block
 * prior to submitting this file to the instructor.
 *
 * (0) No or Yes: PiDay objects are immutable.
 *     REPLACE_THIS_TEXT_WITH_YOUR_ANSWER
 *
 * (1) Record what the expression  (new PiDay().getPi() == PiDay.PI)
 *     evaluates to and briefly explain why.
 *     REPLACE_THIS_TEXT_WITH_YOUR_ANSWER
 *
 * (2) Briefly explain why the  byteValue()  and  shortValue()
 *     methods that are defined in abstract class Number
 *     did not need to be implemented in class PiDay.
 *     REPLACE_THIS_TEXT_WITH_YOUR_ANSWER
 */

public class PiDay extends Number {

    private final static double PI = 3.14159265358979323846264338327950;
    private int intValue;        // PI rounded down to nearest int
    private long longValue;      // PI rounded up to nearest int
    private float floatValue;    // PI stored as a float
    private double doubleValue;


    /*
     * TBI (To Be Implemented)
     * The constructor assigns values to all of the instance
     * variables defined above. The values that are assigned
     * to the instance variables are documented using comments
     * when the instance variables are defined.
     */
    public PiDay() {
        // the expressions on the right side of each of the following
        // assignment expression statements must use PI in them...
        intValue = (int) PI;
        longValue = (long) Math.ceil(PI);
        floatValue = (float) PI;
        doubleValue = PI;
    }

    @Override
    public int intValue() {
        return intValue;
    }

    @Override
    public long longValue() {
        return longValue;
    }

    @Override
    public float floatValue() {
        return floatValue;
    }

    @Override
    public double doubleValue() {
        return doubleValue;
    }

    /*
     * TBI (To Be Implemented)
     * Returns a String representation of this Pi object
     * that is used as the output of this progam.
     */
    public String toString() {
        return "byteValue():  " + byteValue() + "\n" +
                "shortValue():  " + shortValue() + "\n" +
                "intValue():  " + intValue() + "\n" +
                "longValue():  " + longValue() + "\n" +
                "floatValue():  " + floatValue() + "\n" +
                "doubleValue():  " + doubleValue();
    }

    /*
     * The main() and getPi() methods cannot be modified.
     */
    public static void main(String[] argv) {
        System.out.println(new PiDay());
    }

    public double getPi() {
        return doubleValue;
    }


}

/*
 * the output of your program must match the following
 *

byteValue():  3
shortValue():  3
intValue():  3
longValue():  4
floatValue():  3.1415927
doubleValue():  3.141592653589793

 *
 */
Add a comment
Know the answer?
Add Answer to:
Specification Modify a Java application that prints the value of the mathematical constant Pi. Copy the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Copy the program AmusementRide.java to your computer and add your own class that extends class AmusementRide....

    Copy the program AmusementRide.java to your computer and add your own class that extends class AmusementRide. Note: AmusementRide.java contains two classes (class FerrisWheel and class RollerCoaster) that provide examples for the class you must create. Your class must include the following. Implementations for all of the abstract methods defined in abstract class AmusementRide. At least one static class variable and at least one instance variable that are not defined in abstract class AmusementRide. Override the inherited repair() method following the...

  • Question 1 1 pts Which of the following is not a valid class name in Java?...

    Question 1 1 pts Which of the following is not a valid class name in Java? O MyClass MyClass1 My_Class MyClass# Question 2 1 pts Which of the following statements is False about instance variables and methods? Instance variables are usually defined with private access modifier. Instance variables are defined inside instance methods. Instance methods are invoked on an object of the class that contains the methods. A class can have more than one instance variables and methods. Question 3...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • The current code I have is the following: package uml; public class uml {        public...

    The current code I have is the following: package uml; public class uml {        public static void main(String[] args) {              // TODO Auto-generated method stub        } } class Account { private String accountID; public Account(String accountID) { this.accountID = accountID; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID = accountID; } @Override public String toString() { return "Account [accountID=" + accountID + "]"; } } class SuppliesAccount extends Account { private...

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...

  • In Java, Implement a class MyArray as defined below, to store an array of integers (int)....

    In Java, Implement a class MyArray as defined below, to store an array of integers (int). Many of its methods will be implemented using the principle of recursion. Users can create an object by default, in which case, the array should contain enough space to store 10 integer values. Obviously, the user can specify the size of the array s/he requires. Users may choose the third way of creating an object of type MyArray by making a copy of another...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text...

    (JAVA) Use the Pet.java program from the original problem (down below) Compile it. Create a text file named pets10.txt with 10 pets (or use the one below). Store this file in the same folder as your “class” file(s). The format is the same format used in the original homework problem. Each line in the file should contain a pet name (String), a comma, a pet’s age (int) in years, another comma, and a pet’s weight (double) in pounds. Perform the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT