Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE JAVA !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Winter 2021 Lab7 COMP 249 Due date: Today, at the end of the lab period. In this exercise, we will implement a

image text in transcribed

USE JAVA !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Winter 2021 Lab7 COMP 249 Due date: Today, at the end of the lab period. In this exercise, we will implement a Garage. A. Create a Car class a. Define the following attributes: String make, String model, double price b. Implement the constructor that takes all the attributes as parameter. c. Implement the mutators and toString() method B. Create a Parking class: a. Define the following attributes: - an array of Car cars - an int constant: MAXNBOFCARS-3 - an int number of cars nbCars b. Implement the constructor that does not take any parameters and initialize the array and the number of cars. c. Implement the getters: getNbCars().getNbCars Maxi d. Implement void addCar(Car c) method. This method checks if there is still available place in the parking. If yes, it adds the car (c) at the current position and updates the number of cars in the parking. If there is no available parking, the method throws an exception FullParkingException with a meaningful message. e. Implement Car removeCar (int position) method, that checks if the car at the given position can be removed. The method throws the exceptions EmptyParkingException and BadPositionException. When a car is removed from the parking, the next cars are shifted so as to fill the empty space. C. Create the classes EmptyParkingException, BadPositionException and FullParkingeException that extend the java Exception class. The classes have a constructor that takes as parameter a String message. This message is the one that will be printed when the exception will be thrown. D. Create a Driver class Garage to test your program. a. Create 4 Cars and a Parking. In a try/catch block add those cars to the parking. Remove a car by giving a bad position. c. Remove all the cars and once the parking is empty try to remove again a car. You should put every test in one try/cateh block and catch all the possible exception that may occur. Submission: Once you are done, upload your program to the Moodle. Please name your file following this convention: lab7_studentID, where studentID is your Student ID number

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

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

(1 point) Calculate 3 sin x cos x dx.

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago