i am writing a program that would be used for ticket sales and their are 100 tickets and a person can only buy 4 at a time. i need my program to not go negative at the end and also i need to stop the user from entering a negative number here is the code please help!
import java.util.Scanner;
public class ticketmaster {
public static void main(String[] args) {
// Variable decoration uses strings , doubles and final doubles.
Scanner in = new Scanner(System.in);
int balanceTicket = 100;
int desiredTicketAmount = 0;
int buyers = 0;
while (balanceTicket > 0)
{
System.out.println("please enter the number of tickets wanted");
desiredTicketAmount = in.nextInt();
if ( desiredTicketAmount > 4 )
{
System.out.println( "please enter a number less than 4 ");
System.out.println();
}
else if ( desiredTicketAmount <= 4 )
{
buyers++;
balanceTicket = balanceTicket - desiredTicketAmount;
System.out.println (" the number of tickes left are : " + balanceTicket);
System.out.println();
}
}
System.out.println (" the number of customers: " + buyers );
System.out.println();
}
}