The problem I am having with my code is that when I run the code and enter into function 1, I am not able to print out the message saying you have not bought anything. Also, whenever I go to buyitem method and go to listitem method and go back to buy item again, and to list item method again, and then buy item method again, it's not printing out the buyitem method. I am having trouble making it so that the user can go unlimited times between buy item and list item (change value).
I have tried creating variables and updating them and putting them on if else statement in order to know if they have went through the method or not.
public static void main(String[] args) {
int function = 0;
int value = 0;
int rerun = 0;
int check1 = 0;
int check2 = 0;
int check3 =0;
Scanner sc = new Scanner(System.in);
function = userInput(sc);
while (true){
if (function == 1) {
value = userInput2(sc);
String[] names = new String[value];
double[] price = new double[value];
double[] packs = new double [value];
double[] addDiscount = new double [value];
double[] buyItems = new double[value];
double [] addDiscountrate = new double [value];
if(function==1) {
check1 =1;
shopSetup(sc, value, names, packs, addDiscountrate, price, addDiscount);
function = userInput(sc);
}
if (function ==2 && check1 ==1) {
check1 = 2;
buyItems(sc, names, buyItems, value);
function = userInput(sc);
}
if (function ==3 && check1 == 2) {
check1 = 3;
check3 =1;
listItems(names, price, buyItems, value);
function = userInput(sc);
}
if (function ==2 && check3 == 1) {
check3 =2;
buyItems(sc, names, buyItems, value);
function = userInput(sc); //need to return to 2
}
if (function ==3 && check3 == 2) {
listItems(names, price, buyItems, value);
function = userInput(sc); //need to return to 2
}
if (function ==2 && check2 ==10){
buyItems(sc, names, buyItems, value);
function = userInput(sc);
}
if (function ==3 && check1 == 1) {
check2=2;
System.out.println("");
System.out.println("You have not bought anything");
System.out.println("");
function = userInput(sc);
}
if (function ==4 && check1 == 1) {
check2=3;
System.out.println("");
System.out.println("You have not bought anything");
System.out.println("");
function = userInput(sc);
}
if (function ==4 && check1 == 3) {
checkOuts(names, price, packs, addDiscount, buyItems, addDiscountrate, value);
System.out.println("-------------------------------------------------\r\n" +
" Would you like to re-run (1 for yes, 0 for no)? \r\n" +
"-------------------------------------------------");
rerun = sc.nextInt();
}
if (rerun == 1) {
function = userInput(sc);
}
else break;
}
else
if (function ==2 || function ==3 ||function ==4 && check1 == 0){
System.out.println("");
System.out.println("Shop is not set up yet");
System.out.println("");
function = userInput(sc);
}
}
}
}
The result for this code should be where the user can go through the program in order and should not be able to jump through the method and if they do, they should get an error saying, "shop has not been set up yet", "you have not bought items". The user also should be able to go back to buy items if they wished so even after items has already been listed to make changes.
Aucun commentaire:
Enregistrer un commentaire