联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp2

您当前位置:首页 >> Java编程Java编程

日期:2020-07-20 10:11

Coding Assignment 2 - CISC 124 - Introduction to Computing Science II (ASO) S20

DESCRIPTION

Overview - Order of Submission

The following assignment has a peer review component. Here is the order of submission:

1. Read the activity description and prepare the relevant le.

2. Submit your le

in Aropa and start the peer review process (instructions to follow).

3. Review and revise your work (optional).

4. Submit your nal

work in OnQ.

Description

Department of Transportation Registry

In this assignment, you will have the opportunity to practice writing several Java classes involving

inheritance. You have been hired by the Department of Transportation to create a program that they

can use to keep track of vehicle registrations. Your program will maintain registration details for cars,

trucks and motorcycles. The hierarchy of the program will be structured as follows:

You will write a Vehicle class that will be used to represent all types of vehicles. You will then write

three sub-classes: Car, Truck, and Motorcycle. These sub-classes will contain the variables and

methods that are specic

to particular types of Vehicles.

You will write a CarOwner class which will represent the owner of a vehicle.

You will write a Registry class. This class is a simple collection class that represents a collection of

vehicle objects.

The Vehicle class will have the following instance variables:

- registrationNumber (vehicle's registration number)

2020/7/18 Coding Assignment 2 - CISC 124 - Introduction to Computing Science II (ASO) S20

https://onq.queensu.ca/d2l/le/content/388353/viewContent/2198457/View 2/5

- owner (a CarOwner object representing the owner of the vehicle)

- odometerReading (representing the odometer reading of the vehicle)

- make (make of the vehicle -- i.e. Chevrolet)

- model (model of the vehicle -- i.e. Silverado)

- year (model year of the vehicle. The model year of the vehicle must be 1980 or later)

- numWheels (number of wheels on the vehicle. Every vehicle has a minimum of 2 wheels)

- plateNumber (the license plate number. This will be a combination of letters (L) and numbers (#). In

Ontario, a license plate is of the form 4L's and 3#'s. As an example, a license plate may be: HGKW

815. Every vehicle's plate number must be of the correct letter-number combination).

In addition to the instance variables inherited from the Vehicle parent class,the Car class will have

the following instance variables:

- numSeats (number of seats in the Car)

- isSUV (indicating whether the Car is a sport utility vehicle -- SUV).

In addition to the instance variables inherited from the Vehicle class,the Truck class will have the

following instance variables:

- isSemi (True if the truck is a transport truck, False if the truck is another type -- i.e. cube

truck/pickup).

- loadCapacity (the weight that the truck can hold, measured in pounds).

The Motorcycle class will inherit all of its instance variables from the Vehicle class. Think about:

why might we choose to create a Motorcycle class if it inherits all of the instance variables and

methods from the vehicle class but doesn't specify any of its own instance variables or override any

of the methods from the Vehicle class?

The CarOwner class will include the following instance variables:

- name (the name of a driver)

- age (the age of a driver)

- gender (the gender of a driver)

- licenseNumber (the license number of a driver)

- yearsDriving (the number of years that a driver has been driving).

The Registry class will include two elds:

- vehicleCollection (an arraylist to hold a collection of vehicle objects currently registered in the

province.)

- numVehicles (the number of vehicles currently registered in the province).

REQUIRED METHODS

2020/7/18 Coding Assignment 2 - CISC 124 - Introduction to Computing Science II (ASO) S20

https://onq.queensu.ca/d2l/le/content/388353/viewContent/2198457/View 3/5

Each of your classes should provide accessor (“getter”) and mutator (“setter”) methods for each of

the instance variables of the class. For example, your Vehicle class should include a mutator

method for setting the mileage and setting the plate number for an instance of a Vehicle object.

Each of your classes should also include a toString method that prints out a string representation

of an instance of the object. Your Vehicle parent class should have its own toString method which

the children classes will"override"to print out information specic

to the child class. For example,

the toString method for a Truck will print out information about the number of axles...this would

not apply when printing the string representation of a Motorcycle object.

In your Truck class, include a function called getNumberAxles(). The number of axles returns how

many axles the truck has - we assume that the number of axles is the number of wheels divided by

2.

The Registry class should include the following functions:

addVehicle - adds a vehicle object to the registry.

printRegistry - print the vehicles that are currently inventoried in the registry.

averageMileage - calculates the average mileage of all vehicles in the registry (using the

odometerReading attribute of the vehicles).

ERROR CHECKING & INFORMATION HIDING

Error Checking

You are required to check for the following errors in user input.

If there is an attempt made to create an instance of a Vehicle for which the vehicle's year is earlier

than 1980, throw an exception and print out the message (“Illegal year - you need to buy a newer

vehicle!”).

If the "setMileage" method in the Vehicle class is called, your program should verify that

the new value for the mileage is not less than the old value for the mileage. If it is, throw an

exception and print out the message ("Illegal mileage - nice try!").

If there is an attempt to set the number of wheels of any vehicle to less than two, throw an

exception and print out the message ("Illegal number of wheels - buy a unicycle!").

If there is an attempt to set the vehicle's plate number to an illegal value (i.e. doesn't satisfy the

letter-number combination of 4 letters and 3 numbers), throw an exception and print out the

message ("Illegal license plate!").

If there is an attempt to set the age or yearsDriving instance variable of a Person object to a value

less than 0, throw an exception and print out the message ("Illegal value!").

Information Hiding

Marks will be allocated according to how well you have implemented the principles of information

hiding in the development of your class. Reminders:

All instance and class variables should be private. This ensures that other classes are not able to

modify the values of these attributes. Any changes to the values of the attributes should be made

by invoking the "getter" and "setter" methods of the class.

2020/7/18 Coding Assignment 2 - CISC 124 - Introduction to Computing Science II (ASO) S20

https://onq.queensu.ca/d2l/le/content/388353/viewContent/2198457/View 4/5

Any instance variables that are included in a parent class must NOT be redened

in a child class.

For example, since the instance variable "make"is included in the Vehicle class, it should not be

redened

in the Car, Motorcycle or Truck classes. Instead, use the super keyword to access the

constructor of the parent class.

Please ensure that your class includes accessor ("getter") and mutator ("setter") methods for each

of the instance variables.

Constants should be private unless they need to be used by other classes.

Any “helper methods” should be private. A “helper method” is a method that you write to help

implement the required methods.

You will need to write an exception class called "IllegalVehicle". This exception class only needs

the one constructor that accepts a String type message.

Throw an "IllegalVehicle" exception objectif an attemptis made to set or alter any ofthe

attributes to illegal values.

Please ensure that your classes include accessor (“getter”) and mutator (“setter”) methods for

each ofthe instance variables.

PEER REVIEW

This assignment includes a peer review feature. Before you submit this assignment to the teaching

team we would like you to submit it to be reviewed by your peers. The purpose of the peer review

activity is to provide you with the opportunity to collaborate and learn from your peers and for your

peers to learn from you. Once you receive feedback from your peer, you have the option to correct

your work before submitting it for grade.

Instructions

You will submit your work through a web-based application called Aropa

Each student will review (anonymously) another student’s work according to the rubric below.

When reviewing your peer’s work, keep a positive mindset and positive intentions, you are helping

you peer improve.

This review is worth 2% of your overall grade in the course.

Read the following instructions on how to write your review in Aropa

Evaluating Rubric

On a scale of 3-0, please rate your peer’s code.

3- Very good, 2 - some improvements are required, 1 - signicantimprovements

required, 0- No

submission

3 2 1 0 Comments

2020/7/18 Coding Assignment 2 - CISC 124 - Introduction to Computing Science II (ASO) S20

https://onq.queensu.ca/d2l/le/content/388353/viewContent/2198457/View 5/5

Efciency

Clean code,

indicates that the

code was

adequately

developed

No

submission

Maintainability

Readable other

people, a

combination of

short, simple,

consistent and

useful naming with

clear logic.

Well structured

The various objects

in the code working

optimally together.

Follows standards

The code follows a

set of guidelines,

rules, and

regulations.

FINAL SUBMISSION

Submit your nal

work in OnQ to the following assignment submission folder


相关文章

【上一篇】:到头了
【下一篇】:没有了

版权所有:编程辅导网 2018 All Rights Reserved 联系方式:QQ:99515681 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。