Results 1 to 9 of 9

Thread: Please help me!

  1. #1
    KMayers is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Unhappy 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 02:20 PM. Reason: added [code] ... [/code] tags

  2. #2
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Re: Please help me!

    Does nobody on this forum actually read the guidelines!?!

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: Please help me!

    Quote Originally Posted by Darkzombies View Post
    Does nobody on this forum actually read the guidelines!?!
    You're new here, aren't you?
    :)

    KMayers, please use [code] tags [/code] when posting code so it retains its formatting and is readable.
    Are you planning on actually returning to this thread, as I see you didn't bother with your other two?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    KMayers is offline Member
    Join Date
    Nov 2012
    Posts
    4
    Rep Power
    0

    Default Re: Please help me!

    Yes, I am
    Where do I need to post my help question?
    Sorry

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default 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.

    ** This space for rent **

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default 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.

    ** This space for rent **

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Please help me!

    Quote Originally Posted by Tolls View Post
    I think Darkzombies was referring to the fact that you have not used [code] tags [/code] around your code.
    Also possibly to not going through the Forum Rules -- particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: Please help me!

    I added those [code] ... [/code] tags for the OP.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  9. #9
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Please help me!

    I see you still haven't posted your errors - how are we supposed to help?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •