Question: Please program this question in java. The code is on the bottom please do it in java thanks Please program in java For this assignment

Please program this question in java.

The code is on the bottom please do it in java thanks

Please program this question in java. The code is on the bottom

please do it in java thanks Please program in java For this

Please program in java

assignment you will add exception handling to a solution for Assignment #1that is provided to you in D2L, consisting of the files Vehicle.java,Ferry.java, and Ferry Driver.java. (Aside: Our original solution for Assignment #1 wasmodified a bit to make it work easier with a menu-based driver

program for this assignment. Specifically, the removeVehicle, updatePassengers, and findVehicle methods inthe Ferry class now accept a vehicle ID as a parameter rather

For this assignment you will add exception handling to a solution for Assignment #1 that is provided to you in D2L, consisting of the files Vehicle.java, Ferry.java, and Ferry Driver.java. (Aside: Our original solution for Assignment #1 was modified a bit to make it work easier with a menu-based driver program for this assignment. Specifically, the removeVehicle, updatePassengers, and findVehicle methods in the Ferry class now accept a vehicle ID as a parameter rather than a reference to a Vehicle object.) Read, compile and run the program that we have provided. Notice that if you try to add a vehicle to a ferry and it fails, the message given is "==> vehicle not added"; the reason isn't given. Also see what happens if you provide invalid input to a call to the Scanner's nextInt() or nextDouble() methods; e.g. entering "Bob" after the prompt "Enter weight:". new Your tasks are: (a) Create three exceptions, called LimitExceededException, Duplicate VehicleException, and VehicleNotFoundException. Each of these classes should have two (overloaded) constructors: a default constructor and one that accepts a message describing the exception. (b) Modify Ferry.java so that certain methods throw exceptions. Specifically: i. addVehicle - Modify the method signature so that it has a void return type, and indicate that this method may throw a LimitExceededException or a DuplicateVehicleException. In the body of the method, you should throw LimitExceededException if adding the vehicle would exceed any of the three specified limits for this ferry, or throw DuplicateVehicleException if the specified vehicle is already on this ferry. When throwing an exception, be sure to include a message that further explains the problem; in the case of LimitExceededException, for example, the message should indicate which limit check failed. (If adding this vehicle would exceed multiple different limits, your exception message should simply describe the first limit test that failed.) ii. removeVehicle - Modify the method signature so that it has a void return type, and indicate that this method may throw VehicleNotFoundException. In the body of the method, you should throw VehicleNotFoundException if the specified vehicle isn't found on this ferry. iii. updatePass - Modify the method signature so that it has a void return type, and indicate that this method may throw a LimitExceededException or VehicleNotFoundException. In the body of the method, you should throw LimitExceededException if changing the number of passengers in the specified vehicle would exceed the specified passenger limit for this ferry, or throw VehicleNotFoundException if vehicle isn't found. a (c) Modify Ferry Driver.java to handle all exceptions thrown by methods in Ferry.java. In addition, add exception-handling code to the driver to cover any places where InputmismatchException could be thrown by a Scanner method. The completed program should handle any exceptions, no matter the input. Exceptions that occur inside the while (!done) loop should be handled by printing a message and allowing execution to proceed to the next iteration (presenting the user with the menu options once again). Exceptions that occur before the while loop should be handled by printing a message and terminating the program. Helpful hint: try-catch blocks can be nested. import java.text. NumberFormat: ** Class representing a ferry containing vehicles. */ public class Ferry { private int maxPass: private int maxAxels: private double maxWeight; private int totalPass private int totalAxels: private double total Weight: private Vehicle[] list; private int comp: public Ferry (int maxPass, int maxAxels, double maxWeight, int maxVehicles) { this maxPass = maxPass: this maxAxels = maxAxels: this.maxWeight=maxWeight; list = new Vehicle[maxVehicles); totalPass = 0; totalAxels = 0; totalWeight = 0; comp = 0; } public boolean addVehicle (Vehicle input) { boolean success = false; if (comp vehicle added"); } else { System.out.println("==> vehicle not added"); } break; case (2): System.out.println("Enter vehicle ID: "); id=sc nextInto; if (ferry remove Vehicle(id)) { System.out.println("=> vehicle removed"); } else { System.out.println("=> no such vehicle"); } break; case (3): System.out.print("Enter vehicle ID: "); id=sc nextInto; System.out.print("Enter new number of passengers: "); passengers = sc.nextInt(); if (ferry updatePassengers(id, passengers)) { System out.println("=> vehicle "+id + "'s passenger number changed"); } else { System.out.println("= vehicle" + id + "'s passenger number NOT changed"); } break; case(4): System.out.println(ferry.toString(); break; case(5): System.out.println(ferry.getAvailableWeight(); break; case(6): done = true; default: } } /** Represents a vehicle. */ public class Vehicle { /** The a unique id to be assigned to the next vehicle. */ private static int currentld = 100; The a unique id of the vehicle. */ private int id; The number of passengers in the vehicle. */ private int pass; The number of axels on the vehicle. */ private int axels; The weight of the vehicle in kg. *1 private double weight; /** Constructs a vehicle with a specific number of passengers, axels, and weight. The id is assigned a unique value. @param pass The number of passengers in the vehicle. @param axels The number of axels the vehicle has. @param weight The weight of the vehicle. */ public Vehicle (int pass, int axels, double weight) { this.pass = pass; this.axels = axels; this.weight = weight; id = currentld; currentld++; Accesses the number of passengers in the vehicle. @return The number of passengers. */ public int getPass() { return pass; } /** Accesses the number of axels the vehicle has. @return The number of axels. */ public int getAxels() { return axels; } Accesses the number weight of the vehicle. @return The weight of the vehicle. */ public double getWeight() { return weight; } Accesses the id of the vehicle. @return The id of the vehicle. */ public int getid () { return id; } /** Sets the number of passengers in the vehicle. @param num Pass The new number of passengers. */ public void setPass (int numpass) { pass = nympass: }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!