public class Ch1_PrExercise7 { public statis void main(String[] args) { //variab
ID: 3529210 • Letter: P
Question
public class Ch1_PrExercise7 { public statis void main(String[] args) { //variable declaration //variable statements } } a. Write Java statements that declare and initialize the following named constants: SECRET of type int initialized to 11; RATE of type double initialized to 12.50. b. Write Java statements that declare the following variables: num1, num2, and newNum of type int; name of type String; hoursWorked and wages of type double. c. Write Java statements that store 15 into num1 and 28 into num2. d. Write a Java statement(s) that outputs the following line: The value of num1 = 15 and the value of num2 = 28. e. Write a Java statement that multiplies that value of num1 by 2, adds the value of num2 to it, and then stores the result in newNum. Then write a Java statement that outputs value of newNum. f. Write a Java statement that updates the value of newNum by adding the value of the named constant SECRET. Then write a Java statement that outputs the value of newNum with an appropriate message. g. Write a Java statement that stores "Cynthia Jacobson" into name. h. Write a Java statement that stores 45.50 into hoursWorked i. Write a Java statement that multiplies the value of the named constant RATE with the value of hoursWorked and stores the result into the variable wages. j. Write Java statements that produce the following output: Name: //output the value of the variable name Pay rate: $ //output the value of RATE Hours Worked: //output the value of the variable hoursWorked Salary: $ //output the value of the variable wages For the data given in the program, the output is: Name: Cynthia Jacobson Pay Rate: $12.50 Hours Worked: 45.50 Salary: $568.75Explanation / Answer
public class Ch1_PrExercise7 {
/**
* @param args
*/
public static void main(String[] args) {
int SECRET = 11;
double RATE = 12.50;
int num1, num2, newNum;
String name;
double hoursWorked, wages;
num1 = 15;
num2 = 28;
System.out.println("The value of num1 =" + num1);
System.out.println("the value of num2=" + num2);
newNum = num2 + (num1 * 2);
System.out.println("The value of newnum =" + newNum);
newNum = newNum + SECRET;
System.out.println("The value of newnum =" + newNum);
name = "Cynthia Jacobson";
hoursWorked = 45.50;
wages = hoursWorked * RATE;
System.out.println("Name:" + name);
System.out.println("Pay rate:" + RATE);
System.out.println("Hours Worked:" + hoursWorked);
System.out.println("Salary:" + wages);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.