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

Thread: Multiplying Strings

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

    Default Multiplying Strings

    Hello, I am taking my first java class and am having a little trouble with my code. I need to come up with a code that comes ups with the total for each items ordered. I have tried many different things but have had no luck. If someone help me out and point me in the right direction it would be appreciated.


    import java.util.Scanner;
    public class Assignment2
    {
    public static void main(String[] args)
    {


    double Hamburger = 2.75;
    double Cheeseburger = 3.25;
    double FrenchFry = 2.50;
    double ShakeBeverage = 1.50;
    double TotalforHamburgers = Double.parseDouble(Hamburgers) * (2.75);

    Scanner in = new Scanner (System.in);
    String Hamburgers;
    String Cheeseburgers;
    String FrenchFries;
    String Drinks;





    System.out.println("Welcome to the In-N-Out Burger Menu");
    System.out.println("------------------------------------");
    System.out.println("Hamburger $2.75");
    System.out.println("Cheeseburger $3.25");
    System.out.println("French Fries $2.50");
    System.out.println("Shake & Beverage $1.50");
    System.out.println(" ");

    System.out.print("How many hamburger(s) would you like to buy? ");
    Hamburgers = in.nextLine();
    System.out.print("How many cheeseburger(s) would you like to buy? ");
    Cheeseburgers = in.nextLine();
    System.out.print("How many french fries would you like to buy? ");
    FrenchFries = in.nextLine();
    System.out.print("How many drinks would you like to buy? ");
    Drinks = in.nextLine();


    System.out.println("The total cost for the hamburger(s) is " + TotalforHamburgers);
    System.out.println("The total cost for the cheeseburger(s) is ");
    System.out.println("The tolal cost for fries is ");
    System.out.println("The total cost for drinks is ");
    System.out.println("Item with the highest cost total is");
    System.out.println("The total cost for the order is ");


    System.out.println("The total number of items ordered is ");
    }
    }


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,490
    My Mood
    Mellow
    Thanks
    152
    Thanked 610 Times in 597 Posts

    Default Re: Multiplying Strings

    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 per the above link.

  3. #3
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    252
    My Mood
    Angelic
    Thanks
    18
    Thanked 38 Times in 33 Posts

    Default Re: Multiplying Strings

    String Hamburgers;
    String Cheeseburgers;
    String FrenchFries;
    String Drinks;

    Why are these a String type? If all they do is store the amount of each
    order - should they not be an integer?

    If they were - you could easily calculate the cost of each order - just
    by multiplying the price by how many ordered.

    Output to the command line in Java is generally done with the '+' operator
    followed by the variable to be printed out.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

Similar Threads

  1. Sorting lowercase strings before uppercase strings
    By keepStriving in forum Java Theory & Questions
    Replies: 4
    Last Post: March 26th, 2014, 03:33 PM
  2. Strings
    By NewCoder in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 27th, 2014, 03:51 AM
  3. Matrix multiplying using separate input classes and a GUI
    By havinFun in forum What's Wrong With My Code?
    Replies: 24
    Last Post: March 17th, 2012, 11:40 AM
  4. Strings
    By Leeds_Champion in forum Algorithms & Recursion
    Replies: 3
    Last Post: November 3rd, 2009, 09:09 PM
  5. Replies: 2
    Last Post: June 19th, 2008, 03:58 AM