Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Phase 1: Create a separate class each in a .java file to represent vehicle accidents data occurred in a country, an accident, a vehicle and

Phase 1:

Create a separate class each in a .java file to represent vehicle accidents data occurred in a country, an accident, a vehicle and a driver.

The vehicle accidents class has attributes to store a country name and a list of published accidents data by the DfT in that country. The accident class keeps the details about collision road location (within urban area, highway), date/time, the vehicles associated and the number of casualties.

Note: Use the Date class available in java.util package to represent the accident data/time.


Each vehicle has a number and a driver. The driver class records the driver's name, age, gender and his/her license issue date. The reported vehicle accidents are of the following types:


1.     Single vehicle accident: This is a type of road traffic accident in which only one vehicle is involved. A majority of these types of crashes are collisions with fallen debris, a pole, a tree, a wall, and collisions with animals.


2.     Rear-end accident: A traffic accident where a vehicle crashes into the vehicle in front of it. Sudden deceleration (slowing down or braking) is a common cause of such accidents.


3.     Side-impact accident: These accidents, also known as broadside or T-bone collisions, are where the side of one or more vehicles is impacted. These crashes commonly occur at intersections and parking lots. The results from a side-impact collision can be severe but can vary depending on where the vehicle is struck.


4.     Head-on accident: This type of accident is when the front ends of two vehicles hit each other in opposite directions. Being aware of traffic signs, street conditions, and staying in your lane play a critical role in avoiding these types of accidents.



Create a class for each vehicle accident type and define necessary attributes and methods.

Each class must store its state in private variables. It should use a static variable to maintain a count of all instances of the class. For All required access is done through public methods. The public methods which you must implement allow the user to do the following: 

NOTE


I FINISHED THE PHASE 1 AND HERE IS THE CODE :

/*

* Class VehicleAccidents

*/

import java.util.ArrayList;

public class VehicleAccidents {

   private String country;

   private ArrayList<Accident> accidents;

   public VehicleAccidents() {

   }

   public VehicleAccidents(String country, ArrayList<Accident> accidents) {

       this.country = country;

       this.accidents = accidents;

   }

   public String getCountry() {

       return country;

   }

   public ArrayList<Accident> getAccidents() {

       return accidents;

   }

   public void setCountry(String country) {

       this.country = country;

   }

   public void setAccidents(ArrayList<Accident> accidents) {

       this.accidents = accidents;

   }

  

   public void addAccident(Accident acc){

       accidents.add(acc);

   }

}

/*

* Class Accident

*/

import java.util.Date;

public class Accident {

   private String location;

   private Date date;

   private int numOfCasualities;

   public Accident() {

   }

   public Accident(String location, Date date, int numOfCasualities) {

       this.location = location;

       this.date = date;

       this.numOfCasualities = numOfCasualities;

   }

   public String getLocation() {

       return location;

   }

   public void setLocation(String location) {

       this.location = location;

   }

   public Date getDate() {

       return date;

   }

   public void setDate(Date date) {

       this.date = date;

   }

   public int getNumOfCasualities() {

       return numOfCasualities;

   }

   public void setNumOfCasualities(int numOfCasualities) {

       this.numOfCasualities = numOfCasualities;

   }

  

}

/*

* Class Vehicle

*/

public class Vehicle {

   private String vehicleNumber;

   private Driver driver;

   public Vehicle() {

   }

   public Vehicle(String vehicleNumber, Driver driver) {

       this.vehicleNumber = vehicleNumber;

       this.driver = driver;

   }

   public String getVehicleNumber() {

       return vehicleNumber;

   }

   public void setVehicleNumber(String vehicleNumber) {

       this.vehicleNumber = vehicleNumber;

   }

   public Driver getDriver() {

       return driver;

   }

   public void setDriver(Driver driver) {

       this.driver = driver;

   }

  

}


/*

* Class Driver

*/

import java.util.Date;

public class Driver {

   private String name;

   private int age;

   private String gender;

   private Date licenseIssueDate;

   public Driver() {

   }

   public Driver(String name, int age, String gender, Date licenseIssueDate) {

       this.name = name;

       this.age = age;

       this.gender = gender;

       this.licenseIssueDate = licenseIssueDate;

   }

   public String getName() {

       return name;

   }

   public void setName(String name) {

       this.name = name;

   }

   public int getAge() {

       return age;

   }

   public void setAge(int age) {

       this.age = age;

   }

   public String getGender() {

       return gender;

   }

   public void setGender(String gender) {

       this.gender = gender;

   }

   public Date getLicenseIssueDate() {

       return licenseIssueDate;

   }

   public void setLicenseIssueDate(Date licenseIssueDate) {

       this.licenseIssueDate = licenseIssueDate;

   }

  

}


/*

* Class SingleVehicleAccident

*/

import java.util.Date;

public class SingleVehicleAccident extends Accident{

   private Vehicle vehicle;

   private String type;

   static int count;

   public SingleVehicleAccident() {

   }

   public SingleVehicleAccident(Vehicle vehicle, String type, String location, Date date, int numOfCasualities) {

       super(location, date, numOfCasualities);

       this.vehicle = vehicle;

       this.type = type;

   }

   public Vehicle getVehicle() {

       return vehicle;

   }

   public void setVehicle(Vehicle vehicle) {

       this.vehicle = vehicle;

   }

   public String getType() {

       return type;

   }

   public void setType(String type) {

       this.type = type;

   }

  

}


/*

* Class RearendAccident

*/

import java.util.Date;

public class RearendAccident extends Accident{

   private Vehicle frontVehicle;

   private Vehicle rearVehicle;

   private String cause;

   static int count;

   public RearendAccident() {

   }

   public RearendAccident(Vehicle frontVehicle, Vehicle rearVehicle, String cause, String location, Date date, int numOfCasualities) {

       super(location, date, numOfCasualities);

       this.frontVehicle = frontVehicle;

       this.rearVehicle = rearVehicle;

       this.cause = cause;

   }

   public Vehicle getFrontVehicle() {

       return frontVehicle;

   }

   public void setFrontVehicle(Vehicle frontVehicle) {

       this.frontVehicle = frontVehicle;

   }

   public Vehicle getRearVehicle() {

       return rearVehicle;

   }

   public void setRearVehicle(Vehicle rearVehicle) {

       this.rearVehicle = rearVehicle;

   }

   public String getCause() {

       return cause;

   }

   public void setCause(String cause) {

       this.cause = cause;

   }

  

}


/*

* Class SideImpactAccodent

*/

import java.util.ArrayList;

import java.util.Date;

public class SideImpactAccodent extends Accident{

   private String cause;

   private ArrayList<Vehicle> vehicles;

   static int count;

   public SideImpactAccodent() {

   }

   public SideImpactAccodent(String cause, ArrayList<Vehicle> vehicles, String location, Date date, int numOfCasualities) {

       super(location, date, numOfCasualities);

       this.cause = cause;

       this.vehicles = vehicles;

   }

   public String getCause() {

       return cause;

   }

   public void setCause(String cause) {

       this.cause = cause;

   }

   public ArrayList<Vehicle> getVehicles() {

       return vehicles;

   }

   public void setVehicles(ArrayList<Vehicle> vehicles) {

       this.vehicles = vehicles;

   }

  

}


/*

* Class HeadOnAccident

*/

import java.util.Date;

public class HeadOnAccident extends Accident{

   private Vehicle vehicle1;

   private Vehicle vehicle2;

   static int count;

   public HeadOnAccident() {

   }

   public HeadOnAccident(Vehicle vehicle1, Vehicle vehicle2, String location, Date date, int numOfCasualities) {

       super(location, date, numOfCasualities);

       this.vehicle1 = vehicle1;

       this.vehicle2 = vehicle2;

   }

   public Vehicle getVehicle1() {

       return vehicle1;

   }

   public void setVehicle1(Vehicle vehicle1) {

       this.vehicle1 = vehicle1;

   }

   public Vehicle getVehicle2() {

       return vehicle2;

   }

   public void setVehicle2(Vehicle vehicle2) {

       this.vehicle2 = vehicle2;

   }

  

}

I NEED HELP WITH PHASE 2 (I NEED SOMEONE TOADD ON MY CODE FOR PHASE 2)

THIS IS PHASE 2 IVE DONE SOME IN MY CODE BUT I NEED HELP TO CONTINUE

-         Initiate, get, and set the state of any created object.

-         Create a new vehicle accident data object for a given country.

-         Add a reported accident type to the list of accidents if is not already in the list of the accident.

-         Find and display the most frequent accident type from the collected data.

-         Display percentage of causalities in accidents involving drivers over age 65.

-         Compare the number of accidents that occur within built-up areas to those accidents that occur on highways.

-         Display the country name and accidents list which shows the accident details for the drivers involved in accidents having a driver's license issued after 2015.

-         Dump the vehicle accident data structure into text.

-         Save the information of the vehicle accident data structure into a file.


If the user attempts do an operation that will violate the state of objects, you must check for it. In that case, the operation should be ignored and the application should give back an error message.

Step by Step Solution

3.44 Rating (144 Votes )

There are 3 Steps involved in it

Step: 1

Class VehicleAccidents import javautilArrayList publi... 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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

133544613, 978-0133544619

More Books

Students also viewed these Programming questions

Question

What is supply chain management (SCM) and why is it important?

Answered: 1 week ago

Question

When would a packaged data model be useful?

Answered: 1 week ago