Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ECE25100 Object-Oriented Programming Assignment 2 ********************************************************************************* NOTE: 1. Programs must compile without error. If your program does not compile, you will lose 50% of the

ECE25100 Object-Oriented Programming Assignment 2 ********************************************************************************* NOTE: 1. Programs must compile without error. If your program does not compile, you will lose 50% of the points. Even if your program is "essentially" correct, you will still lose 50% of the points; there is no reason to turn in a program with syntax errors. 2. To get full credit for an assignment your program must completely solve the stated problem. 3. Your program should contain a reasonable amount of comments. At the very beginning of each file, there should be a comment containing the course number, your name, the assignment number, and the date. It is good practice to insert comments into the source code, as you do when programming in any other languages. 4. You should follow the programming styles and guidelines set forth in class. In particular, use meaningful names for variables. For each coding question you should also write a test class and test your code thoroughly. 5. Compress all .java files into one zip file and name it with your full name firstname_lastname_assignment #.zip. Submit the zip file on blackboard. ********************************************************************************* In this assignment, you will create a TicketBooth object in which Person objects will purchase tickets in order to get onto Rides. You will define these classes, then do testing which simulates many people buying tickets and getting on the rides. PART A: The Ride class Define a class called Ride that defines the following private instance variables: 1. name - a string indicating the name of the ride 2. ticketsRequired - an int indicating the number of tickets that must be used to get onto this ride 3. heightRequirement - a float indicating the minimum height requirement for a person to be able to get onto this ride 4. numberOfRiders - an int indicating the number of riders on the ride so far Write: 1. get methods for each instance variable 2. a constructor that takes the name of the ride, the number of tickets required and the height requirement 3. a toString() method that returns a string in the following format "Millennium requiring 6 tickets and height restriction 4.9 feet" P a g e | 2/7 Write a test case to show that your get methods, constructor and toString() methods all work properly. PART B: The TicketBooth class Define a class called TicketBooth that defines the following private instance variables: 1. moneyMade - a float indicating the amount of money received by this booth so far 2. availablePasses - an int indicating the number of passes that are available at this booth Make the following two publically accessible class constants: 1. TICKET_PRICE (which is the price for each individual ticket...set it to be 50 cents). 2. PASS_PRICE (which is the price for a ride pass...set it to be sixteen dollars and 50 cents). Write the following (making use of the class constants whenever possible): 1. get methods for each instance variable 2. a constructor that takes an initial number of passes that the booth has available 3. a soldTickets(int num) method that records the fact that the specified number of tickets have been sold at this booth 4. a soldPass() method that records the fact that a ride pass has been sold from this booth 5. a toString() method that returns a string in the following format: "Ticket Booth with 5 passes" Write a test case to show that all your methods work properly. PART C: The Person class Define a class called Person. This class has the following private instance variables: 1. money - a float representing the amount of money the person currently has. 2. Height- a float representing the persons height (in inches). 3. ticketCount- an integer indicating the number of tickets the person currently has. 4. hasPass - a boolean indicating whether or not the person has a pass to get on rides. Write ALL the necessary methods in the Person class so that the following code works as indicated: public class PersonTester { public static void main(String args[]) { Person mary = new Person(4.9f, 20.00f); System.out.println(mary.getHeight()); System.out.println(mary.getMoney()); System.out.println(mary.getTicketCount()); System.out.println(mary.hasPass()); System.out.println(mary); mary.setTicketCount(3); System.out.println(mary); mary.useTickets(2); System.out.println(mary); mary.setPass(true); System.out.println(mary); P a g e | 3/7 } } Here is the output: 4.9 20.0 0 false 4.9 foot person with $20.00 and 0 tickets 4.9 foot person with $20.00 and 3 tickets 4.9 foot person with $20.00 and 1 tickets 4.9 foot person with $20.00 and a pass PART D: Complete the Person class Add the following instance methods to the Person class: 1. buyTickets(int number, TicketBooth booth) - This method simulates the person buying the specified number of tickets from the given booth object. It should modify the person and the booth in the appropriate way, and then return a boolean indicating whether or not the transaction was successful. The transaction is successful ONLY if the person has enough money for ALL the requested tickets. Make sure that the booth maintains a proper total of all money paid to it. 2. buyPass(TicketBooth booth) - This method simulates the person buying a ride pass from the given booth object. It should modify the person and the booth in the appropriate way, and then return a Boolean indicating whether or not the transaction was successful. The transaction is successful ONLY if the booth has a pass available and the person has enough money for the pass. 3. allowedToRide(Ride aRide) - This method determines whether or not the person is allowed to ride on the given ride. A person can get on a ride if he/she meets the ride's minimum height requirements AND the person either has a pass or the required number of tickets. The method MUST return a boolean and MUST NOT have any System.out.println code within it. Also, it MUST be written efficiently...you will lose marks for unnecessary code. 4. getOn(Ride aRide) - This method simulates the person getting on the given ride. A person can get on a ride ONLY if he/she is allowed to (i.e., make sure you use the method you just wrote). If allowed, then if the person has a pass, then he/she rides without problems, otherwise he/she needs to already have the required number of tickets. Make sure that the person AND the ride object are updated accordingly (you may not change the modifiers for the Ride instance variables, but you may write additional needed method if necessary). The method MUST NOT have any System.out.println code within it. Make sure to now test your code with the following test case in a class called FairTester: public class FairTester { public static void doTestCase1() { // Make some rides on which the people can ride, specify // name, #tickets and height req P a g e | 4/7 Ride millennium = new Ride("Millennium", 6, 4.25f); Ride mcCormick = new Ride("McCormick Place", 5, 3.1f); Ride kensington = new Ride("Kensington", 4, 2.0f); Ride homewood = new Ride("Homewood", 2, 0); Ride roosevelt = new Ride("Roosevelt Rd.", 7, 4.9f); //Make a place where tickets are sold, specifiying the //number of available passes TicketBooth booth1 = new TicketBooth(4); // Make some people by specifying their height and their //money amounts Person billy = new Person(4.9f, 10.00f); Person donna = new Person(3.0f, 5.00f); Person fredy = new Person(6.0f, 0.00f); Person harry = new Person(4.8f, 78.50f); Person jenny = new Person(2.0f, 1.00f); Person larry = new Person(4.0f, 50.00f); System.out.println("Billy is a " + billy); if (billy.buyTickets(20, booth1)) System.out.println("Billy just bought 20 tickets."); else System.out.println("Billy did not have enough money to buy 20 tickets."); System.out.println("Billy is going on the Millennium and Roosevelt Rd...."); billy.getOn(millennium); billy.getOn(roosevelt); System.out.println("Billy is now a " + billy); System.out.println(); System.out.println("Donna is a " + donna); if (donna.buyPass(booth1)) System.out.println("Donna just bought a pass."); else System.out.println("Donna did not have enough money to buy a pass."); if (donna.buyTickets(6, booth1)) System.out.println("Donna just bought 6 tickets."); else System.out.println("Donna did not have enough money to buy 6 tickets."); System.out.println("Donna is going on the McCormick Place and Merry Go Round..."); P a g e | 5/7 donna.getOn(mcCormick); donna.getOn(homewood); System.out.println("Donna is now a " + donna); System.out.println(); System.out.println("Fredy is a " + fredy); if (fredy.buyTickets(5, booth1)) System.out.println("Fredy just bought 5 tickets."); else System.out.println("Fredy did not have enough money to buy 5 tickets."); System.out.println("Fredy is going on the Merry Go Round..."); fredy.getOn(homewood); System.out.println("Fredy is now a " + fredy); System.out.println(); System.out.println("Harry is a " + harry); if (harry.buyTickets(10, booth1)) System.out.println("Harry just bought 10 tickets."); else System.out.println("Harry did not have enough money to buy 10 tickets."); if (harry.buyPass(booth1)) System.out.println("Harry just bought a pass."); else System.out.println("Harry did not have enough money to buy a pass."); System.out.println("Harry is going on the Millennium twice and the Roosevelt Rd. Once..."); harry.getOn(millennium); harry.getOn(roosevelt); harry.getOn(millennium); System.out.println("Harry is now a " + harry); System.out.println(); System.out.println("Larry is a " + larry); if (larry.buyTickets(15, booth1)) System.out.println("Larry just bought 15 tickets."); else System.out.println("Larry did not have enough money to buy 15 tickets."); System.out.println("Larry is going on the Roosevelt Rd., Millennium and Merry Go Round..."); P a g e | 6/7 larry.getOn(roosevelt); larry.getOn(millennium); larry.getOn(homewood); System.out.println("Larry is now a " + larry); System.out.println(); System.out.println("Ticket Booth 1 made $" + booth1.getMoneyMade()); System.out.println("Ticket Booth 1 has " + booth1.getAvailablePasses()+" passes left."); System.out.println(millennium + " and had " + millennium.getNumberOfRiders() + " riders."); System.out.println(mcCormick + " and had " + mcCormick.getNumberOfRiders() + " riders."); System.out.println(kensington + " and had " + kensington.getNumberOfRiders() + " riders."); System.out.println(homewood + " and had " + homewood.getNumberOfRiders() + " riders."); System.out.println(roosevelt + " and had " + roosevelt.getNumberOfRiders() + " riders."); } public static void main(String args[]) { doTestCase1(); } } Here is the output to expect: Billy is a 4.9 foot person with $10.00 and 0 tickets. Billy just bought 20 tickets. Billy is going on the Millennium and Roosevelt Rd.... Billy is now a 4.9 foot person with $0.00 and 7 tickets. Donna is a 3.0 foot person with $5.00 and 0 tickets. Donna did not have enough money to buy a pass. Donna just bought 6 tickets. Donna is going on the McCormick Place and Merry Go Round... Donna is now a 3.0 foot person with $2.00 and 4 tickets. Fredy is a 6.0 foot person with $0.00 and 0 tickets. Fredy did not have enough money to buy 5 tickets. Fredy is going on the Merry Go Round... Fredy is now a 6.0 foot person with $0.00 and 0 tickets. Harry is a 4.8 foot person with $78.50 and 0 tickets. Harry just bought 10 tickets. Harry just bought a pass. Harry is going on the Millennium twice and the Roosevelt Rd. Once... Harry is now a 4.8 foot person with $57.00 and a pass. Larry is a 4.0 foot person with $50.00 and 0 tickets. P a g e | 7/7 Larry just bought 15 tickets. Larry is going on the Roosevelt Rd., Millennium and Merry Go Round... Larry is now a 4.0 foot person with $42.50 and 13 tickets. Ticket Booth 1 made $42.0 Ticket Booth 1 has 3 passes left. Millennium requiring 6 tickets and height restriction 4.25 feet. and had 3 riders. McCormick Place requiring 5 tickets and height restriction 3.1 feet. and had 0 riders. Kensington requiring 4 tickets and height restriction 2.0 feet. and had 0 riders. Homewood requiring 2 tickets and height restriction 0.0 feet. and had 2 riders. Roosevelt Rd. requiring 7 tickets and height restriction 4.9 feet. and had 1 riders

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions