ComputerForum.com ComputerForum.com  

Go Back   Computer Forum > Computer Software > General Software

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 10-22-2009, 07:30 AM   #1 (permalink)
banned
 
Join Date: Dec 2007
Location: Los Angeles
Posts: 3,896
Default Need help, basic Java

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));
        
    }
}
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.

Vizy is offline   Reply With Quote


Old 10-22-2009, 07:33 AM   #2 (permalink)
banned
 
Join Date: Dec 2007
Location: Los Angeles
Posts: 3,896
Default

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
Vizy is offline   Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT +1. The time now is 06:34 AM.


Powered by: vBulletin Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.0 ©2009, Crawlability, Inc.