Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Making a tax program

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Making a tax program

    The code is below and the problem I am having is the numbers after the decimal won't add together for the total I am teaching myself java through liang's 10th edition book and I took one of the sample programs further than what was shown. The one in the book only shows the tax amount I simply wanted to make it so that the purchase amount and the tax amount would add together


    package javalearning;
    import java.util.Scanner;



    public class FindingTax {
    public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    System.out.print("Enter Purchase amount: ");
    double purchaseAmount = input.nextDouble();
    double taxAmount = purchaseAmount * 0.0825;
    System.out.println("Sales tax is $" + (int)(taxAmount * 100) /
    100.0);
    double taxTotal =(int) ((taxAmount * 100) / 100.0);
    double TotalAmount = ((double)(taxTotal * 1.00) + purchaseAmount);

    System.out.println("The total amount to pay is:" + TotalAmount);
    }
    }


    This is the result

    run:
    Enter Purchase amount: 125.25
    Sales tax is $ 10.33
    The total amount to pay is: 135.25
    BUILD SUCCESSFUL (total time: 5 seconds)

    Any and all help is very appreciated.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,407
    Thanks
    53
    Thanked 2,399 Times in 2,352 Posts

    Default Re: Making a tax program

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE GOES HERE
    [/code]
    to get highlighting and preserve formatting.

    make it so that the purchase amount and the tax amount would add together
    Can you explain what that means? Perhaps an example of the desired output would help.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Location
    British Columbia, Canada
    Posts
    6
    My Mood
    Busy
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Making a tax program

    Quote Originally Posted by sevengreen7 View Post
    The code is below and the problem I am having is the numbers after the decimal won't add together for the total I am teaching myself java through liang's 10th edition book and I took one of the sample programs further than what was shown. The one in the book only shows the tax amount I simply wanted to make it so that the purchase amount and the tax amount would add together


    package javalearning;
    import java.util.Scanner;



    public class FindingTax {
    public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    System.out.print("Enter Purchase amount: ");
    double purchaseAmount = input.nextDouble();
    double taxAmount = purchaseAmount * 0.0825;
    System.out.println("Sales tax is $" + (int)(taxAmount * 100) /
    100.0);
    double taxTotal =(int) ((taxAmount * 100) / 100.0);
    double TotalAmount = ((double)(taxTotal * 1.00) + purchaseAmount);

    System.out.println("The total amount to pay is:" + TotalAmount);
    }
    }


    This is the result

    run:
    Enter Purchase amount: 125.25
    Sales tax is $ 10.33
    The total amount to pay is: 135.25
    BUILD SUCCESSFUL (total time: 5 seconds)

    Any and all help is very appreciated.
    As Norm said as above, use the code tags. So you're asking the numbers won't add up in decimal form? Well thats because you're casting them to an integer.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Making a tax program

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly using code or highlight tags per the above link.

Similar Threads

  1. [SOLVED] Tax calculation program
    By howardderamus1111 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 12th, 2014, 05:44 PM
  2. Why wont my program calculate sales tax?
    By scholaryoshi in forum What's Wrong With My Code?
    Replies: 2
    Last Post: February 28th, 2012, 08:30 PM
  3. help with tax program???
    By JavaNewb3 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 31st, 2011, 12:34 PM
  4. First, simple, two-classed tax program
    By rousseau in forum What's Wrong With My Code?
    Replies: 5
    Last Post: May 24th, 2011, 02:14 PM
  5. tax return program..help finish please!!
    By dscrudato21xo in forum Loops & Control Statements
    Replies: 2
    Last Post: November 5th, 2009, 03:23 PM