For a cleaner and more readable code, prefer in this case do..while
block since now no need for more
variable:
public static void main(String[] args) {
double purchase = 0.0;
Scanner scan = new Scanner(System.in);
System.out.print("Do you have any more purchases Y/N?: ");
if (!scan.nextLine().equalsIgnoreCase("y")) {
return;
}
do {
System.out.print("Please input purchase amount: ");
purchase += Double.parseDouble(scan.nextLine());
System.out.print("Do you have any more purchases Y/N?: ");
}
while (scan.nextLine().equalsIgnoreCase("y"));
System.out.println("Your purchase amount is: " + purchase + " and so is " + (purchase >= 2500 ? ">= 2500" : "< 2500"));
}
For a homework, that's pretty good I think. For a real work in a project, you should refactor in many small methods that make sense and avoid most of redundancy. That could be your secondary homework: optimize it :)