0

Good day to everyone..
First Here is my code so far..

import java.io.*;
public class Inventory {
    public static void main (String[]args)throws IOException{
        BufferedReader bv = new
                BufferedReader (new InputStreamReader(System.in));
        String x, z;
        boolean y = true;
        int a, b, c, d = 0;
        do
        {

        System.out.println("--------------------------------------------------------------");
        System.out.println("                    M I N I   S T O R E ");
        System.out.println("--------------------------------------------------------------\n");
        System.out.println("Classification  || Product ||  Product Name  ||   Unit Price  ");
        System.out.println("of Product      || Number  ||                ||               ");
        System.out.println("----------------------------------------------------------------");
        System.out.println("1. SHAMPOO      ||  1      ||  Sunsilk       ||   P 5.00");
        System.out.println("                ||  2      ||  Palmolive     ||   P 4.00");
        System.out.println("                ||  3      ||  Rejoice       ||   P 4.00");
        System.out.println("----------------------------------------------------------------");
        System.out.println("2. MILK         ||  4      ||  Nido          ||   P 20.00");
        System.out.println("                ||  5      ||  Bear Brand    ||   P 25.00");
        System.out.println("                ||  6      ||  Alaska        ||   P 20.00");
        System.out.println("----------------------------------------------------------------");
        System.out.println("3. SNACKS       ||  7      ||  Piatos        ||   P 12.00");
        System.out.println("                ||  8      ||  Nova          ||   P 10.00");
        System.out.println("                ||  9      ||  Fritos        ||   P 10.00\n");

        System.out.print("Classification Product No: ");
        x = bv.readLine();
        a = Integer.parseInt(x);

        switch (a){
            case 1: System.out.println("You choose SHAMPOO\n");
                    System.out.println("Available Products:");
                    System.out.println("Product | Product Name");
                    System.out.println("Number  |             ");
                    System.out.println("----------------------");
                    System.out.println(" 1      | Sunsilk     ");
                    System.out.println(" 2      | Palmolive   ");
                    System.out.println(" 3      | Rejoice     ");
            break;   
        }

            System.out.print("Enter Product Number : ");
            x = bv.readLine();
            b = Integer.parseInt(x);

        if (b==1){
            System.out.println("Product Name       : Sunsilk");
            System.out.println("Unit Price         : P 5.00");
        }


            System.out.print("How many you want  : ");
            x = bv.readLine();
            c = Integer.parseInt(x);

        if (b==1){
            d = (5*c);
        System.out.println("Total Price:"+d);    
        }

        System.out.println("\n--------------------------------------");
        System.out.println("   O F F I C I A L   R E C E I P T");
        System.out.println("--------------------------------------\n");

        switch (a){
            case 1: System.out.println(" Product Classification: SHAMPOO");
                break;
        }

        switch (b){
            case 1: System.out.println(" Product Name          : Sunsilk");
                    System.out.println(" Unit Price            : P 5.00");
                break;
        }

    System.out.println(" Quantity              : "+c);
    System.out.println(" Total Price           : P "+d);

     System.out.print("Do you want to buy again? ");
        z = bv.readLine();

         } 
        while(y);

    }     
    }

Now Here is my problem:
1. my do while loop never end.. (Do you want to buy again? (Y/N) ) if y or n it always repeat..
2. And what if their is more than one product to buy?

You can edit or make your own code..
Thanks in advanced..

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by NormR1
1

my do while loop never end.

what does the code do to end the loop? When is y ever set false or a break statement used?

if y or n it always repeat..

where does the program look at the value that the user entered and use it to make a decision about anything?

Edited by NormR1

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.