import java.util.Scanner;


public class CalculatingSales
{
    private static boolean Double;



    public static void main(String[] args)
    {

        Scanner input = new Scanner ( System.in );

        int ProductNumber;
        double RetailPrice;
        double total = 0;
        int Product1Count = 0;
        int Product2Count = 0;
        int Product3Count = 0;
        int Product4Count = 0;
        int Product5Count = 0;

        System.out.print (" Enter Product Number: ");
        ProductNumber = input.nextInt();

        Switch ( ProductNumber );
        {

            case 1:
                System.out.print("Product1 Retail Price is 2.98");
            break;
            case 2:
                System.out.print("Product2 Retail Price is 4.50 ");
            break;
            case 3:
                System.out.print("Product3 Retail Price is 9.98");
            break;
            case 4:
                System.out.print("Product4 Retail Price is 4.49");
            break;
            case 5:
                System.out.print("Product5 Retail Price is 6.87");
                default :
                    System.Out.print("We are sorry, we do not have this product");


        System.out.print("Enter Retail Price");

        RetailPrice = input.nextDouble();

        while ( RetailPrice != -1);
        {  
            total += RetailPrice;

        }

        System.out.print("Total Price of Products sold " + total);

        System.out.printf("%s\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n",
                "Number of items sold for each product:",
                "Product1:", Product1Count,
                "Product2:", Product2Count,
                "Product3:", Product3Count,
                "Product4:", Product4Count,
                "Product5:", Product5Count);

    }


    }



}

IT KEEPS TELLING ME THAT IT CAN'T FIND SYMPOLE.

PLZZ HELP ME

Edited 3 Years Ago by Reverend Jim: Fixed formatting

I'm pretty sure switch must be lowercase 's'.
Also no semicolon after the parentheses after switch.
And on first glance it doesnt look like you closed the statement in the appropriate place. You should close your switch after the text of the default case.
One last thing, please use code tags to make the code more readable.

Edited 7 Years Ago by Grn Xtrm: n/a

I don't know you tell me. :)
But seriously, tell me the error being reported by the compiler.
Also post your updated code.

Edited 7 Years Ago by Grn Xtrm: n/a

that program is an application to this question : ( Please check it for me
and tell me if there is anything wrong)

An online retailer sells five products whose retail prices are as follows: Product 1, $2.98; product 2, $4.50; product 3, $9.98; product 4, $4.49; and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows:
a) product number
b) quantity sold

Your program should use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results.

You should really proofread your code before posting.
Look at the print statement for your defalt case.

System.out.print

Shouldn't be capital Out

oh i am sorry i got it and i got the switch statement, but can you help me in solving that question ?

ok then whats wrong with my while statement

Do not put a semi-colon at the end of your while statement.

Ok this code runs without syntax errors but you still have some program errors.

import java.util.Scanner;


public class CalculatingSales
{
private static boolean Double;

public static void main(String[] args)
{

Scanner input = new Scanner ( System.in );

int ProductNumber;
double RetailPrice;
double total = 0;
int Product1Count = 0;
int Product2Count = 0;
int Product3Count = 0;
int Product4Count = 0;
int Product5Count = 0;

System.out.print (" Enter Product Number: ");
ProductNumber = input.nextInt();

switch ( ProductNumber )
{

case 1:
System.out.println("Product1 Retail Price is $2.98");
break;
case 2:
System.out.println("Product2 Retail Price is $4.50 ");
break;
case 3:
System.out.println("Product3 Retail Price is $9.98");
break;
case 4:
System.out.println("Product4 Retail Price is $4.49");
break;
case 5:
System.out.println("Product5 Retail Price is $6.87");
default :
System.out.println("We are sorry, we do not have this product");
}//You forgot this

System.out.print("Enter Retail Price: ");

RetailPrice = input.nextDouble();

while ( RetailPrice != -1)/*This is an infinite loop which needs to be changed; it will never be equal to -1 so it will never end instead it will increase forever*/
{
total += RetailPrice;

}

System.out.print("Total Price of Products sold " + total);

System.out.printf("%s\n%s%d\n%s%d\n%s%d\n%s%d\n%s%d\n",
"Number of items sold for each product:",
"Product1:", Product1Count,
"Product2:", Product2Count,
"Product3:", Product3Count,
"Product4:", Product4Count,
"Product5:", Product5Count);

}


}

I would write this with a 'while' and a 'switch' inside the 'while' and I would make the 'switch' add up everything for me which will be displayed after the 'while' loop is finished.

Edited 7 Years Ago by qzmowx: n/a

This article has been dead for over six months. Start a new discussion instead.