Very novice Java Question - PLEASE HELP!

Started by
3 comments, last by smc 17 years, 5 months ago
Hey, I'm working on a homework assignment for a course i'm taking in basic Java & I have no idea how to do the second half of the assignment (first half seemed relatively easy). Here's the program: import javax.swing.*; public class GiftStore { public static void main(String[] args) { //variable declaration double price; double quantity; double discountrate; double moneyPaid; double moneySaved; int saleCounter = 0; double totalPaid = 0; double averageDiscount = 0; String productnameString; String priceString; String quantityString; String discountrateString; String productID; String answer; do { //input product ID productID=JOptionPane.showInputDialog("input product ID:"); //input product name productnameString=JOptionPane.showInputDialog("input product name:"); //input price priceString=JOptionPane.showInputDialog("input price:"); price=Double.parseDouble(priceString); //input quantity quantityString=JOptionPane.showInputDialog("input quantity:"); quantity=Double.parseDouble(quantityString); //input discount rate discountrateString=JOptionPane.showInputDialog("input discount rate:"); discountrate=Double.parseDouble(discountrateString); //display product ID System.out.println("Product ID " + productID); //display product name System.out.println("Product Name " + productnameString); // Calculate money paid here. moneyPaid=price*quantity; System.out.println("You pay $" + moneyPaid); //calculate money saved moneySaved=price*quantity*discountrate; System.out.println("You save $" + moneySaved); saleCounter++; //Calculate total paid here totalPaid += moneyPaid; averageDiscount += moneySaved / saleCounter; answer=JOptionPane.showInputDialog("more items? (Y/N)"); } while (answer.equals("Y")||answer.equals("y")); // while loop System.out.println("===== Report ====="); System.out.println("Number of sales: "+saleCounter); System.out.println("Total sales: " +totalPaid); System.out.println("Average discount: $" +averageDiscount); } } Basically, it's a program to calculate store inventory price, quantity, etc... and it creates a loop at the end to enter in more information and, finally, gives a report summar of the number of sales, total sales, avg. discount. That part was easy, but this second part is really killing me. Here's the exact second part of the assignment: "Gift Store -2 The manager of the gift store also wants to have a program that can keep track the sales over a week. That is five days since the store closes on Sundays and Tuesdays. The program will do the same for each day, like what it does in the Gift Store-1. The only added function is that it will do for five days and at the end, print also a report of the total sales for the week and an average day sales. First the program asks input for Day 1 till the user says No more. Then it will continues asks for input for Day 2. (Reuse the program you have in Gift Store-1)" Basically it introduces counters & possibly a do loop. All of the examples and material we've covered in class seem far more simplistic than this. Anyway, this project is due by 5pm EST (less than 2 hours) & I still have to work on flowcharts & screenshots for the assignment to upload online. This probably seems like a preschooler assignment to a lot of you &, therefore, i'd be grateful to anyone who can take out some time & help out. Thanks! EDIT: Just so you guys know, here's a screen of how she expects the input & partial output to look: http://img102.imageshack.us/my.php?image=screensfu6.jpg
Advertisement
I am sure you know most people on these boards choose not to help with HW assignments...

Quote:Original post by Poetic
The manager of the gift store also wants to have a program that can keep track the sales over a week. That is five days since the store closes on Sundays and Tuesdays. The program will do the same for each day, like what it does in the Gift Store-1. The only added function is that it will do for five days and at the end, print also a report of the total sales for the week and an average day sales. First the program asks input for Day 1 till the user says No more. Then it will continues asks for input for Day 2.
(Reuse the program you have in Gift Store-1)"


You can reuse the program from part 1. You just need to find a way to store the totals from each day. Doing this without classes is a bit tedious. Hint... think array, index, offset and another loop.

∫Mc
Thanks for the reply. This assignment isn't worth many points. I mainly just want to know how it's supposed to be done. For some reason she didn't go over anything remotely like this in class. Yes, basic counters she did go over but nothing like this. We haven't started arrays yet - that's next week. I already know what "has" to be done... I simply don't know how to do get it to output in the categories for each day.

After about 7 hours of scratching my head all i've been able to come up with is declaring a dayCounter & ending the program with the statement:

System.out.println("===== Day" + dayCounter + "Report =====");

Oh well... :-/
Ok, well I just submited the assignment. I think I did alright regardless of only getting half the second part done. Thanks anyway for the help & if any of you is still willing to help out i'd be interested in finding the answer out to this - just out of curiousity. I won't see my professor until Monday, so I can't ask her till then. Once again, thanks anyway!
Actually I guess you could just do it using totals for each day they are open. In this case M,W,R,F,S. Then use the same loop you have now inside another loop. The only logic you would need to add to the current loop is a swich where you tally the total. i.e.

while(days < N)
while(user inputting)
switch(day)
M: monday_total = total ;
W: wednesday_total = total ;


∫Mc

This topic is closed to new replies.

Advertisement