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

What you need to do: In the same class that includes the main method write and t

ID: 3758217 • Letter: W

Question

What you need to do: In the same class that includes the main method write and test a method with the following method header: boolean static golenRatio (int n1, int n2) The method goldenRatio returns true if the quotient of the greater number divided by the smaller number - rounded to 3 decimal digits - equals 1.618 Otherwise it returns false. Test the method goldenRatio in main. That means: call it with a number pair that is a golden ratio and verity that it returns true. Then call it with a number pair that is NOT a golden ratio (e.g. 4 and 5) and verify that the answer is false. Hint: How to round a number x to 3 digits after the decimal point: x = Math.round(x * 1000) / 1000d; // notice the d at the end; can you guess why we need it? FYI: More general as a method: How to round a number x to n digits after the decimal point: double round (double x, int n) { double factor = Math.pow(10, n); return Math.round(x * factor) / factor;

Explanation / Answer

PRAGMAT precision=200 PRAGMAT

MODE INTEGER = LONG LONG INT;

LONG INT default integer width := 69;

INT width = 69+2;

INT fix w = 1, fix h = 1; # round up #

LONG LONG INT golden ratio w := ENTIER ((long long sqrt(5)-1) / 2 * LENG LENG 10 ** default integer width + fix w),

              golden ratio h := ENTIER ((long long sqrt(5)+1) / 2 * LENG LENG 10 ** default integer width + fix h);

test: (

print((

    "The approximate golden ratios, width: ", whole(golden ratio w,width), new line,

    "                              length: ", whole(golden ratio h,width), new line,

    "                product is exactly: ", whole(golden ratio w*golden ratio h,width*2), new line));

INTEGER two to the power of 64 = LONG 2 ** 64;

INTEGER neg two to the power of 64 = -(LONG 2 ** 64);

print(("2 ** 64 * -(2 ** 64) = ", whole(two to the power of 64*neg two to the power of 64,width), new line))

)

OP -   = (INTEGER a)INTEGER: raise integer not implemented error("monadic minus"),

ABS = (INTEGER a)INTEGER: raise integer not implemented error("ABS"),

ODD = (INTEGER a)INTEGER: raise integer not implemented error("ODD"),

BIN = (INTEGER a)INTEGER: raise integer not implemented error("BIN");

OP + = (INTEGER a, b)INTEGER: raise integer not implemented error("addition"),

   - = (INTEGER a, b)INTEGER: raise integer not implemented error("subtraction"),

   / = (INTEGER a, b)REAL: ( VOID(raise integer not implemented error("floating point division")); SKIP),

   % = (INTEGER a, b)INTEGER: raise integer not implemented error("fixed point division"),

   %* = (INTEGER a, b)INTEGER: raise integer not implemented error("modulo division"),

   ** = (INTEGER a, b)INTEGER: raise integer not implemented error("to the power of");

LONG INT default integer width := long long int width - 2;

INT fix w = -1177584, fix h = -3915074; # floating point error, probably GMP/hardware specific #

INTEGER golden ratio w := INTEGERINIT ENTIER ((long long sqrt(5)-1) / 2 * LENG LENG 10 ** default integer width + fix w),

        golden ratio h := INTEGERINIT ENTIER ((long long sqrt(5)+1) / 2 * LENG LENG 10 ** default integer width + fix h);

test: (

print((

    "The approximate golden ratios, width: ", REPR golden ratio w, new line,

    "                            length: ", REPR golden ratio h, new line,

    "                product is exactly: ", REPR (golden ratio w * golden ratio h), new line));

INTEGER two to the power of 64 = INTEGERINIT(LONG 2 ** 64);

INTEGER neg two to the power of 64 = INTEGERINIT(-(LONG 2 ** 64));

print(("2 ** 64 * -(2 ** 64) = ", REPR (two to the power of 64 * neg two to the power of 64), new line))

)

PRAGMAT precision=200 PRAGMAT

MODE INTEGER = LONG LONG INT;

LONG INT default integer width := 69;

INT width = 69+2;

INT fix w = 1, fix h = 1; # round up #

LONG LONG INT golden ratio w := ENTIER ((long long sqrt(5)-1) / 2 * LENG LENG 10 ** default integer width + fix w),

              golden ratio h := ENTIER ((long long sqrt(5)+1) / 2 * LENG LENG 10 ** default integer width + fix h);

test: (

print((

    "The approximate golden ratios, width: ", whole(golden ratio w,width), new line,

    "                              length: ", whole(golden ratio h,width), new line,

    "                product is exactly: ", whole(golden ratio w*golden ratio h,width*2), new line));

INTEGER two to the power of 64 = LONG 2 ** 64;

INTEGER neg two to the power of 64 = -(LONG 2 ** 64);

print(("2 ** 64 * -(2 ** 64) = ", whole(two to the power of 64*neg two to the power of 64,width), new line))

)

OP -   = (INTEGER a)INTEGER: raise integer not implemented error("monadic minus"),

ABS = (INTEGER a)INTEGER: raise integer not implemented error("ABS"),

ODD = (INTEGER a)INTEGER: raise integer not implemented error("ODD"),

BIN = (INTEGER a)INTEGER: raise integer not implemented error("BIN");

OP + = (INTEGER a, b)INTEGER: raise integer not implemented error("addition"),

   - = (INTEGER a, b)INTEGER: raise integer not implemented error("subtraction"),

   / = (INTEGER a, b)REAL: ( VOID(raise integer not implemented error("floating point division")); SKIP),

   % = (INTEGER a, b)INTEGER: raise integer not implemented error("fixed point division"),

   %* = (INTEGER a, b)INTEGER: raise integer not implemented error("modulo division"),

   ** = (INTEGER a, b)INTEGER: raise integer not implemented error("to the power of");

LONG INT default integer width := long long int width - 2;

INT fix w = -1177584, fix h = -3915074; # floating point error, probably GMP/hardware specific #

INTEGER golden ratio w := INTEGERINIT ENTIER ((long long sqrt(5)-1) / 2 * LENG LENG 10 ** default integer width + fix w),

        golden ratio h := INTEGERINIT ENTIER ((long long sqrt(5)+1) / 2 * LENG LENG 10 ** default integer width + fix h);

test: (

print((

    "The approximate golden ratios, width: ", REPR golden ratio w, new line,

    "                            length: ", REPR golden ratio h, new line,

    "                product is exactly: ", REPR (golden ratio w * golden ratio h), new line));

INTEGER two to the power of 64 = INTEGERINIT(LONG 2 ** 64);

INTEGER neg two to the power of 64 = INTEGERINIT(-(LONG 2 ** 64));

print(("2 ** 64 * -(2 ** 64) = ", REPR (two to the power of 64 * neg two to the power of 64), new line))

)

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