Assignment3 - user from inputing a first index > second...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// The "Assignment3" class. /*Emilie Courtemanche Simon Wu Section O Section O 459 7274 454 5302 /*This program shows the ability to use if and else statements, by calculating the index of refraction. We had to use our knowledge of the Math functions to be able to convert angles from radians to degrees and vis versa.*/ b import apsc142.*; public class Assignment3 { public static void main (String[] args) { //variables double index1;//declaring the first index double index2;//declaring the second index double angle1;//declaring the first angle double angle2;//declaring the second angle d //prompt the user System.out.print ("Please enter index one: "); index1=StdIn.readDouble(); System.out.print ("Please enter index two (index two has to be > index 1): "); index2=StdIn.readDouble(); System.out.print ("please enter angle one in degrees: "); angle1=StdIn.readDouble(); a if (index1>index2){/*The If statement is used to try and prevent the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: user from inputing a first index > second index because this will cause a reflection (ie. no real solution).*/ System.out.println ("There is no real solution"); System.out.println ("All light is reflected back into Region1 and no light passes into Region 2 at all."); /*We are trying to give them a second chance to enter indexes that can be actually calculated.*/ System.out.print ("Please enter index one: "); index1=StdIn.readDouble(); System.out.print ("Please enter index two: "); index2=StdIn.readDouble(); angle2=Math.asin(index1/index2*Math.sin(angle1*(Math.PI/180))); Fmt.printf ("The refraction angle is: %.2f" , (angle2*(180/Math.PI)) + "degrees"); } else if (index1<=index2){ //formula angle2=Math.asin(index1/index2*Math.sin(angle1*(Math.PI/180))); Fmt.printf ("The refraction angle is: %.2f" , (angle2*(180/Math.PI)) + "degrees"); } } // main method } // Assignment3 class...
View Full Document

This note was uploaded on 12/01/2010 for the course APPLIED SC 142 taught by Professor Professorstansimmons during the Winter '10 term at Queens University.

Page1 / 2

Assignment3 - user from inputing a first index > second...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online