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

Notes: PRINT becomes system.out.println ( ) ; PRINT USING is formatted output, y

ID: 3806517 • Letter: N

Question

 Notes:    PRINT becomes system.out.println ( ) ;   PRINT USING is formatted output, you can likely ignore the formatting   REM is a comment   INPUT is a combination of System.out.println ( prompt) then use a Scanner     to getNext ( ) the needed value.   ^ means exponentiation, or "raising to a power"   : allows multiple BASIC statements on the same line.   GOSUB was a way to run a function. 
 // Convert this BASIC to Java here:   // Notes: for gosub 180, use   // plot ( ) ;   //   // for the goto 30, use a do/while loop   //   // find Java/Processing equivalents for ATN, SIN, SQR, RND and ^   /*   25 R0=180/3.14159   30 REM     RANDOM IMPACT PARAMETER   35 X=-1+2*RND(1)   40 Y=-1+2*RND(1)   45 B=SQR(X*X+Y*Y)   50 IF B>=1 THEN 30   55 REM     COLOR & INDEX OF REFR.   60 C=1+INT(3*RND(1))   65 N=1.33+.01*(C-1)   70 REM     COMPUTE ANGLES   75 I=ATN(B/SQR(1-B*B))   80 R=ATN(B/SQR(N*N-B*B))   85 T1=(4*R-2*I)*R0   90 T2=(6*R-2*I)*R0-180   95 REM     INTENSITY FACTORS   100 RS=(SIN(I-R)/SIN(I+R))^2   105 RP=(TAN(I-R)/TAN(I+R))^2   110 RB=(1-RP)*(1-RP)   115 RC=(1-RS)*(1-RS)   120 I1=(RS*RC+RP*RB)/2   125 I2=(RS*RS*RC+RP*RP*RB)/2   130 IF I1<.04*RND(1) THEN 140   135 TH=T1:  GOSUB 180   140 IF I2<.02*RND(1) THEN 150   145 TH=T2:  GOSUB 180   150 GOTO 30   */ 

Explanation / Answer

Hope below program will help you. This programs highlights the Java equivalents of BASIC.

public class BasicToJava {

  

  

   public static void main(String[] args) {

       double I2 = 0;

       double TH = 0;

       do {

           double R0 = 180 / 3.14159;

           // RANDOM IMPACT PARAMETER

           double B;

           do {

               double X = -1 + 2 * Math.random();

               double Y = 0.0;

               B = Math.pow(X * X + Y * Y, 2);

           } while (B >= 1);

           // COLOR & INDEX OF REFR

           int C = 1 + (int) Math.round(3 * Math.random());

           double N = 1.33 + .01 * (C - 1);

           // COMPUTE ANGLES

           double I = Math.atan(B / Math.pow(1 - B * B, 2));

           double R = Math.atan(B / Math.pow(N * N - B * B, 2));

           double T1 = (4 * R - 2 * I) * R0;

           double T2 = (6 * R - 2 * I) * R0 - 180;

           // INTENSITY FACTORS

           double RS = Math.pow(Math.sin(I - R) / Math.sin(I + R), 2);

           double RP = Math.pow(Math.tan(I - R) / Math.tan(I + R), 2);

           double RB = Math.pow(1 - RP, 2);

           double RC = Math.pow(1 - RS, 2);

           double I1 = (RS * RC + RP * RB) / 2;

           I2 = (RS * RS * RC + RP * RP * RB) / 2;

           TH = 0;

           if (!(I1 < .04 * Math.random())) {

               TH = T1;

               plot(TH);

           }

       } while (I2 < .02 * Math.random());

       plot(TH);

   }

   private static void plot(Double d) {

       System.out.println(d);

   }

}

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