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 E to stop the programme

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Enter E to stop the programme

    My question is : [B]Modify the programme that can calculate total sales of the day, total wholesaler(s), total retailer(s). The user will need to enter 'E' for customer type to the stop the program/B]

    How do I execute the program right away at the first prompt-user(type of customer) without entering input for the second one (no. of units)?




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

    {
    Scanner sc = new Scanner(System.in);

    System.out.println("INSTRUCTIONS; Enter a code based on type of customer, enter E to quit");
    System.out.println("eg. Wholesaler ==> w");
    System.out.println(" Retailer ==> r");
    System.out.println(" ");
    System.out.print("Enter code : ");
    String customer = sc.next();

    System.out.print("Enter no. of unit(s) : ");
    int unit = sc.nextInt();

    double price=0, total=0;
    int w=0, r=0;

    while (!customer.equals("E"))
    {
    if (customer.equals("w"))
    {
    w = w + 1;
    if (unit >= 5)
    price = 9*unit;
    else
    price = 10*unit;
    }


    else if (customer.equals("r"))
    {
    r = r + 1;
    if (unit <= 3)
    price = 15*unit;
    else if (unit <= 8)
    price = 14*unit;
    else
    price = 12*unit;
    }
    else
    System.out.println("Invalid code entered");

    total = total + price;

    System.out.println(" ");
    System.out.print("Enter code : ");
    customer = sc.next();
    System.out.print("Enter no. of unit(s) : ");
    unit = sc.nextInt();
    }
    System.out.println("Total sales of the day = RM" + String.format("%.2f",total));
    System.out.println("Total wholesaler(s) : " + w);
    System.out.println("Total retailer(s) : " + r);
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Enter E to stop the programme

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    How do I execute the program right away at the first prompt-user(type of customer) without entering input for the second one (no. of units)?
    Use some conditional test like an if statement to control asking the second question based on what was entered for the first question.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Can someone programme for me?
    By chemical_dog in forum Paid Java Projects
    Replies: 9
    Last Post: November 7th, 2013, 05:37 PM
  2. I don't understand what's wrong in my programme
    By si3012 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 16th, 2013, 07:58 AM
  3. Help with designing a library programme
    By clarky2006 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 8th, 2012, 05:40 AM
  4. please correct my programme on swings
    By jeevan reddy mandali in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 6th, 2012, 03:32 AM
  5. help with bookfinder programme
    By kidza12 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 9th, 2011, 02:15 PM

Tags for this Thread