lab2 - CS116 LAB2 .(upload...

Info icon This preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS116 LAB 2 This lab is using mostly material covered in CS115 and it is intended as a review. This Lab is to be started in the lab. It is due on Wednesday June 9 on Blackboard (upload  to Folder Lab 2) , time stamped by 10:00 p.m.   Use EditPlus or equivalent editor to create source code. Objectives:  1. Usage of enum class. 2. Equality of objects. 3. Vectors. 4. Arrays of objects. 5. Sequential search of arrays. Task 1 (1.5 points)   Use your solution to Lab 1 Task 1. Do not modify the package! You will need the   Vehicle class from lab 1. Vehicle.class should be in path folder1.folder2 with   respect to the directory where your source code is located. 1. A car manufacturer  makes available the following Vehicle types: 1
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
FOUR_DOOR_SEDAN,  TWO-DOOR-SEDAN, TRUCK, SUV, SPORT,  VAN,  MINI_VAN This time we are going to create a class by itself for the enumeration (in its  own file, separate than the Vehicle class file). Create a class named  VehicleType.  The class should be in the same package  as the Vehicle  class (folder1.folder2), therefore first you type the package line of code  and then the code: public  enum  VehicleType { list the types in here}; Save the file with the enumeration class name as the name of the file and  compile it using the proper javac command to create the package. Check  to make sure that the compiled file is in the right folder (folder1.folder2).   2. MODIFICATIONS TO VEHICLE CLASS     Modify the class Vehicle  to provide the proper additional instance variable  needed for the VehicleType. Provide the proper accessor and mutator  methods for the enumeration type. Notice that the constructors are not  modified. Therefore one needs to call the mutator method for VehicleType  instance variable to set its value. Question 1 : What is the value of the instance variable for VehicleType  after declaration but before its value is set to a specific type? Answer : 2
Image of page 2
Add an equals method in Vehicle class that will allow two Vehicle objects  to be compared for equality. In the equals method decide that two objects  are equal if and only if their instance variables: init_v, init_d, VehicleType,  and acceleration are equal (the rest of the instance variables don’t matter  for the equality decision). o The comparison of the VehicleType instance variable, will have to  be done using a call to the Object ‘s class equal method i.e if vt I  steh identifier for the VehicleType then: this.vt.equals(objVeh.vt);   compares this object’s vt to object objVeh’ s vt value.
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern