Vizy
New Member
Ok guys, so I finished the assignment, but it's not doing what it needs to lol. My problem is with the stupid Scanner thing (it's the only way that I know of for kb input. And my teacher requested that we just used scanner).
So the prompt comes up (i'm using BlueJ) asking for hours worked, and i cannot input a decimal without the thing crapping out.
He wants a seperate driver and class so here are both. I would really appreciate it if someone looked it over real quick.
Driver:
Class
And if someone would tell me how it's possible to get all the different Calculators into one method, that's be awesome.
Thanks guys.
So the prompt comes up (i'm using BlueJ) asking for hours worked, and i cannot input a decimal without the thing crapping out.
He wants a seperate driver and class so here are both. I would really appreciate it if someone looked it over real quick.
Driver:
Code:
import java.util.Scanner;
public class TaxesDriver
{
public static void main (String[] ouchy)
{
Scanner myScanner = new Scanner (System.in);
System.out.println("Enter your hours worked: ");
double hoursWorked = myScanner.nextInt();
System.out.println("Enter your hourly pay rate (in cents): ");
double hourlyRatePay = (myScanner.nextInt())/100;
Taxes myTaxes = new Taxes();
System.out.println("Hours worked:" + hoursWorked);
System.out.println("Hourly Rate: " + hourlyRatePay);
System.out.println("");
System.out.println("Gross pay: " + hoursWorked*hourlyRatePay);
System.out.println("");
System.out.println("Federal Tax (15.4%):" + myTaxes.FederalTaxCalc(hoursWorked, hourlyRatePay));
System.out.println("FICA Tax (7.75%): " + myTaxes.FicaTaxCalc(hoursWorked, hourlyRatePay));
System.out.println("State Tax (4.0%): " + myTaxes.StateTaxCalc(hoursWorked, hourlyRatePay));
System.out.println("");
System.out.println("");
System.out.println("Net Pay: " + myTaxes.NetPayCalc(hoursWorked, hourlyRatePay));
}
}
Class
Code:
public class Taxes
{
final double FEDERAL_TAX = .154;
final double FICA_TAX = .0775;
final double STATE_TAX = .04;
public double hoursWorked;
public double hourlyRatePay;
public void Taxes()
{
hoursWorked = 2;
hourlyRatePay = 2;
}// default constructor
public double FederalTaxCalc(double inputHoursWorked, double inputHourlyRatePay)
{
double hoursWorked = inputHoursWorked;
double hourlyRatePay = inputHourlyRatePay;
double grossPay = hoursWorked*hourlyRatePay;
double federalTax = grossPay *FEDERAL_TAX;
return federalTax;
}
public double FicaTaxCalc(double inputHoursWorked, double inputHourlyRatePay)
{
double hoursWorked = inputHoursWorked;
double hourlyRatePay = inputHourlyRatePay;
double grossPay = hoursWorked*hourlyRatePay;
double ficaTax = grossPay *FICA_TAX;
return ficaTax;
}
public double StateTaxCalc(double inputHoursWorked, double inputHourlyRatePay)
{
double hoursWorked = inputHoursWorked;
double hourlyRatePay = inputHourlyRatePay;
double grossPay = hoursWorked*hourlyRatePay;
double stateTax = grossPay *STATE_TAX;
return stateTax;
}
public double NetPayCalc(double inputHoursWorked, double inputHourlyRatePay)
{
double hoursWorked = inputHoursWorked;
double hourlyRatePay = inputHourlyRatePay;
double grossPay = hoursWorked*hourlyRatePay;
double federalTax = grossPay *FEDERAL_TAX;
double ficaTax = grossPay *FICA_TAX;
double stateTax = grossPay *STATE_TAX;
double netPay = grossPay - federalTax - ficaTax - stateTax;
return netPay;
}
}
And if someone would tell me how it's possible to get all the different Calculators into one method, that's be awesome.
Thanks guys.