Help! A question about programming?
-
So I'm on this question and I have to do this: b) Write a Java program to calculate and print a bill of sale based on the following: - the cashier must enter in the amount of the item purchased (type in an amount less than $15) - enter the amount tendered ($20) (assume it will be larger than the purchase price, and when testing your program always enter a value greater than the tender) -calculate taxes (GST at 7%, PST at 8% calculated separately), total bill, and change -output the entire bill showing purchased price, taxes, total and change So this is what I have so far: import java.io.*; import hsa.Console; import java.awt.*; import java.text.*; public class Bill2 { public static void main (String[] args) throws IOException { String bill, tendered; DataInputStream keyboard = new DataInputStream(System.in); System.out.println("Tender: "); bill = keyboard.readLine(); System.out.println("Subtotal: " + bill); System.out.println("Amount tendered: "); tendered = keyboard.readLine(); //variable declaration int tendered, at; double t, st, g, p, gst, pst, bill; /* *at represents amount tendered *t represents the total amount *st represents the subtotal *g represents the gst percent *p represents the pst percent *gst represent the percent on tender *pst represents the percent on tender */ //variable initialization g = 0.07; p = 0.08; //calculations st = (bill * g) + (bill * p) + st; } } I don't understand what to do next ): I'm a bit confused on the whole question actually. I already know how to input colour and cursor commands so I'll do all that later, I just don't understand the question and I don't really know what I'm doing.. Thanks! :D
-
Answer:
I haven't touched Java in a long time, so I might be off in a few places. But I'll give you basic idea. Use this to set up your Reader (#1): InputStreamReader convert = new InputStreamReader(System.in); BufferedReader stdin = new BufferedReader(convert); String tempString = ""; 1. Enter amount *Purchased.* tempString = stdin.readLine(); double amountPurchased = new Double(tempString).doubleValue(); 2. Enter amount *tendered* tempString = stdin.readLine(); //Maybe use a different variable. double amountTendered = new Double(tempString).doubleValue(); 3. Calculate taxes: double GST_Tax = 1.07; double PST_Tax = 1.08; double GST_TaxTotal = (amountPurchased * GST_Tax); double PST_TaxTotal = (amountPurchased * PST_Tax); double totalWithTaxes = GST_TaxTotal + PST_TaxTotal; 4. Maybe *here* you should do some validation as to: if ( amountTendered > totalWithTaxes ) then OK else NOT OK. 5. Calculate change: double change = amountTendered - totalWithTaxes; 6. Output: System.out.println("Purchased price: " + amountPurchased); System.out.println("GST Tax: " + GST_TaxTotal); System.out.println("PST Tax: " + PST_TaxTotal); System.out.println("Total with tax: " + totalWithTaxes); System.out.println("Amount tendered: " + amountTendered); System.out.println("Change: " + change); hope this helps, and I hope my logic isn't wrong.
єm.lєαh.... at Yahoo! Answers Visit the source
Other answers
First - think about the problem you're solving. a) You need to record the price of the item being purchased a.a) Calculate the taxes involved. Taxes are applied to the item being purchased. a.a.b) GST = 1.07 * itemPrice, PST = 1.08 * itemPrice. totalTax = PST + GST. a.a.c) Now the total bill amount (subtotal) will be itemPrice + totalTax. b) You need record the amount of money being tendered. c) Calculate the change required. c.a) amountTendered - subTotal d) Print the required information. Now you understand the problem well enough to solve it, start coding. Always declare any variables at the beginning. It makes it easier to read. Always use descriptive variable names. Always use the most appropriate data types. public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); final float GST = 1.07; final float PST = 1.08 float itemPrice; float amountTendered; float subTotal; float totalTax; float change; float gstAmount; float pstAmount; System.out.print("Item Price: "); itemPrice = input.nextFloat(); gstAmount = GST * itemPrice; pstAmount = PST * itemPrice; totalTax = pstAmount + gstAmount; subTotal = itemPrice + totalTax; System.out.println("\nAmount Tendered: "); amountTendered = input.nextFloat change = amountTendered - subTotal; System.out.println("Item Price: " + itemPrice); System.out.println("\nTaxes..."); System.out.println("GST: " + gstAmount); System.out.println("PST: " + pstAmount); System.out.println("Total Tax: " + totalTax); System.out.println("\nTotal Amount: " + subTotal); System.out.println("Change: " + change); } This is untested, so some changes might have to be made before you hand it in.
Related Q & A:
- How do you insert a picture on yahoo when you ask a question?Best solution by Yahoo! Answers
- How do i attach a picture to a question?Best solution by Yahoo! Answers
- How do you add a link to a photo on a question?Best solution by Yahoo! Answers
- How to remove a question in the ask question editor?Best solution by Meta Stack Overflow
- How can I get a career in programming?Best solution by cplus.about.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.