Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Quiz/thinly disguised helpme

Name: Anonymous 2008-10-12 12:38

/*TODO
 * Have something actually call printData
 */

import java.util.Scanner;

public class IRS
{
    public static void main(String[] args)
    {
        new IRS();
    }
    private Scanner in;
    private int married;
    private double income;
   
    public IRS()
    {
        married = 1;
        income = 0;
        in = new Scanner(System.in);

    }
   
    public IRS(int m, double i)
    {
        married = m;
        income = i;
        in = new Scanner(System.in);
    }
   
    public boolean inputData()
    {
        boolean valid = false;
        System.out.print("Enter marital status (1=single, 2=married): ");
        married = in.nextInt();
        if(married == 1 || married == 2)
        {
            valid = true;
        }
        System.out.print("Enter taxable income: ");
        income = in.nextDouble();
        if(income < 0)
        {
            valid = false;
        }
        return valid;
    }
   
    public double calcTax()
    {
        if(married == 1)
        {
            if(income <= 2750)
            {
                return income * 0.15;
            }
            else if(income <= 65550)
            {
                return (income - 27050) * 0.275 + 4057.5;
            }
            else if(income <= 136750)
            {
                return (income - 65550) * 0.305 + 14645;
            }
            else if(income <= 297350)
            {
                return (income - 136750) * 0.355 + 36361;
            }
            else
            {
                return (income - 297350) * 0.391 + 93374;
            }
        }
       
        else
        {
            if(income <= 45200)
            {
                return income * 0.15;
            }
            else if(income <= 109250)
            {
                return (income - 45200) * 0.275 + 6780;
            }
            else if(income <= 166500)
            {
                return (income - 109250) * 0.305 + 24393.75;
            }
            else if(income <= 297350)
            {
                return (income - 166500) * 0.355 + 41855;
            }
            else
            {
                return (income - 297350) * 0.391 + 88306;
            }
        }
    }

    public void printData()
    {
        System.out.print("Your Federal tax= ");
        System.out.printf("$%.2f", calcTax());
        System.out.println();
    }

}
//The goal: modify this program to actually take the user's input and call printData() after doing calculations

Name: Anonymous 2008-10-12 13:11

You need to call the inputData and printData in your main method. Like this:
public static void main(String[] args)
{
    IRS irs = new IRS();
    irs.inputData();
    irs.readData();
}

Name: Anonymous 2008-10-12 13:52

This code makes me cry.

Name: Anonymous 2008-10-12 21:47

import java.util.Scanner;

public class IRS {
    private Scanner in;
    private int married;
    private double income;
   
    final static int MARRIED;
    final static int UNMARRIED;
   
    public static void main(String[] args) {
        IRS cunt = new IRS();
        if (cunt.inputData())
            cunt.printData();
    }
  
    public IRS() {
        this(1, 0.0);
    }
  
    public IRS(int m, double i) {
        married = m;
        income = i;
        in = new Scanner(System.in);
    }
  
    public boolean inputData() {
        boolean valid = false;
        System.out.print("Enter marital status (1=single, 2=married): ");
        married = in.nextInt();
        System.out.print("Enter taxable income: ");
       
        return (married == MARRIED || married == UNMARRIED) && income >= 0
    }
  
    public double calcTax() {
        if (married == UNMARRIED) {
            if (income <= 2750)
                return income * 0.15;
            if (income <= 65550)
                return (income - 27050) * 0.275 + 4057.5;
            if(income <= 136750)
                return (income - 65550) * 0.305 + 14645;
            if(income <= 297350)
                return (income - 136750) * 0.355 + 36361;
            return (income - 297350) * 0.391 + 93374;
        }

        if (income <= 45200)
            return income * 0.15;
        else if (income <= 109250)
            return (income - 45200) * 0.275 + 6780;
        else if (income <= 166500)
            return (income - 109250) * 0.305 + 24393.75;
        else if (income <= 297350)
            return (income - 166500) * 0.355 + 41855;
        return (income - 297350) * 0.391 + 88306;
    }

    public void printData() {
        System.out.printf("Your Federal tax= $%.2f\n", calcTax());
    }

}

Name: Anonymous 2008-10-13 3:20

>>4
I like how you make a "valid" boolean in your inputData(), yet you never return in and decide to return that piece of shit instead:
        return (married == MARRIED || married == UNMARRIED) && income >= 0

I fucking hate seeing multiple returns/returns that don't return a variable. Almost makes me rage as much as seeing Exit For

Name: Anonymous 2009-06-25 18:54

testetsatestestte
teste
stestestest
eststeste

Name: Anonymous 2011-02-04 15:42


Don't change these.
Name: Email:
Entire Thread Thread List