jeudi 8 mai 2014

Codage java aide ticketmaster - Stack Overflow


How can I get the number of customers to equal the number of tickets bought?? So every ticket bought equals one customer.I can't quite figure it out give been working on it for a while but cant quite figure it out if anyone could help that would be great thanks.


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();

// check if entered integer is negative
if (desiredTicketAmount < 0) {
System.out.println("please enter a positive number.");
System.out.println();
} else if (desiredTicketAmount > 4) {
System.out.println("please enter a number less than 4 ");
System.out.println();
} else if (desiredTicketAmount <= 4) {
// check if the entered amount is available in your pool
if (balanceTicket - desiredTicketAmount < 0) {
System.out.println("sorry, we only have " + balanceTicket + " tickets left.");
System.out.println();
} else {
buyers++;
balanceTicket = balanceTicket - desiredTicketAmount;
System.out.println(" the number of tickes left are : " + balanceTicket);
System.out.println();
System.out.println(" the total number of customers: " + buyers);
System.out.println();
System.out.println();
}
}
}
}
}



Instead of this:


buyers++;

Try incrementing buyers by the amount of tickets bought. Like so.


buyers += desiredTicketAmount;



It seems to me as though you don't understand your assignment.


Why am I saying this?



  • Because a buyer could buy more than one ticket.

  • It wouldn't make sense to say a buyer equals every ticket purchased.


So... Using the int variable buyers would be bad practice for the case of buyers equaling number of tickets bought.


Instead of buyers for that case. How about substitute the variable below for buyers.


int ticketsPurchased;


How can I get the number of customers to equal the number of tickets bought?? So every ticket bought equals one customer.I can't quite figure it out give been working on it for a while but cant quite figure it out if anyone could help that would be great thanks.


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();

// check if entered integer is negative
if (desiredTicketAmount < 0) {
System.out.println("please enter a positive number.");
System.out.println();
} else if (desiredTicketAmount > 4) {
System.out.println("please enter a number less than 4 ");
System.out.println();
} else if (desiredTicketAmount <= 4) {
// check if the entered amount is available in your pool
if (balanceTicket - desiredTicketAmount < 0) {
System.out.println("sorry, we only have " + balanceTicket + " tickets left.");
System.out.println();
} else {
buyers++;
balanceTicket = balanceTicket - desiredTicketAmount;
System.out.println(" the number of tickes left are : " + balanceTicket);
System.out.println();
System.out.println(" the total number of customers: " + buyers);
System.out.println();
System.out.println();
}
}
}
}
}


Instead of this:


buyers++;

Try incrementing buyers by the amount of tickets bought. Like so.


buyers += desiredTicketAmount;


It seems to me as though you don't understand your assignment.


Why am I saying this?



  • Because a buyer could buy more than one ticket.

  • It wouldn't make sense to say a buyer equals every ticket purchased.


So... Using the int variable buyers would be bad practice for the case of buyers equaling number of tickets bought.


Instead of buyers for that case. How about substitute the variable below for buyers.


int ticketsPurchased;

0 commentaires:

Enregistrer un commentaire