diff --git a/.DS_Store b/.DS_Store index 348e32b..1c34ddd 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/BetterTicketMachine.java b/BetterTicketMachine.java new file mode 100644 index 0000000..06f820d --- /dev/null +++ b/BetterTicketMachine.java @@ -0,0 +1,131 @@ +/** + * TicketMachine models a ticket machine that issues + * flat-fare tickets. + * The price of a ticket is specified via the constructor. + * Instances will check to ensure that a user only enters + * sensible amounts of money, and will only print a ticket + * if enough money has been input. + * + * @author David J. Barnes and Michael Kölling + * @version 2011.07.31 + */ +public class BetterTicketMachine +{ + // The price of a ticket from this machine. + private int price; + // The amount of money entered by a customer so far. + private int balance; + // The total amount of money collected by this machine. + private int total; + private int saving; + private int discount; + private int mean; + private int count; + private int budget; + + + + /** + * Create a machine that issues tickets of the given price. + */ + public BetterTicketMachine(int ticketCost) + { + price = ticketCost; + balance = 0; + total = 0; + } + + /** + * @Return The price of a ticket. + */ + public int getPrice() + { + return price; + } + + /** + * Return The amount of money already inserted for the + * next ticket. + */ + public int getBalance() + { + return balance; + } + + /** + * Receive an amount of money from a customer. + * Check that the amount is sensible. + */ + public void insertMoney(int amount) + { + if(amount > 0) { + balance = balance + amount; + } + else { + System.out.println("Use a positive amount: " + + amount); + } + } + + /** + * 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 = price - balance; + + + if(amountLeftToPay < 0) { + // 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."); + + } + saving = price * discount; + if(count > 0){ + mean = total / count; + } + budget = 1000; + if(price > budget){ + System.out.println("Too expensive " + budget); + } + else{ + System.out.println("Just right"); + } + } + + public int emptyMachine(){ + int resetTotal = total; + total= 0; + return resetTotal; + } + + + + /** + * Return the money in the balance. + * The balance is cleared. + */ + public int refundBalance() + { + int amountToRefund; + amountToRefund = balance; + balance = 0; + return amountToRefund; + } +} \ No newline at end of file diff --git a/TicketMachine.java b/TicketMachine.java index 40d24a5..06f51c7 100644 --- a/TicketMachine.java +++ b/TicketMachine.java @@ -17,15 +17,19 @@ public class TicketMachine private int balance; // The total amount of money collected by this machine. private int total; + + private int status; + + private int score; /** * Create a machine that issues tickets of the given price. * Note that the price must be greater than zero, and there * are no checks to ensure this. */ - public TicketMachine(int ticketCost) + public TicketMachine() { - price = ticketCost; + price = 1000; balance = 0; total = 0; } @@ -75,4 +79,41 @@ public void printTicket() // Clear the balance. balance = 0; } + public int getTotal() + { + return total; + } + public void setPrice(int ticketCost) + { + this.price = ticketCost; + } + /** + * Increase score by the given number of points. + */ + public void increase(int points){ + this.score = points + score; + } + + /** + * Reduce price by the given amount. + */ + public void discount(int amount){ + this.price = price - amount; + } + + public void prompt(){ + System.out.println("Please insert the correct amount of money"); + } + public void showPrice(){ + System.out.println("The price of a ticket is " + price +" cents."); + } + public void empty(){ + total=0; + } + public TicketMachine(int price){ + + } + + + } diff --git a/bluej.pkg b/bluej.pkg index bf25784..497e3de 100644 --- a/bluej.pkg +++ b/bluej.pkg @@ -1,20 +1,20 @@ #BlueJ package file editor.fx.0.height=722 editor.fx.0.width=800 -editor.fx.0.x=709 -editor.fx.0.y=113 +editor.fx.0.x=622 +editor.fx.0.y=23 objectbench.height=101 -objectbench.width=461 +objectbench.width=776 package.divider.horizontal=0.6 package.divider.vertical=0.8007380073800738 package.editor.height=427 package.editor.width=674 -package.editor.x=1067 -package.editor.y=119 +package.editor.x=35 +package.editor.y=217 package.frame.height=600 package.frame.width=800 package.numDependencies=0 -package.numTargets=1 +package.numTargets=2 package.showExtends=true package.showUses=true project.charset=UTF-8 @@ -24,9 +24,16 @@ readme.width=47 readme.x=10 readme.y=10 target1.height=50 -target1.name=TicketMachine +target1.name=BetterTicketMachine target1.showInterface=false target1.type=ClassTarget -target1.width=120 -target1.x=80 +target1.width=150 +target1.x=240 target1.y=50 +target2.height=50 +target2.name=TicketMachine +target2.showInterface=false +target2.type=ClassTarget +target2.width=120 +target2.x=80 +target2.y=50 diff --git a/package.bluej b/package.bluej index bf25784..497e3de 100644 --- a/package.bluej +++ b/package.bluej @@ -1,20 +1,20 @@ #BlueJ package file editor.fx.0.height=722 editor.fx.0.width=800 -editor.fx.0.x=709 -editor.fx.0.y=113 +editor.fx.0.x=622 +editor.fx.0.y=23 objectbench.height=101 -objectbench.width=461 +objectbench.width=776 package.divider.horizontal=0.6 package.divider.vertical=0.8007380073800738 package.editor.height=427 package.editor.width=674 -package.editor.x=1067 -package.editor.y=119 +package.editor.x=35 +package.editor.y=217 package.frame.height=600 package.frame.width=800 package.numDependencies=0 -package.numTargets=1 +package.numTargets=2 package.showExtends=true package.showUses=true project.charset=UTF-8 @@ -24,9 +24,16 @@ readme.width=47 readme.x=10 readme.y=10 target1.height=50 -target1.name=TicketMachine +target1.name=BetterTicketMachine target1.showInterface=false target1.type=ClassTarget -target1.width=120 -target1.x=80 +target1.width=150 +target1.x=240 target1.y=50 +target2.height=50 +target2.name=TicketMachine +target2.showInterface=false +target2.type=ClassTarget +target2.width=120 +target2.x=80 +target2.y=50