Could anybody help me with this university portfolio question please?
6.3 project better-ticket-machine:
Rewrite the printTicket method so that it declares a local variable, amountLeftToPay. This should then be initialized to contain the difference between price and balance.
Rewrite the test in the conditional statement to check the value of amountLeftToPay. If its value is less than or equal to zero, a ticket should be printed, otherwise an error message should be printed stating the amount still required. Test your version to ensure that it behaves correctly. (exercise 2.57 from Barnes and Kolling 4th edition)
Ive added the bit in bold already...... but dont know how to do the rest of the question..... im not looking for the answer to be posted but any help you could give me to help guide me there would be very gratefully recieved.....
/**
* Print a ticket if enough money has been inserted, and
* reduce the current balance by the ticket price. Print
Question
Joffy14
Hello,
Could anybody help me with this university portfolio question please?
6.3 project better-ticket-machine:
Rewrite the printTicket method so that it declares a local variable, amountLeftToPay. This should then be initialized to contain the difference between price and balance.
Rewrite the test in the conditional statement to check the value of amountLeftToPay. If its value is less than or equal to zero, a ticket should be printed, otherwise an error message should be printed stating the amount still required. Test your version to ensure that it behaves correctly. (exercise 2.57 from Barnes and Kolling 4th edition)
Ive added the bit in bold already...... but dont know how to do the rest of the question..... im not looking for the answer to be posted but any help you could give me to help guide me there would be very gratefully recieved.....
/**
* Print a ticket if enough money has been inserted, and
* reduce the current balance by the ticket price. Print
* an error message if more money is required.
*/
public void printTicket()
{
int amountLeftToPay;
if(balance >= price) {
// Simulate the printing of a ticket.
System.out.println("##################");
System.out.println("# The BlueJ Line");
System.out.println("# Ticket");
System.out.println("# " + price + " cents.");
System.out.println("##################");
System.out.println();
// Update the total collected with the price.
total = total + price;
// Reduce the balance by the prince.
balance = balance - price;
}
else {
System.out.println("You must insert at least: " +
(price - balance) + " more cents.");
}
}
Link to comment
Share on other sites
2 answers to this question
Recommended Posts