|
|
|
|
#1 (permalink) |
|
banned
Join Date: Dec 2007
Location: Los Angeles
Posts: 3,896
|
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: 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));
}
}
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;
}
}
Thanks guys.
|
|
|
|
|
|
#2 (permalink) |
|
banned
Join Date: Dec 2007
Location: Los Angeles
Posts: 3,896
|
3 minutes later.....
Ok my bad i'm an idiot. I got it. And if anyone was wondering of what was needed (for all you beginner AP compsci people like me) my teacher never taught us crap, but i changed the NextInt to NextDouble. it works thanks guys |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| internet explorer 8....no java runtime enviorment? | fastforded | General Software | 2 | 07-05-2009 07:04 PM |
| What does basic Java Programming language actually look like? | leeroyMarv | General Software | 3 | 06-09-2006 04:48 AM |
| Help with basic applet - java programming | mikekelly | General Software | 0 | 04-30-2006 05:49 PM |
| Java problem.. | Hobo_man | Operating Systems | 2 | 03-03-2006 09:19 PM |
| Java Problems | Hobo_man | Operating Systems | 1 | 03-03-2006 07:47 PM |