Results 1 to 9 of 9
Thread: Please help me!
- 11-29-2012, 06:16 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 4
- Rep Power
- 0
Please help me!
a. Write a Java statement that imports the class Scanner.
b. Write a Java statement that declares console to be a Scanner object for inputting data from the standa rd input device.
c. 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 .
d. Write Java statements that declare the following variables: num1, num2, a nd newNum of type int; name of type String; hoursWorked and wages of type double.
e. Write Java sta tements that prompt the user to input two integers, store the first number into num1, and store the second n umber into num2 .
f. Write a Java s tatement(s) that ou tputs the value of num1 and num2 , indicating which is num1 and whic h is num2. For example, if num1 is 8 and num2 is 5, then the output is:
The value of num1 = 8 and the value of num2 = 5.
g. Write a Ja va statement that multiplies tha t 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 the valu e of newNum.
h. Write a Java statement tha t updates the valu e of newNum by adding the value of the named constant SECRET. Then write a Ja va s tatement that outputs the valu e of newNum with a n a ppropria te message.
i. Write Java statements that prompt the user to enter a person's las t name and then store the last name into the variabl e name.
j. Write Java statements that prompt the user to enter a decimal number between 0 and 70 (inclusive) and then store the number entered into hoursWorked.
k. Write a Java s tatement that multiplies the valu e of the named constant RATE with the valu e of hoursWorked and s tores the result into the variable wages.
I. Write Java s tatements that produce the following output:
Name: //output the value of the variable name
Pay Rate: $ //output the value of the variable rate
Hours Worked: //output the value of the variable hours worked
Wages: $ //output the value of the variable wages
For exampl e, if the value of name is "Rainbow" and hoursWorked is
4 5 . 50 , then the output is:
Name: Rainbow
Pay Rate: $12.50
Hours Worked: 45.50
Wages: $568.75
m. Write a Java program that tests eac h of the Java sta tements in parts (a)* (1). Place the statemen ts at the appropriate loca tion in the preceding Ja va program segment. Test run your program (twice) on the following input data.
a. num1 = 13, num2 = 28; name = "Jacobson"; hoursWorked = 48.30.
b. num1 = 32, num2 = 15; name = "Cynthia"; hoursWorked = 58.45.
This is what I came up with so far but still getting an error message
Java Code:import java.util.*; public class Exercise4 { static final int SECRET = 11; static final double RATE = 12.50; static Scanner console = new Scanner(System.in); { int num1; int num2; int newNum; double hoursWorked; double wages; String name; num1 = 12; num2 = 2; name = "Jacobson"; hoursWorked = 48.30; System.out.println("num1 + num2 = " + (num1 + num2)); newNum = console.nextInt(); System.out.println(); newNum = num1 + num2; System.out.println("num1 * 2 + num2 " + (num1 * 2 + num2)); newNum = num1 * 2 + num2; System.out.println("Enter newNum + SECRET " + (newNum + SECRET)); newNum = console.nextInt(); newNum = newNum + SECRET; System.out.print("Enter name: "); name = console.nextInt(); System.out.println(); System.out.print("Enter a decimal between 0 and 70: "); hoursWorked = console.nextDouble(); System.out.println(); System.out.print("Enter RATE * hoursWorked" + (RATE * hoursWorked)); wages = console.nextDouble(); System.out.println(); wages = RATE * hoursWorked; System.out.println("lastname ": + lastname); System.out.println("RATE ": + RATE); System.out.println("hoursWorked ": + hoursWorked); System.out.println("Salary" : + salary); } }Last edited by JosAH; 11-29-2012 at 01:20 PM. Reason: added [code] ... [/code] tags
- 11-29-2012, 06:32 AM #2
Senior Member
- Join Date
- Nov 2012
- Posts
- 105
- Rep Power
- 0
Re: Please help me!
Does nobody on this forum actually read the guidelines!?!
- 11-29-2012, 10:17 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: Please help me!
Please do not ask for code as refusal often offends.
- 11-29-2012, 12:43 PM #4
Member
- Join Date
- Nov 2012
- Posts
- 4
- Rep Power
- 0
Re: Please help me!
Yes, I am
Where do I need to post my help question?
Sorry
- 11-29-2012, 12:57 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: Please help me!
I think Darkzombies was referring to the fact that you have not used [code] tags [/code] around your code.
Here is a prefectly good place to ask your question, but the tags are needed so we can actually read your code easily.Please do not ask for code as refusal often offends.
- 11-29-2012, 12:58 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Re: Please help me!
Oh, and while I'm here, you also need to post the full error message you are getting, highlighting the line on which it occurs.
Please do not ask for code as refusal often offends.
- 11-29-2012, 01:19 PM #7
Re: Please help me!
Also possibly to not going through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 11-29-2012, 01:22 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,402
- Blog Entries
- 7
- Rep Power
- 17
Re: Please help me!
I added those [code] ... [/code] tags for the OP.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 11-29-2012, 01:28 PM #9


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks