Hi i am new to java and i need help to write program for this problem

Updating inventory
A national chain is making room for new inventory, so it is selling existing inventory at discounted prices. All products in the store are on sale, but the markdown percentage varies depending upon the product sold. Write a program that accepts information from the user (store clerk), calculates the new markdown price and final selling price, and displays a receipt of this information for the customer.
Information entered by the user (store clerk) includes:

• • The product’s original price
• • The percentage discount for the product
• • The sales tax rate (varies according to county and state) The program then outputs the following information:
• • The product name
• • The product’s original price
• • The percentage discount
• • The store’s selling price of the product
• • The sales tax rate
• • The sales tax
• • The final price of the product (selling price plus sales tax)
This is an example of what your program should look like when it runs: (Bold items are entered by the user; these values may change each time the program runs depending what the user enters)
PRODUCT INFORMATION
Please enter the name of the product: Table
Please enter the original price: 55.00
Please enter the percentage discount (such as 15 for 15%): 10 Please enter the sales tax rate (such as 7.25 for 7.25%): 6.5

Updating inventory 
A national chain is making room for new inventory, so it is selling existing inventory at discounted prices. All products in the store are on sale, but the markdown percentage varies depending upon the product sold. Write a program that accepts information from the user (store clerk), calculates the new markdown price and final selling price, and displays a receipt of this information for the customer. 
Information entered by the user (store clerk) includes: 
•   •  The product name 
•   •  The product’s original price 
•   •  The percentage discount for the product 
•   •  The sales tax rate (varies according to county and state) The program then outputs the following information: 
•   •  The product name 
•   •  The product’s original price 
•   •  The percentage discount 
•   •  The store’s selling price of the product 
•   •  The sales tax rate 
•   •  The sales tax 
•   •  The final price of the product (selling price plus sales tax) 
This is an example of what your program should look like when it runs: (Bold items are entered by the user; these values may change each time the program runs depending what the user enters) 
PRODUCT INFORMATION
Please enter the name of the product: Table
Please enter the original price: 55.00
Please enter the percentage discount (such as 15 for 15%): 10 Please enter the sales tax rate (such as 7.25 for 7.25%): 6.5 
      CUSTOMER RECEIPT       
Product name: Table      
 Original price: $55.0       
Percentage discount: 10%       
Selling price: $49.5       
Sales tax: $3.2175       
Final product price: $52.7175 

Product name: Table
Original price: $55.0
Percentage discount: 10%
Selling price: $49.5
Sales tax: $3.2175
Final product price: $52.7175

Recommended Answers

All 25 Replies

Please write some code and then post it where you stuck.

This seems like a pretty straightforward (and easy) beginners assignment. You haven't even tried to write it on your own. Something tells me you won't find this class very easy.

There are lots of people here who will freely give their time to help you become the best Java programmer you can be. There's nobody here who is interested in helping you cheat or doing your homework for you.

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do provide evidence of having done some work yourself if posting questions from school or work assignments"
http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

sorry i forgot to post the code help me fix it

 public static void main(String[] args) {
        //Declare variables

        double dOriginalprice = 0;
        // Origiona price entered by user

        float fDiscount = 0 ;
        // Discount entered by user

        double dSellingPrice =0 ;
        //total discount from user input

        float fSalesTax = 0 ;
        // Sales tax entered by user

        double dTotalPrice = 0 ;
        //total calculate from sales tax

        Scanner input = new Scanner(System.in); //Used to read input from the console



        //Prompt user for product
        System.out.print("Please enter the name of the product: ");
        //Read Product from user


        //Prompt user for original price
        System.out.print("Please enter the original price: ");
        //Read inches from user
        dOriginalprice = input.nextDouble();

        //Prompt user for discount 
        System.out.print("Please enter the percentage discount (such as 15 for 15%):");
        //Read inches from user
        fDiscount  = input.nextFloat();

        //Prompt user for sales tax
        System.out.print("Please enter the sales tax rate (such as 7.25 for 7.25%):");
        //Read inches from user
        fSalesTax = input.nextFloat();

        //Calculate total selling price 
         dSellingPrice = dOriginalprice -(fDiscount / 100)*(dOriginalprice);

        // Calculate sales tax
          dTotalPrice =  dSellingPrice + (fSalesTax / 100); 

          //Print Product
        System.out.println("Product " + dOriginalprice);

        //Print Original Price
        System.out.println("Original Price " + dOriginalprice);

        //Print Original Price
        System.out.println("Original Price " + dOriginalprice);

        //Print Discount
        System.out.println("Percentage Discount " + fDiscount);  

        //Print Selling Price
        System.out.println("Selling Price " + dSellingPrice);

        //Print Sales Tax 
        System.out.println("Sales Tax " + fSalesTax);


        //Print Final Price
        System.out.println("Final PRice " + dTotalPrice);


         String input = JOptionPane.showInputDialog("Enter Input:");

                   System.out.println(input);

when is the deadline?

and also, what is your specific question ? The code snippet you posted is not your complete code. If it was: your code wouldn't compile.

Could you please be complete about both ?

deadlines is today at 9pm
and i cant finish its my first time doing this

I presume the code listing you posted earlier is now out of date. What have you done to your code in the last 13 hours?

i have edit a littel but it still need help with few stuff

1st is how do i wrote product name after the output

2nd how do i write my calculation for discout and sales tax
3rd my calculaiton doestn show on output

please help me its my 1st time writing this code and idk if i am right or not

 public static void main(String[] args) {
        //Declare variables
        double dOriginalprice = 0;
        // Origiona price entered by user
        float fDiscount = 0 ;
        // Discount entered by user
        double dSellingPrice =0 ;
        //total discount from user input
        float fSalesTax = 0 ;
        // Sales tax entered by user
        double dTotalPrice = 0 ;
        //total calculate from sales tax
        Scanner input = new Scanner(System.in); //Used to read input from the console


        //Prompt user for product
        System.out.print("Please enter the name of the product: ");
        //Read Product from user
        //Prompt user for original price
        System.out.print("Please enter the original price: ");
        //Read inches from user
        dOriginalprice = input.nextDouble();
        //Prompt user for discount 
        System.out.print("Please enter the percentage discount (such as 15 for 15%):");
        //Read inches from user
        fDiscount  = input.nextFloat();
        //Prompt user for sales tax
        System.out.print("Please enter the sales tax rate (such as 7.25 for 7.25%):");
        //Read sales tax from user
        fSalesTax = input.nextFloat();


        //Calculate total selling price 
         dSellingPrice = dOriginalprice -(fDiscount / 100)*(dOriginalprice);
        // Calculate sales tax
          dTotalPrice =  dSellingPrice + (fSalesTax / 100); 
          //Print Product



       System.out.println("Product " + dOriginalprice);
        //Print Original Price
        System.out.println("Original Price " + dOriginalprice);
        //Print Original Price
        System.out.println("Original Price " + dOriginalprice);
        //Print Discount
        System.out.println("Percentage Discount " + fDiscount);  
        //Print Selling Price
        System.out.println("Selling Price " + dSellingPrice);
        //Print Sales Tax 
        System.out.println("Sales Tax " + fSalesTax);
        //Print Final Price
}
}
  1. Use a String variable for the name. At line 18 you can use Scanner's nextLine() method to read the user's input as a String, and down around line 40 you can print it.

  2. You discount calc looks ok. The sales tax is amost identical, except that it's added to the price not subtracted from it

  3. I don't understand you. What you see is what you coded println's for.

well how do i write a string code for product type ____

I'm quite certain your class has covered how to use String variables. I'm not going to do your homework for you.

no we havent done any strings yet we will cover it next week, and its not a hw its a practice problem

OK, that explains why you have a requirement that needs a String when you haven't learned them yet!
In that case it's probably best of you just leave out the product name part. You can go back to it after your course has covered Strings next week.

oh okay well when i run the code and put in the number will it calculate automaticlly

and also how do would i be able to calcualte percent like

$55 * 10%

It will execute all those instructions in the order you coded them so, yes, it will calculate after getting the input and before printing

You calculate percentages the same way as you already did on lines 34 and 36 (divide the percentage by 100). Just make sure you are using float or double variables because int variables don't do fractions.

oh okay thank you and one more questions how do write a int code to use letters instead of numbers

You don't.
ints are for whole numbers
floats/doubles are for fractions and very large nunbers
chars and Strings are for letters (as you will learn next week!)

oh ok thank you

hey i am getting some yellow ligbult symbols next to this codes can you please check

double dOriginalprice = 0; 
        float fDiscount = 0 ;  
        double dSellingPrice =0 ; 
        float fSalesTax = 0 ;
        double dTotalPrice = 0 ; 
        Scanner input = new Scanner(System.in);

Probably because a double and a float are values with a decimal point such as 1.2345 while you set the initial value of your fields to be a whole number, "0" in your case. Should be fixed if you set it to 0.0

i already tried that it still doesnt go away

double dOriginalprice = 0.0;   // Origiona price entered by user

        float fDiscount = (float) 0.0;   // Discount entered by user

        double dSellingPrice =0.0 ;
       //total discount from user input

        float fSalesTax = (float) 0.0 ;
        // Sales tax entered by user

        double dTotalPrice = 0.0 ;
        //total calculate from sales tax

Your IDE should give you a proper error message, not just an icon. The error message will tell you (or us) what the real problem is. Remember it may be something wrong with the immediatley preceeding code (for example, an extra } that closes a class definition, so the followining declarations are illegal).

An option would be, since you are just starting out with Java, to try and compile, package, run your classes without the use of an ide.

Go old school and perform those tasks manually through the command prompt. If (and when) compilation fails, you will be presented by something very ugly, yet extremely handy, called a StackTrace. It will tell you precisely on which line of your code there is a problem and, what problem it is, both the type of the problem and a describing message in understandable english.

but something's fishy here: you claim you haven't learned about String yet, yet you are using them throughout your code, and using classes and methods (JOptionPane, for one) that are far more "advanced". If this is some code you came up with yourself, to help you study, I hope you realize that there is something like "studying the wrong way" which won't help you in the long run.

a double and a float are values with a decimal point such as 1.2345 while you set the initial value of your fields to be a whole number, "0" in your case.

Just FYI, there's no problem initialising a float or double to an integer value.
int to float or double is an example of a widening primitive conversion which is explicity allowed in an assignment context (Java Language Spec 5.2)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.