Need help getting underway
What I am trying to do:
The program shows a history of the status of a single member based on the time
between purchases in months and the actual number of purchases made.
Your program should allow a user to enter in the time between purchases (in months)
from the keyboard. Your program should then ask the user if s/he would like to enter any
more time between purchases from a confirm dialog box. If yes, then get another amount
of time between purchases. If not then begin processing the data. Some users may have
made 10 purchases, some 20, some 50. You do not know the number of purchases ahead
of time. Your program should use at least one for loop and one while loop. Also, your
program should signify (and use) PLATINUM, GOLD, SILVER, BRONZE, and
STANDARD as constants.
Here is my code so far just please get me turned around in the right direction.
import javax.swing.JOptionPane;
public class CustomerStatus {
public static void main(String[] args) {
int time = 0;
int total = 0;
final int STANDARD;
final int SILVER;
final int GOLD;
final int PLATINUM;
final int BRONZE;
int purchase;
int status=?;
for(purchase=0; (++purchase < 2); purchase++)
System.out.println("Purchase Number\tTime before next purchase(months)\tTotal Customer Loyalty(months)\tStatus History");
System.out.println(purchase + "\t\t" + time + "\t\t\t\t\t" + total + "\t\t\t\t" + status);
For example, suppose this is the information entered for one customer for the time before
the next purchase in months:
0 2 12 3 10 50 4
Then a status history needs to be printed out as follows:
Purchase
Number
Time before next
purchase (months)
Total Customer Loyalty
Time (months)
Status
History
1 0 0 STANDARD
2 2 2 STANDARD
3 12 14 STANDARD
4 3 17 SILVER
5 10 27 BRONZE
6 50 77 STANDARD
7 4 81 GOLD
It prints kinda like a table with all off the stuff lined up in columns and the numbers and the status(such as STANDARD) are lined up underneath the headings "Purchase Number" , "Time before next purchase(months)", "Total Customer Loyalty(months)", "Status History"
I see.. First question, do you really need the confirmation dialog box, or can we do away with it so that all user inputs will be from the console? Because if you want the confirmation dialog box, you'll have to program this using Java AWT or Javax Swing, and it's hard to explain that here
Anyway, regardless of what you're gonna use, here's the general algorithm of the program. Let's assume first that user inputs will be from the console.
You'll need a string or char variable that will store the answer of the user if he wants to continue, say
char response = 'Y';
you'll see later on why I initialized it to Y
response can hold values Y or N (yes or no respectively)
Another variable to count the number of rows the user has inputted, say
int counter = 0;
I'd suggest you use a do-while loop since the program has to run at least once, but since you are required to use a while loop, we then check if response is Y (if he wants to continue)
while (response == 'Y') {
// insert code here
}
*I posted that preliminary post so you'll know that I'm working on your program =)
To continue, we now prompt the user for the time before next purchase in months. I think you'll have to store this in an array of integers for future reference, say
int[] time;
So we store the first input in time[counter]
then increment counter
counter++;
We then ask the user if he wants to continue, and store his response in
response
Of course, the loop would continue until the user says N (or No)
Now, we need another variable to store the total, say
int total = 0;
We print the header first
System.out.println("Purchase Number\tTime before next purchase(months)\tTotal Customer Loyalty(months)\tStatus History");
Here comes the for loop!
for (int i=0; i<counter; i++) {
total += time[i];
System.out.println(i+1 + "\t\t" + time[i] + "\t\t" + total + "\t\t" + status);
}
>
Now, the status is another story. I think the status is dependent on the total, and the PLATINUM, GOLD etc are categories in which the status would fall in.
So let's say
final int PLATINUM = 100;
final int GOLD = 80;
final int SILVER = 20;
final int BRONZE = 15;
final int STANDARD = 0;
*apparently in the example you gave, BRONZE is higher than SILVER, so just change it accordingly. And the values there are made up by me, I don't know the real values required
In the for loop, after doing the line
total += time[i];
do an if-else statements to determine the status;
String status;
if (total >= STANDARD && total < BRONZE)
status = "STANDARD";
and so on. These if-else statements should come before the println statement inside the for-loop
Hope that helped =)
I appreciate you working on this Albert I am sooo lost. I am starting to understand it though as you are walking through it. It is like 2 :30 in the morning where I live so I am about to go to bed but will you be on here any tomorrow to pick up where we left off because I want to create another 2 posts and just let you type something in so I can give you 10 dollars for this post 10 dollars for another post and 7 for another one. And I will just name it Albert only and all you have to do is type one word in on each post and I will give you the other 10 and the other 7 after I give you 10 for this one. This thing is due by tomorrow night around this time . I hope you will still be able to help me.
Well, it's 3PM here, so by the time it's morning in your place, it'll be night at my place, hence I'm probably asleep =)
Anyway, you don't have to worry yourself about creating new threads so you can reward me with the stars. I'm just glad that I was able to help you =)
And creating a topic entitled "Albert" will be considered as spam by the moderators lol So don't worry about the stars. I just hope you'll be able to finish what you're doing in time for the deadline =)
Message was edited by:
albertsese
So is that pretty much the entire program you walked through? Or is there still some more to it?
That's pretty much the algorithm... If you'll be using Java AWT or Javax Swing for a GUI, you'll have to be familiar with that because it's hard to explain it here..
like I was thinking I would import javax.swing.JOptionPaneThen I could use the JOptionPane input dialog box for entering the number of months before next purchase and then use another one for the yes or no question do you have any ideas about this ?
I'm afraid it's not as easy as importing and instantiating.. I'm a bit rusty with my AWT and Swing