From 86bce244242d75afde5b20e5400cb14e3f83033f Mon Sep 17 00:00:00 2001 From: Thao Nguyen Date: Wed, 6 Feb 2019 23:13:57 -0500 Subject: [PATCH] Finished --- .DS_Store | Bin 6148 -> 6148 bytes BetterTicketMachine.java | 131 +++++++++++++++++++++++++++++++++++++++ TicketMachine.java | 45 +++++++++++++- bluej.pkg | 25 +++++--- package.bluej | 25 +++++--- 5 files changed, 206 insertions(+), 20 deletions(-) create mode 100644 BetterTicketMachine.java diff --git a/.DS_Store b/.DS_Store index 348e32b8c8110eb26612743aef48b3926c52344f..1c34ddd9962d0c1d5e25c3427bee29c16f0d2cd0 100644 GIT binary patch literal 6148 zcmeHK%Z}496uq7nNP`9{gfz1w8zdH^su5@g2_cn|S#*JfNX0{dX7W;#A&sjxnF>l# zH*9Ci;}7^0zF7O01PaIRTHZfLVhYs zvY{+j5Si%X2pTYeH_+>(OVQe(8PE*;Z4A)2TLT|bC?JBl@0SOD%6;_G)^HEYt)D_r zTa^)a(o)8^g^UV>z#%9{v8~ln{&+M{qks1YX)?;2%~Q5fsb08v$uLaA+%#XiF(13R zmlvb9H+)I0$6g-$O7C)>{?enCgEccQu8j9p3j4TX!K3otvv{E$M&Fy@4s=r5*FUnM~p77fG4mI55R#(hz;mNxRCKk+n(!CUBqR^EIc*wnI;0ku?(%PYOws2R`< z{Lc)~{$ODtY$=>c6k7*Y;tGIRMY9mp>4$-GEQKwFGl}RyVKNm_rZRQKU@{%;mWpdB zoJo}Fz|`e~sgaqwp)fHz_HT)BU@eKd)(mI{$_!Lwvrgy#{`&iWIZ3xP1Db(B`mu~2NHo}vgV0|Nsi1A_oVa!yiyeh!eyz&x>V1taU^Qr5c7G9272 n8ykw4HnVf^a{x7M7UcNOJegm_QUIt9q>l+ovuutKS;GtfqB#-( 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