Results 1 to 18 of 18
  1. #1
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default Have code cant get to run

    Hello,

    This is a class project with University of Phoenix Axia. My instructor told me to seek help here the lab also had trouble. Can someone help wit the program
    The troble is canty get the varible work.

    import java.util.Scanner;

    public class Payroll
    {
    // This method is used to get the name from the user. The prompt
    // to display is passed in.
    public static String getName(String prompt) {
    Scanner input = new Scanner( System.in );
    String name;
    System.out.print(prompt);
    name = input.nextLine();
    return(name);
    }

    // This method is a generic method to read in a positive number. The prompt to
    // display is passed in. The method continues asking for a number until a positive
    // number is entered.
    public static double getPositiveNumber(String prompt) {
    Scanner input = new Scanner( System.in );
    double number = 0;
    do {
    System.out.print(prompt);
    number = input.nextDouble();
    } while (number<=0);
    return(number);
    }

    public static void main (String args[])
    {

    String name = "";
    double payRate;
    double hours;
    double weeklyPay;

    while (!name.equals("stop")) {

    name = getName("Enter name: ");
    if (!name.equals("stop")) {

    payRate = getPositiveNumber("Enter payrate: ");
    hours = getPositiveNumber("Enter hours: ");
    weeklyPay = payRate * hours;

    System.out.print(name + " earned ");
    System.out.printf("$ %.2f", weeklyPay);
    System.out.println();
    }

  2. #2
    helpmeplease is offline Member
    Join Date
    Dec 2009
    Posts
    15
    Rep Power
    0

    Default


    }
    }
    }


    ^^ add these to the end of your program and it will run fine

  3. #3
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default code doe not work

    Still doesnt print name or pay. Stops at enter name.
    Ehanks

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Abbinormal View Post
    Still doesnt print name or pay. Stops at enter name.
    Ehanks
    It prints it for me.

  5. #5
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Question Confused

    Hello,

    I am checking this with Eclipse, and it doesn't give a run condition. How did you run the code?

    Thanks,

  6. #6
    helpmeplease is offline Member
    Join Date
    Dec 2009
    Posts
    15
    Rep Power
    0

    Default

    Im running it on blue j. I just added three extra }'s to your program and it ran for me

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    A minor quibble: If you open scanner objects you should close them. Else you may run out of resources, perhaps not with this program, but in future programs. It's just a good habit to get in to.

  8. #8
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default BlueJ

    Hello,
    I was originaly going to use Bluej, but couldn't get to download. I do not like Eclipse , but recommended bu instructor . Can you use Java 6 witt it. I have to use 5.

  9. #9
    helpmeplease is offline Member
    Join Date
    Dec 2009
    Posts
    15
    Rep Power
    0

    Default

    the code was pretty much on point to me. blue j is the best for beginners

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    So what happens? Does your code not compile? Does it compile and not run? Any error messages? If so, post them all.

  11. #11
    helpmeplease is offline Member
    Join Date
    Dec 2009
    Posts
    15
    Rep Power
    0

    Default

    outside of the }'s i still dont see the issue

  12. #12
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default

    Hello,

    Message , cant initulize varibles

  13. #13
    helpmeplease is offline Member
    Join Date
    Dec 2009
    Posts
    15
    Rep Power
    0

    Default

    are you reading anything i wrote?

    just add three }'s to the end of your code

  14. #14
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default

    Yes , but didn't help

  15. #15
    helpmeplease is offline Member
    Join Date
    Dec 2009
    Posts
    15
    Rep Power
    0

    Default

    just copy and paste the following

    Java Code:
    import java.util.Scanner; 
    
    public class Payroll
    { 
    // This method is used to get the name from the user. The prompt
    // to display is passed in.
    public static String getName(String prompt) {
    Scanner input = new Scanner( System.in ); 
    String name;
    System.out.print(prompt);
    name = input.nextLine();
    return(name);
    }
    
    // This method is a generic method to read in a positive number. The prompt to
    // display is passed in. The method continues asking for a number until a positive 
    // number is entered.
    public static double getPositiveNumber(String prompt) {
    Scanner input = new Scanner( System.in ); 
    double number = 0;
    do {
    System.out.print(prompt);
    number = input.nextDouble(); 
    } while (number<=0);
    return(number);
    }
    
    public static void main (String args[])
    {
    
    String name = "";
    double payRate;
    double hours;
    double weeklyPay;
    
    while (!name.equals("stop")) {
    
    name = getName("Enter name: ");
    if (!name.equals("stop")) {
    
    payRate = getPositiveNumber("Enter payrate: ");
    hours = getPositiveNumber("Enter hours: ");
    weeklyPay = payRate * hours;
    
    System.out.print(name + " earned ");
    System.out.printf("$ %.2f", weeklyPay);
    System.out.println();
    } 
    
    }
    }
    }

  16. #16
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Abbinormal View Post
    Message , cant initulize varibles
    What is the precise compiler error message, word-for word? Paste it here.

    And which line throws this compiler error?

  17. #17
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Default No Errors now, But

    Hello, Just ran again, no errors but only prints" Enter name:" rest of program does't work on console

  18. #18
    Abbinormal is offline Member
    Join Date
    Dec 2009
    Posts
    16
    Rep Power
    0

    Talking Fixed

    You all have been great. This is my first forum for programing and it has been Great. It takes a gret bunch of people to help as well as you have:

Similar Threads

  1. Convert java code to midlet code
    By coldvoice05 in forum New To Java
    Replies: 1
    Last Post: 08-12-2009, 12:14 PM
  2. Convert java code to midlet code
    By coldvoice05 in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2009, 02:21 PM
  3. Why doesn't this code accept my code?
    By PeterFeng in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 02:39 PM
  4. I need help fixing my code.. or non code?
    By MrHuggykins in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 11:12 PM
  5. Replies: 1
    Last Post: 04-26-2007, 04:52 PM

Posting Permissions

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