Manny Grewal
Posts: 5
Nickname: mannyg
Registered: Mar, 2009
|
|
Re: Java Scanning
|
Posted: Mar 3, 2009 3:40 PM
|
|
I see, well thanks for that, I fixed those errors. Actually I am just learning from slides, so I don't quite know it well enough, thanks for letting me know. So I have completed the assignment but now I recieve a logical error. I believe I know what the problem is, but I do not know how to solve it. I will post my whole program so you can understand it, I also added comments explaining what some things do (as pertained in the assignment).
import java.util.Scanner; // Importing Scanner class PayTime // Naming the class PayTime { public static void main(String[] args) { Scanner pay = new Scanner (System.in); //Creating class for Scanner, naming it "pay" int employeeNumber =0; double wage=0; double hours=0; double overTime=hours-40; double grossPay=hours*wage; double incomeTax=0; double incomeTaxOverTime=overTime*.25; double incomeTaxOverall=incomeTax+incomeTaxOverTime; double netPay=(grossPay-incomeTaxOverall); double overHours=hours+overTime; double overTimePay=overTime*1.5;
System.out.print("Enter Employee Number: ");//Prompting Employees Number employeeNumber=pay.nextInt(); // Declared variable for Employees Number, and saving it System.out.print("Enter Employee Name: ");//Prompting Employees Name String name=pay.next(); // Declare String "name" storing Employees Name here System.out.print("Enter Hours Worked: ");//Prompting for Employees hours worked hours=pay.nextDouble();//Declaring variable for hours to be used, and saving it System.out.print("Enter Hourly Wage: $");//Prompting Employee for hourly wage wage=pay.nextDouble();//Declaring variable wage, and saving input given by user while (wage>100)//If the hourly wage is above 100 dollars, then a invalid message is shown { System.out.print("Invalid, Please enter a valid hourly wage: ");//Prompting for a realistic value for the hourly wage wage=pay.nextDouble();//scanning/saving the new wage entered until it meets condition } if (grossPay>=0 || grossPay<=300) incomeTax=.10; else if (grossPay>=300.01 || grossPay<=400) incomeTax=.12; else if (grossPay>=400.01 || grossPay<=500) incomeTax=.15; else incomeTax=.20;
if (hours>40){
System.out.println("Employee Name: "+name); System.out.println("Regular Pay: "+grossPay); System.out.println("Overtime Pay: "+overTimePay); System.out.println("Regular Income Taxes: "+incomeTax); System.out.println("Overtime Income Taxes: "+incomeTaxOverTime); System.out.println("Net Pay: "+netPay); else System.out.println("Employee Name: "+name); System.out.println("Gross Pay: "+grossPay); System.out.println("Income Taxes: "+incomeTax); System.out.println("Net Pay: "+netPay); }
} }
I believe the problem lies with the if statement at the end, where I do the final output, but the if statement only accepts the first condition after, it, everything else is just written. I dont know how to do it properly, I recieve a logical error. The values i use are this: Number: 12345 Name: Manny Hours worked: 50 Hourly wage: $10
and the output is: Name: Manny Regular Pay: 0.0 Overtime Pay: -60 Regular Income Taxes: 0.1 Overtime income taxes: -10.0 Net Pay: 10.00 Gross Pay: 0.0 Income taxes: 0.1 Net Pay: 10.0
it's a logical error, and it also displays the else part automatically, I do apologize if for you this is basic, but I am only a month into learning Java, doing it twice a week, I do find some things difficult to fix. Thanks for any help
|
|