Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Simple Salary Calculator Program

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    35
    My Mood
    Fine
    Thanks
    5
    Thanked 1 Time in 1 Post

    Post Simple Salary Calculator Program

    Hello, this is my first post on here, and I am new to java. I am trying to make a simple salary calculator that takes user input using the Scanner for the fields of entering an employee ID number, hourly pay, number of regular, and number of overtime hours worked. From there, it calculates the weekly pay with the employee ID number in the system.out somewhere. Here is what I have so far:
    import java.util.Scanner;
     
    public class PaymentCalculator {
    	int employeeId;
    	int regHours;
    	int overHours;
    	double wage;
    	double totalPay;
     
    	public static void main(String[] args) {
    		System.out.println("Enter Employee ID: ");
    		Scanner scan = new Scanner(System.in);
    		int employeeId = scan.nextint();
    		System.out.println("Enter the Number of Regular Hours: ");
    		Scanner scan1 = new Scanner(System.in);
    		int regHours = scan.nextint();
    		System.out.println("Enter the Number of Over Time Hours: ");
    		Scanner scan2 = new Scanner(System.in);
    		int overHours = scan.nextint();
    		System.out.println("Enter the Hourly Wage: ");
    		Scanner scan3 = new Scanner(System.in);
    		double wage = scan.nextdouble();
    		double totalPay = (regHours * wage) + (overHours * (wage * 1.5));
    		System.out.println("The total pay this week is: " + totalPay);
    	}
    }

    I am using JCreator and am getting the errors:

    --------------------Configuration: PaymentCalculator - JDK version 1.7.0_03 <Default> - <Default>--------------------
    C:\Users\Bert\Documents\JCreator Pro\MyProjects\PaymentCalculator\PaymentCalculator .java:13: error: cannot find symbol
    int employeeId = scan.nextint();
    ^
    symbol: method nextint()
    location: variable scan of type Scanner
    C:\Users\Is\Documents\JCreator Pro\MyProjects\PaymentCalculator\PaymentCalculator .java:16: error: cannot find symbol
    int regHours = scan.nextint();
    ^
    symbol: method nextint()
    location: variable scan of type Scanner
    C:\Users\A\Documents\JCreator Pro\MyProjects\PaymentCalculator\PaymentCalculator .java:19: error: cannot find symbol
    int overHours = scan.nextint();
    ^
    symbol: method nextint()
    location: variable scan of type Scanner
    C:\Users\Andrew\Documents\JCreator Pro\MyProjects\PaymentCalculator\PaymentCalculator .java:22: error: cannot find symbol
    double wage = scan.nextdouble();
    ^
    symbol: method nextdouble()
    location: variable scan of type Scanner
    4 errors

    Process completed.


    Under the general output I am receiving:

    --------------------Configuration: PaymentCalculator - JDK version 1.7.0_03 <Default> - <Default>--------------------
    Error: Could not find or load main class PaymentCalculator

    Process completed.


    Any help with this would be much appreciated!
    Last edited by Blasfemmy; August 20th, 2014 at 03:32 PM.


  2. #2
    Member suyog53's Avatar
    Join Date
    Sep 2012
    Location
    Mumbai
    Posts
    37
    My Mood
    Daring
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Simple Salary Calculator Program

    Java is case sensitive. . .'
    Your code contains nextint() and nextdouble() . . .'
    Replace them with nextInt() and nextDouble(). . .'
    ('I' and 'D' are capital)'

  3. #3
    Member suyog53's Avatar
    Join Date
    Sep 2012
    Location
    Mumbai
    Posts
    37
    My Mood
    Daring
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Simple Salary Calculator Program

    Also in line 14, 17 and 20, replace scan with scan1, scan2, scan3 respectively.'

  4. The Following User Says Thank You to suyog53 For This Useful Post:

    Blasfemmy (October 18th, 2012)

  5. #4
    Member
    Join Date
    Oct 2012
    Posts
    35
    My Mood
    Fine
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: Simple Salary Calculator Program

    Thanks, it is working now! Should I update the op with the corrections?

  6. #5
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Simple Salary Calculator Program

    It would be kind of you to post the new code with corrections rather than change the op, so that people can understand what was changed later on. You can also mark this thread as solved up at the top of the page under thread tools.

  7. #6
    Member
    Join Date
    Oct 2012
    Posts
    35
    My Mood
    Fine
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: Simple Salary Calculator Program

    Okay, will do.

    import java.util.Scanner;
     
    public class PaymentCalculator {
    	int employeeId;
    	int regHours;
    	int overHours;
    	double wage;
    	double totalPay;
     
    	public static void main(String[] args) {
    		System.out.println("Enter Employee ID: ");
    		Scanner scan = new Scanner(System.in);
    		int employeeId = scan.nextInt();
    		System.out.println("Enter the Number of Regular Hours: ");
    		Scanner scan1 = new Scanner(System.in);
    		int regHours = scan1.nextInt();
    		System.out.println("Enter the Number of Over Time Hours: ");
    		Scanner scan2 = new Scanner(System.in);
    		int overHours = scan2.nextInt();
    		System.out.println("Enter the Hourly Wage: ");
    		Scanner scan3 = new Scanner(System.in);
    		double wage = scan3.nextDouble();
    		double totalPay = (regHours * wage) + (overHours * (wage * 1.5));
    		System.out.println("The Total Pay This Week Is $" + totalPay);
    		System.out.println("For Employee #" + employeeId);
    	}
    }

    Then I modified it so that it would take a day by day entry:

    import java.util.Scanner;
     
    public class Mod_of_3_4 {
     
    //Constant Vars	
    	int employeeId;
    	int regHours;
    	int overHours;
    	double wage;
    	double totalPay;
     
    //Day 1	Var
    	int regHours1;
    	int overHours1;
    //Day 2	Var
    	int regHours2;
    	int overHours2;
    //Day 3	Var
    	int regHours3;
    	int overHours3;
    //Day 4 Var
    	int regHours4;
    	int overHours4;
    //Day 5 Var
    	int regHours5;
    	int overHours5;
     
     
    	public static void main(String[] args) {
     
    //Constants		
    		System.out.println("Enter Employee ID: ");
    		Scanner scan = new Scanner(System.in);
    		int employeeId = scan.nextInt();
     
    		System.out.println("Enter the Hourly Wage: ");
    		Scanner scan3 = new Scanner(System.in);
    		double wage = scan3.nextDouble();
    //Day 1		
    		System.out.println("Monday: Enter the Number of Regular Hours: ");
    		Scanner scan1 = new Scanner(System.in);
    		int regHours1 = scan1.nextInt();
     
    		System.out.println("Monday: Enter the Number of Over Time Hours: ");
    		Scanner scan2 = new Scanner(System.in);
    		int overHours1 = scan2.nextInt();
     
    //Day 2		
    		System.out.println("Tuesday: Enter the Number of Regular Hours: ");
    		Scanner scan4 = new Scanner(System.in);
    		int regHours2 = scan4.nextInt();
     
    		System.out.println("Tuesday: Enter the Number of Over Time Hours: ");
    		Scanner scan5 = new Scanner(System.in);
    		int overHours2 = scan5.nextInt();
     
    //Day 3		
    		System.out.println("Wednesday: Enter the Number of Regular Hours: ");
    		Scanner scan6 = new Scanner(System.in);
    		int regHours3 = scan6.nextInt();
     
    		System.out.println("Wednesday: Enter the Number of Over Time Hours: ");
    		Scanner scan7 = new Scanner(System.in);
    		int overHours3 = scan7.nextInt();
     
    //Day 4		
    		System.out.println("Thursday: Enter the Number of Regular Hours: ");
    		Scanner scan8 = new Scanner(System.in);
    		int regHours4 = scan8.nextInt();
     
    		System.out.println("Thursday: Enter the Number of Over Time Hours: ");
    		Scanner scan9 = new Scanner(System.in);
    		int overHours4 = scan9.nextInt();
     
    //Day 5	
    		System.out.println("Friday: Enter the Number of Regular Hours: ");
    		Scanner scan10 = new Scanner(System.in);
    		int regHours5 = scan10.nextInt();
     
    		System.out.println("Friday: Enter the Number of Over Time Hours: ");
    		Scanner scan11 = new Scanner(System.in);
    		int overHours5 = scan11.nextInt();
     
    //Calculations		
    		int regHours = (regHours1 + regHours2 + regHours3 + regHours4 + regHours5);
    		int overHours = (overHours1 + overHours2 + overHours3 + overHours4 + overHours5);
    		double totalPay = (regHours * wage) + (overHours * (wage * 1.5));
     
    //Print Results		
    		System.out.println("The Total Pay This Week Is $" + totalPay);
    		System.out.println("For Employee #" + employeeId);
    	}
    }

    Thanks again for the help!

  8. #7
    Member suyog53's Avatar
    Join Date
    Sep 2012
    Location
    Mumbai
    Posts
    37
    My Mood
    Daring
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Simple Salary Calculator Program

    So. you look quite happy now....'
    You can also try to reduce no. of lines of code.....which helps to run your program little faster....'
    (I read it somewhere while Googling)'
    Declare all variables in single line '
    You can loop through blocks instead of writing such a large program..................'

  9. #8
    Member
    Join Date
    Oct 2012
    Posts
    35
    My Mood
    Fine
    Thanks
    5
    Thanked 1 Time in 1 Post

    Default Re: Simple Salary Calculator Program

    Okay, I am trying to make the program run from a few methods and I'm running into errors left and right:

     
    import java.util.Scanner; //Takes user input
     
    import java.text.*; //import for the decimal format
     
    public class Mod_of_3_4 {
     
    //Constant Vars	
    	int employeeId;
    	int regHours;
    	int overHours;
    	double wage;
    	double totalPay;
     
    //Day 1	Var
    	int regHours1;
    	int overHours1;
    //Day 2	Var
    	int regHours2;
    	int overHours2;
    //Day 3	Var
    	int regHours3;
    	int overHours3;
    //Day 4 Var
    	int regHours4;
    	int overHours4;
    //Day 5 Var
    	int regHours5;
    	int overHours5;
     
     
    public static void main(String[] args) {
     
    //Methods
    		inputID();
    		inputWage();
    		inputDays();
    		calcPay();
    		calcTotal();
    		printResults();
     
    	}
     
    //Employee ID Number	
    	public int inputID() {
     
    		System.out.println("Enter Employee ID: ");
    		Scanner scan = new Scanner(System.in);
    		int employeeId = scan.nextInt();
     
    	}
    //Hourly Wage
    	public double inputWage() {
     
    		System.out.println("Enter the Hourly Wage: ");
    		Scanner scan3 = new Scanner(System.in);
    		double wage = scan3.nextDouble();
     
    	}
    //Input Daily Hours
    	public int inputDays() {
     
    	//Day 1		
    		System.out.println("Monday: Enter the Number of Regular Hours: ");
    		Scanner scan1 = new Scanner(System.in);
    		int regHours1 = scan1.nextInt();
     
    		System.out.println("Monday: Enter the Number of Over Time Hours: ");
    		Scanner scan2 = new Scanner(System.in);
    		int overHours1 = scan2.nextInt();
     
    	//Day 2		
    		System.out.println("Tuesday: Enter the Number of Regular Hours: ");
    		Scanner scan4 = new Scanner(System.in);
    		int regHours2 = scan4.nextInt();
     
    		System.out.println("Tuesday: Enter the Number of Over Time Hours: ");
    		Scanner scan5 = new Scanner(System.in);
    		int overHours2 = scan5.nextInt();
     
    	//Day 3		
    		System.out.println("Wednesday: Enter the Number of Regular Hours: ");
    		Scanner scan6 = new Scanner(System.in);
    		int regHours3 = scan6.nextInt();
     
    		System.out.println("Wednesday: Enter the Number of Over Time Hours: ");
    		Scanner scan7 = new Scanner(System.in);
    		int overHours3 = scan7.nextInt();
     
    	//Day 4		
    		System.out.println("Thursday: Enter the Number of Regular Hours: ");
    		Scanner scan8 = new Scanner(System.in);
    		int regHours4 = scan8.nextInt();
     
    		System.out.println("Thursday: Enter the Number of Over Time Hours: ");
    		Scanner scan9 = new Scanner(System.in);
    		int overHours4 = scan9.nextInt();
     
    	//Day 5	
    		System.out.println("Friday: Enter the Number of Regular Hours: ");
    		Scanner scan10 = new Scanner(System.in);
    		int regHours5 = scan10.nextInt();
     
    		System.out.println("Friday: Enter the Number of Over Time Hours: ");
    		Scanner scan11 = new Scanner(System.in);
    		int overHours5 = scan11.nextInt();
    	}
    //Reformat and Calculate
    	public int calcPay() {
     
    	//Decimal Format
    		DecimalFormat df = new DecimalFormat("#.##"); 
     
    	//Calculations		
    		int regHours = (regHours1 + regHours2 + regHours3 + regHours4 + regHours5);
    		int overHours = (overHours1 + overHours2 + overHours3 + overHours4 + overHours5);
    			}	
    	public double calcTotal() {
    		double totalPay = (regHours * wage) + (overHours * (wage * 1.5));
    	}
    //Print Results
    	public void printResults() {
     
    		System.out.println("Total pay for the week is: $"+df.format(totalPay));
    		System.out.println("For Employee #" + employeeId);
    	}
    }

    I'm getting the error messages:

    --------------------Configuration: Mod of 3.4 - JDK version 1.7.0_03 <Default> - <Default>--------------------
    C:\Users\Andrew\Documents\JCreator Pro\MyProjects\Mod of 3.4\src\Mod_of_3_4.java:41: error: non-static method inputID() cannot be referenced from a static context
    inputID();
    ^
    C:\Users\Andrew\Documents\JCreator Pro\MyProjects\Mod of 3.4\src\Mod_of_3_4.java:42: error: non-static method inputWage() cannot be referenced from a static context
    inputWage();
    ^
    C:\Users\Andrew\Documents\JCreator Pro\MyProjects\Mod of 3.4\src\Mod_of_3_4.java:43: error: non-static method inputDays() cannot be referenced from a static context
    inputDays();
    ^
    C:\Users\Andrew\Documents\JCreator Pro\MyProjects\Mod of 3.4\src\Mod_of_3_4.java:44: error: non-static method calcPay() cannot be referenced from a static context
    calcPay();
    ^
    C:\Users\Andrew\Documents\JCreator Pro\MyProjects\Mod of 3.4\src\Mod_of_3_4.java:45: error: non-static method calcTotal() cannot be referenced from a static context
    calcTotal();
    ^
    C:\Users\Andrew\Documents\JCreator Pro\MyProjects\Mod of 3.4\src\Mod_of_3_4.java:46: error: non-static method printResults() cannot be referenced from a static context
    printResults();
    ^
    C:\Users\Andrew\Documents\JCreator Pro\MyProjects\Mod of 3.4\src\Mod_of_3_4.java:130: error: cannot find symbol
    System.out.println("Total pay for the week is: $"+df.format(totalPay));
    ^
    symbol: variable df
    location: class Mod_of_3_4
    7 errors

    Process completed.
    I've tried to fix the errors and I'm only getting more, any help would be much appreciated! Also, how can I do the loops mentioned in the post above?
    Last edited by Blasfemmy; October 18th, 2012 at 05:44 PM.

Similar Threads

  1. Simple Commission Calculator
    By mrivera8504 in forum What's Wrong With My Code?
    Replies: 22
    Last Post: August 27th, 2012, 07:35 PM
  2. [SOLVED] Simple calculator issue
    By ikocijan in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 20th, 2012, 03:43 AM
  3. Employee class won't set salary and number values
    By JeremiahWalker in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 7th, 2012, 06:01 PM
  4. Need help building a simple calculator
    By zigma in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 14th, 2011, 02:13 AM
  5. Simple Calculator
    By JKDSurfer in forum Loops & Control Statements
    Replies: 3
    Last Post: June 28th, 2011, 02:37 PM

Tags for this Thread