Question: 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
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
