- Correct the following statements:
- boolean isGood = 1;
- char firstLetter = p;
- int 2way = 89;
- String name = Emina;
- int player score = 8976543;
- Double $class = 4.5;
- int _parents = 20.5;
- string name = "Ashenafi";
- Without doing any programming, what do you think the following main method prints to the screen?
public static void main(String[] args) {
int x = 5;
int y = 3;
int z = x + x * y - y;
System.out.println( "The value of z is " + z );
int w = ++x + y + y--;
System.out.println( "The value of w is " + w );
System.out.println( "The value of x is now " + x );
System.out.println( "The value of y is now " + y );
boolean a = true;
boolean b = false;
boolean c = (( a && ( !( x > y ))) && ( a || y > x ));
System.out.println( "c is " + c );
}
-
Create a new Java file with a class called UsingOperators and copy the above main method into it. (Can you figure out what the name of the of the Java file must be? Hint: see step 10 of Lab 0.) Compile and run. Does the output match what you thought?
-
Create a new Java class called TempConverter. Add a main method to TempConverter that declares and initializes a variable to store the temperature in Celsius. Your temperature variable should be store numbers with decimal places.
-
In the main method, compute the temperature in Fahrenheit according to the following formula and print it to the screen:
Fahrenheit = (9 � 5) � Celsius + 32
-
Set the Celsius variable to 100 and compile and run TempConverter. The correct output is 212.0. If your output was 132, you probably used integer division somewhere by mistake.
Submission: You should submit your answers to questions one and three and your TempConverter class code.