Question: java program Lab Exercise 1: Understanding problem from real world translating into object-oriented a) Define a class TicketMachine that contains two attributes price and balance




Lab Exercise 1: Understanding problem from real world translating into object-oriented a) Define a class TicketMachine that contains two attributes price and balance plus three methods as specified in Table 3. Refer details specification as in Figure 3 and Figure 4. Table 3: Ticket Machine.java detail specification Method Type Action setBalance (double b) void balance-b getBalance(void) double return balance payTicket(Double) void if (balance >- tprice) setBalance (getBalance() - tprice) Check balance if icket Yo No TicketMachine -balance double sotBalance double vold getBalance vold) double pay Ticket double vold Figure 30 - A simple TicketNachine UML class diagram Figure 40. Activity diagram for TicketApp java Project Ed Took View Help New Chess Cc ca Del Do om od double et validatie Execute setBalance(), enter 600. Check getBalance. Then perform pay Ticket(). Enter 120 for ticket price. Show what is the output. Solution: import java.util.Scanner; public class TicketMachine public double balance; public TicketMachine public void setBalance (double b) balance b;} public double getBalance() { return balances) vo public void setBalance( double b) { balance = b;} public double getBalance() { return balance; } Practical SH. Haris, Sem 181 Page 19 of 21 public void payTicket(double p) if (p = ticket Yes No Check ifuser ends the program No Yes Figure 5.0- Activity diagram for TicketAppExt.java Solution
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
