its been a while since i left this program without clarification...
the code is a bit large.. so i tried to reconstruct the part where the error occurs
this is the Class
public class CoffeeBeans { private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private int numberOfOrders; private boolean orderAgain; public CoffeeBeans() { numberOfOrders = 0; } public void setOrder(int numberOfOrders) throws IOException { this.numberOfOrders = numberOfOrders; if ((this.numberOfOrders < 20) && (this.numberOfOrders >= 5)) { do { System.out.print("\n"); System.out.println("Too Small"); System.out.println(numberOfOrders); // why is the value of this PARAMETER stuck in the first value that had been passed to it? (why does it never change?) orderAgain = reOrder(); } while((orderAgain == true) && (numberOfOrders < 20)); // IM HAVING PROBLEM WITH THIS PART } } public void showOrder() { System.out.println("Number of orders: " + numberOfOrders); } private boolean reOrder() throws IOException { System.out.print("\n"); System.out.print("Do You Wish To Order Again? "); String response = br.readLine(); if ((response.equalsIgnoreCase("Y")) || (response.equalsIgnoreCase("Yes"))) { numberOfOrders = 0; System.out.print("\n"); System.out.print("Enter Your New Order "); numberOfOrders = Integer.parseInt(br.readLine()); setOrder(numberOfOrders); return true; } else if ((response.equalsIgnoreCase("N")) || (response.equalsIgnoreCase("No"))) { return false; } else { return false; } } }
this is the Main Class
public class MainClass { private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { CoffeeBeans cb = new CoffeeBeans(); System.out.print("Enter Your Order: "); int order = Integer.parseInt(br.readLine()); cb.setOrder(order); cb.showOrder(); } }
i dont know why is it happening like that....
if i enter an order that is larger than or equal to 20 the program works fine...
but i made a condition that IF the ORDER is TOO SMALL..
then the program will ask if you wish to re-order..(i defined a method for that as you can see in my class).
int this part of the method reOrder()
System.out.print("\n"); System.out.print("Do You Wish To Order Again? "); String response = br.readLine(); if ((response.equalsIgnoreCase("Y")) || (response.equalsIgnoreCase("Yes"))) { numberOfOrders = 0; System.out.print("\n"); System.out.print("Enter Your New Order "); numberOfOrders = Integer.parseInt(br.readLine()); // this part will receive a new value setOrder(numberOfOrders); // and the new value will be passed on the setOrder() method return true; }
supposedly if i re-enter a proper value (which is greater than or equal to 20) ,, the program should stop..
but why is it asking me over and over again?.... please PLEASE PLEASE HELP ME WITH THIS!!