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 2 of 2

Thread: Enter in name ....need a little bit of help!

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Enter in name ....need a little bit of help!

    Hey guys i'm working on a following project that gives a person how much money there car is going to be with sales tax. here is my code

    import java.util.Scanner;
    import java.text.DecimalFormat;



    public class tad
    {
    public static void main(String[] args)
    {
    final double INTEREST_RATE = 0.075;
    DecimalFormat df = new DecimalFormat("#,000.00");


    Scanner s = new Scanner(System.in); // create a Scanner object
    String input; // read in user input as a string
    double carPrice;
    double carTax;
    double carTotal;
    double personName;

    System.out.print("Please enter your first name ");
    input = s.nextLine();
    personName = Double.parseDouble(input);


    System.out.print("Enter the price of the car: "); // user prompt
    input = s.nextLine(); // read input as a string
    carPrice = Double.parseDouble(input);

    carTax =(carPrice*INTEREST_RATE);
    carTotal=(carPrice + carTax);
    System.out.println ("The Sales tax on your purchase is $" + df.format (carTax));
    System.out.println ("making the total $" + df.format (carTotal));

    }
    } this is what the programs looks like running

    Please enter your first name 99 (i put 99 because i get an error when i type in a name)
    Enter the price of the car: 12345.67
    The Sales tax on your purchase is $925.93
    making the total $13,271.60

    it needs to look like this....
    Please enter your first name Adam
    Enter the price of the car: 12345.67
    Adam,
    The Sales tax on your purchase is $925.93
    making the total $13,271.60.

    thanks alot for your help fellas!


  2. #2
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Enter in name ....need a little bit of help!

    Just so you know, people will not directly give you an answer to your problem. They will (or should) instead, guide you to find the answer..

    Anyway, what exactly is the problem you are having?
    Simplicity calls for Complexity. Think about it.

Similar Threads

  1. Why does it enter this if ?
    By piulitza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 25th, 2011, 11:42 AM
  2. Trying to start a game when 'Enter' is pressed.
    By Shaybay92 in forum AWT / Java Swing
    Replies: 6
    Last Post: September 27th, 2011, 07:48 AM
  3. i dont know why i cant see the output nor enter input
    By Newbiesss in forum What's Wrong With My Code?
    Replies: 2
    Last Post: June 1st, 2011, 12:41 PM
  4. command prompt, acquiring input without enter?
    By kitube in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: January 24th, 2011, 10:14 PM
  5. How to make user press enter to continue in program?
    By BC2210 in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: October 3rd, 2009, 05:08 AM