Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is the third time I\'ve asked this question. READ. THE. DIRECTIONS. PLEASE.

ID: 3730072 • Letter: T

Question

This is the third time I've asked this question. READ. THE. DIRECTIONS. PLEASE. Answers that DO NOT ANSWER what is CLEARLY outlined below will be downvoted!

Copy the program Pi.java to your computer and do the following.

-Implement the abstract methods defined in Oracle.com::class Number. (Link right below) https://docs.oracle.com/javase/8/docs/api/java/lang/Number.html

-Implement the public PI() constructor method following the instructions given in the method's comment block.

-Implement the public double tauValue() method following the instructions given in the method's comment block.

-Modify the toString() method following the instructions given in the method's comment block.

-Answer the three questions given in the program's file comment block.

The output of your program must match the following.

PROGRAM LOCATED HERE: http://azfoo.net/gdt/csc205/assignments/02018/Pi.java.txt

Explanation / Answer

/*

* Pi is a Number (albeit irrational and transcendental).

* Answer the following questions here in this file comment block

* prior to submitting this file to the instructor.

*

* (0) No or Yes: PI objects are immutable. Justify your answer.

*

* RECORD_YOUR_ANSWER_HERE

*

* (1) The byteValue() and shortValue() are not abstract methods

* in class Number. Briefly explain why they were able to be

* defined (implemented) inside class Number.

*

* RECORD_YOUR_ANSWER_HERE

*

* (2) Briefly explain why the last line of this program's

* output is the word "false".

*

* RECORD_YOUR_ANSWER_HERE

*

* (3) Briefly explain why Pi rounded to the nearest 100th in

* base-10 (i.e. 3.14) equals 11.001001 in base-2 rounded

* to the nearest 64th.

*

* RECORD_YOUR_ANSWER_HERE

*

* (4) Briefly explain why 3.14 in base-10 is approximately

* equal to 11.0010001 in base-2.

*

* RECORD_YOUR_ANSWER_HERE

*/

public class Pi extends Number {

   private final static double PI = 3.14159265358979323846264338327950;

   private final int intValue; // PI rounded down to nearest int

   private final long longValue; // PI rounded up to nearest int

   private final double floatValue; // PI rounded to nearest hundredth

   private final double doubleValue; // PI rounded to nearest millionth

   private final double tauValue; // two Pi

   /*

   * TBI (To Be Implemented)...

   *

   * The constructor assigns values to all of the instance

   * variables defined above. The values assigned to the instance

   * variables are documented using comments when the instance

   * variables are defined (see above).

   */

   public Pi() {

       // implementation note: The expressions on the right side of

       // the first four assignment statements must use PI in them.

       // In addition, you are prohibited from using class Math methods.

       intValue = (int)PI;

       longValue = (long)PI;

       floatValue = (float)PI;

       doubleValue = PI;

       tauValue = 2*doubleValue; // tauValue is a multiple of doubleValue

   }

   /*

   * Creates a String representation of this Pi object.

   *

   * @return a String representation of this Pi object

   *

   * TBI (To Be Implemented)...

   *

   * Rewrite the toString() method so that a StringBuffer object

   * is used to create the string respresentation of this Pi object.

   */

   public String toString() {

       return "byteValue(): " + byteValue() +

               " shortValue(): " + shortValue() +

               " intValue(): " + intValue() +

               " longValue(): " + longValue() +

               " floatValue(): " + floatValue() +

               " doubleValue(): " + doubleValue() +

               " tauValue(): " + tauValue();

   }

   /*

   * TBI (To Be Implemented)...

   *

   * Implement the abstract methods defined in class Number.

   */

   /*

   * TBI (To Be Implemented)...

   *

   * Implement the tauValue() getter method.

   *

   * @return the tauValue instance variable

   */

   double tauValue() {

       return 2*doubleValue();

   }

   /*

   * The main() method is used to test class Pi.

   * You are prohibited from modifying main().

   */

   public static void main(String[] argv) {

       System.out.println(new Pi());

       System.out.println(new Pi() == new Pi());

   }

   @Override

   public int intValue() {

       // TODO Auto-generated method stub

       return (int)PI;

   }

   @Override

   public long longValue() {

       // TODO Auto-generated method stub

       return (long)PI;

   }

   @Override

   public float floatValue() {

       // TODO Auto-generated method stub

       return (float)PI;

   }

   @Override

   public double doubleValue() {

       // TODO Auto-generated method stub

       return PI;

   }

}

/*

* the output of your program must match the following

*

byteValue(): 3

shortValue(): 3

intValue(): 3

longValue(): 4

floatValue(): 3.14

doubleValue(): 3.14159

tauValue(): 6.28318

false

*

*/

/*

Sample run:

byteValue(): 3

shortValue(): 3

intValue(): 3

longValue(): 3

floatValue(): 3.1415927

doubleValue(): 3.141592653589793

tauValue(): 6.283185307179586

false

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote