Go Back   Java Programming Forums > Java Standard Edition Programming Help > What's Wrong With My Code?


Reply
 
LinkBack Thread Tools Display Modes
  #11 (permalink)  
Old 11-03-2010, 05:56 AM
helloworld922's Avatar
Super Moderator
 

Join Date: Jun 2009
Posts: 1,215
Thanks: 5
Thanked 258 Times in 234 Posts
helloworld922 will become famous soon enoughhelloworld922 will become famous soon enoughhelloworld922 will become famous soon enough
Default Re: Calculate federal taxes program! Help!

oops, my bad. I forgot to shuffle the sumOfTax calculation around. that line should go underneath the if/else statements (after you've calculated the new tax dollar cost).

You still have the "%%" in your printf statements. If you notice in my above post, I removed them. Also, it would be a good idea to print out some newline characters to make your output clear-er.

Java Code
System.out.printf("The tax is $%.2f\n ", tax);	
			System.out.printf("The sumOfTax is $.2f\n",sumOfTax);



__________________
ASCII a question .. Get an ANSI

Please surround your code with [highlight=Java]code goes here[/highlight].
Reply With Quote
The Following User Says Thank You to helloworld922 For This Useful Post:
ocmjt (11-03-2010)
Sponsored Links
Java Training from DevelopIntelligence
  #12 (permalink)  
Old 11-03-2010, 06:12 AM
Junior Member
 

Join Date: Mar 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
ocmjt is on a distinguished road
Default Re: Calculate federal taxes program! Help!

I dont think I put it in the right spot? Still no answer comes up?

Java Code
public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);
		final double LOWTAXRATE = 0.1;
		final double MEDTAXRATE = 0.15;
		final double HIGHTAXRATE = 0.33;
		double sumOfTax=0;
		System.out.println("Please input the income, type -1 to end");
		double income = keyboard.nextDouble();
		double tax=0;
		
		
		while(income>=0) {
		
			

		
	if(income<=15000)
		tax=income*LOWTAXRATE;
	else if(income>60000)
		tax=8250+(income-60000)*HIGHTAXRATE;
	else if(income<=60000&&income>15000)
		tax=1500+(income-15000)*MEDTAXRATE;
	
		}
		
		sumOfTax = sumOfTax + tax;
		System.out.printf("The tax is $%.2f ", tax);
		System.out.printf("The total tax is $%.2f ", sumOfTax);
		System.out.println("Please input the income, type -1 to end");
		income = keyboard.nextDouble();
				
		
	
}
	
}
Reply With Quote
  #13 (permalink)  
Old 11-03-2010, 06:18 AM
Junior Member
 

Join Date: Mar 2010
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
ocmjt is on a distinguished road
Default Re: Calculate federal taxes program! Help!

I think I got it..thanks a lot for your help! Can you explain what you mean with newline characters?
and does this look right?
Java Code
import java.util.Scanner;
public class IncomeTax {

	/**
	 * This program calculates federal taxes on a list containing various incomes
	 * Author: Marco Tomasello
	 * Date: March 8, 2010
	 */
	public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);
		final double LOWTAXRATE = 0.1;
		final double MEDTAXRATE = 0.15;
		final double HIGHTAXRATE = 0.33;
		double sumOfTax=0;
		System.out.println("Please input the income, type -1 to end");
		double income = keyboard.nextDouble();
		double tax=0;
		
		
		while(income>=0) {
		
			

		
	if(income<=15000)
		tax=income*LOWTAXRATE;
	else if(income>60000)
		tax=8250+(income-60000)*HIGHTAXRATE;
	else if(income<=60000&&income>15000)
		tax=1500+(income-15000)*MEDTAXRATE;
	
		
		
		sumOfTax = sumOfTax + tax;
		System.out.printf("The tax is $%.2f ", tax);
		System.out.println("Please input the income, type -1 to end");
		income = keyboard.nextDouble();
		}
		System.out.printf("The total tax is $%.2f ", sumOfTax);	
		
	
}
	
}
Reply With Quote
  #14 (permalink)  
Old 11-03-2010, 03:25 PM
helloworld922's Avatar
Super Moderator
 

Join Date: Jun 2009
Posts: 1,215
Thanks: 5
Thanked 258 Times in 234 Posts
helloworld922 will become famous soon enoughhelloworld922 will become famous soon enoughhelloworld922 will become famous soon enough
Default Re: Calculate federal taxes program! Help!

Yeah, I guess that looks like what you want. Newline characters are what put lines of text on different lines. Ex:

Java Code
System.out.println("This has no new lines. These two sentences are on the same line.");
System.out.println("The new line character is \\n.\n These two sentences are on different lines.");
__________________
ASCII a question .. Get an ANSI

Please surround your code with [highlight=Java]code goes here[/highlight].
Reply With Quote
The Following User Says Thank You to helloworld922 For This Useful Post:
ocmjt (11-03-2010)
Reply

Thread Tools
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
Check difference between no. of stops, calculate cost JavaStudent23 Java Theory & Questions 4 17-11-2009 07:29 AM
Calculate primes help TommyFiz What's Wrong With My Code? 3 28-10-2009 03:41 AM
Simple java program to calculate wall covering of a room parvez07 What's Wrong With My Code? 3 22-08-2009 08:31 PM


100 most searched terms
Search Cloud
2 dimensional arraylist java 2d arraylist java actionlistener actionlistener in java addactionlistener addactionlistener java convert double to integer java double format java double to integer in java double to integer java drag en drop programmeren java eclipse shortcut keys exception in thread "awt-eventqueue-0" java.lang.outofmemoryerror: java heap space exception in thread "main" java.lang.nullpointerexception exception in thread "main" java.lang.outofmemoryerror: java heap space format double in java format double java get mouse position java java 2d arraylist java actionlistener java double format java double formatting java double to int java double to integer java format double java forum java forums java get mouse position java list to map java mouse position java programming forum java programming forums java programming practice problems java send keystrokes to another application java two dimensional arraylist java.io.ioexception: premature eof java.lang.classformaterror: truncated class file java.lang.outofmemoryerror: java heap space java.util.arraylist jbutton action jbutton actionlistener jtextarea font jtextfield font size jxl.read.biff.biffexception: unable to recognize ole stream programming mutators and generics smack api two dimensional arraylist two dimensional arraylist java unable to sendviapost to url what is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

All times are GMT. The time now is 02:06 AM.
Powered by vBulletin® Copyright ©2000-2009, Jelsoft Enterprises Ltd.