SlideShare a Scribd company logo
This is the assignment:
OBJECTIVES
After finishing this lab, students can have the following:
Understand how to declare an unsorted-optimized array data structure
Know how to insert nodes to the structure, fetch a node with a key field of node, update the
information of a node and delete a node from the structure
Verify that the nodes in the unsorted-optimized array data structure are fully encapsulated.
Students will be familiar with the ArrayList and apply all the basic operation to access nodes
Also, students recognize that ArrayList is a heterogeneous data structure that can store nodes of
any type of objects.
REQUIREMENT STATEMENT
A car dealer needs an application that can help the shop to do the following tasks:
1.Insert a car or a motocycle
2.Test for the encapsulation of the data structure
3.Remove a car or a motocycle
4.Update information of a car or a motocycle
5.Show All vehicles
6.Exit
Also, the owner of the shop asks for:
-Using the Unsorted Optimized Array data structure for the application and apply Inheritance
and polymorphism of Object Oriented Programming
-Requiement for output:
The car’s information is displayed as below (for example)
VIN: 123A456B Color: White Year: 2014
Car make: Toyota Model: Sienna Number of passengers: 8 Number of doors: 4
The motocycle’s information is displayed as below (for example
VIN: 321BC654
Color: Grey
Year: 2015
Motocycle make: Honda
Model: PCX150
Has side car: no
-After a task from the menu, the application should allow users to continue using the application
and only terminate when users select Exit
COSC2436 – Lab3
1
TASK INSERT
-Display the message: “*** TASK: INSERT and FETCH A CAR OR A MOTOCYCLE ***”
-Allow users to enter the information of a car or a motocyle from the keyboard -Insert the
car/motocycle to the data structure
-Fetch the information of car/motocycle by its VIN from the data structure that have entered to
the structure to ensure that the car/motocycle is in the structure
TEST FOR ENCAPSULATION
-Display the message: “*** TASK: TEST FOR DATA ENCAPSULATION ***”
-Create a test car with the following information typed from the keyboard: -Insert this test car to
the data structure
-Modify the the color of the test car with different color
-Declare an object of car named “copy” and assign the node that is fetched from the data
structure with the target key as VIN of test car
-Display information of the object named copy
-Compare the color of test car with the color of object copy. If they are different then display the
message: “The Unsorted Optimized Array structure has the encapsulation”; otherwise display
“The Unsorted Optimized Array structure does not have the encapsulation”
TASK UPDATE
-Display: “***TASK: UPDATE INFORMATION OF A CAR OR A MOTOCYCLE *** “ -
Create an object of class Car named newNode
-Fetch a node with the VIN is the same VIN of test car then assign to newNode, therefore, the
newNode has the same VIN with the test car
-Change the color of the newNode to different color -Update the data structure with with the
newNode
-Fetch with the key as the key of test car. If the node resulted from fetch has different color from
the test car the display the message “Update test car successfully”; otherwise display “Update
test car failed”
TASK DELETE
-Display: “ *** TASK: DELETE A CAR OR A MOTOCYCLE ***”
-Delete the node with the VIN as SP2017 that was not inserted to the data structure, print out the
result of task delete (output: false)
-Delete the node with the VIN of the above test car, print the result (output: true) -Fetch with the
key as the VIN of the test car, print out the result (output: null)
TASK SHOW ALL
-Call showAll to display all nodes on the data structure
WHAT WE NEED TO KNOW TO DO THE PROGRAM
-Review how to declare the Inheritance relationship between 2 classes
-How to write the constructor, toString or other methods of child classes to inherit from the super
class -How to apply polymorphism to the main
-Understand what is Unsorted Optimized Array structure, how initialize the Unsorted Optimized
Array data structure
-How 4 operations of Unsorted Optimized Array structure work
UML and PSUEDO-CODE
You should provide the UML of super class, and 2 child classes
The pseudo-code is provided in the requirement, you do not need to rewrite; just follow step by
step to write the code
COSC2436 – Lab3
2
HOW TO DO THE LAB part1
-After provide UML and read the pseudo-code, start the Java editor -Create the project name
SP2017LAB3_PART1_yourLastname
-Add super class named SP2017LAB3_Vehicle_yourLastname that maintain Vin number, color,
make, model, year. It also has some methods, such as, mutator, accessor, and toString, method
forward (accept the amount of distance in miles, for example, 25, then display “move forward 25
miles”), method backward (accept the amount of distance in miles, for example 3 then display
the message “move backward 3 miles”), turn left (display word “Turn left”) and turn right
(display word “Turn Rright”)
-Add child class named SP2017LAB3_Car_yourLastName inherits from above class Vehicle. It
has more data members, such as, number of passengers, number of doors
-Add child class named SP2017LAB3_Motocycle_yourLastName inherits from above class
Vehicle. It has more data members, such as, has side car (boolean)
-Add a data structure class named
SP2017LAB3_VehicleUnsortedOptimizedArray_yourLastName that maintain size(int), a vehicle
array and next (int) to hold the location where the new node is inserted to the structure. Also, the
class has the methods for 4 operations: insert, fetch, delete, update and showAll that display all
the nodes in the structure. ( see the code on page 103 for your reference)
-Add a driver class name SP2017LAB3_VehicleDealerShop_yourLastname that do the
requirement asking for
PART2:
OBJECTIVES: Practice using Java ArrayList class.
REQUIREMENT and HOW TO DO THE LAB PART2
Add the following part to the previous project with the following step by strep (pseudo-code)
-Declare a data structure of ArrayList with the size 25
-Insert 3 cars/motocycles with information that are entered from the keyboard -Show all 3 nodes
that have inserted to the ArrayList data structure
-Use a for loop to insert number 1 to 100 to the above data structure of ArrayList
-Display the size of the above ArrayList.
-Remove the one above car/motocycle from the ArrayList data structure with one of the VIN
displyed at above showAll(). Then display the size of the ArrayList structure
-Get and display the information of nodes at the location 45. Change the value at location 45 to
2016. Display the information at location 45 again
-Use JOptionPane to display the message: “Congratulation! You are successful on ArrayList
with four operations: add, get, remove and set”
This is the code I have so far:
***Vehicle Class***
import java.util.Scanner;
public class SP2017LAB3_Vehicle{
//
private static Scanner keyboard = new Scanner(System.in);
protected String vin, model, sideCar;
protected String color;
protected String make;
protected int year, miles, passengers, doors;
// default constructor
public SP2017LAB3_Vehicle() {
vin = null;
model = null;
color = null;
make = null;
year = 0;
miles = 0;
}
//parameter constructor
public SP2017LAB3_Vehicle(String vin, String model, String color, String make,
int year, int miles){
this.vin = vin;
this.model = model;
this.color = color;
this.make = make;
this.year = year;
this.miles = miles;
}
// mutator method
public void setVin(String vin){
this.vin = vin;
}
// accessor method
public String getVin(){
return vin;
}
public void setColor(String color){
this.color = color;
}
public String getColor(){
return color;
}
public void setMake(String make){
this.make = make;
}
public String getMake(){
return make;
}
public void setYear(int year){
this.year = year;
}
public int getYear(){
return year;
}
public void setMiles(int miles){
this.miles = miles;
}
public int getMiles(){
return miles;
}
public void forward(){
System.out.println("How far forward would you like to go?");
miles = keyboard.nextInt();
System.out.println("Move forward " + miles + " mile(s)");
}
public void backward(){
System.out.println("How far backward would you like to go?");
miles = keyboard.nextInt();
System.out.println("Move backward " + miles + " mile(s)");
}
public void left(){
System.out.println("Turn left");
}
public void right(){
System.out.println("Turn right");
}
// Standard output list
public String toString() {
String infoOutput = "VIN:t" + vin + " Color:t" + color + " Year:t";
return infoOutput;
}
public SP2017LAB3_Vehicle deepCopy(){
SP2017LAB3_Vehicle clone = new SP2017LAB3_Vehicle(vin, model, color, make, year,
miles);
return clone;
}
public int compareTo(String targetKey){
return(vin.compareTo(targetKey));
}
}
***Car***
import java.util.Scanner;
public class SP2017LAB3_Car extends SP2017LAB3_Vehicle{
private static Scanner keyboard = new Scanner(System.in);
int doors;
int passengers;
public SP2017LAB3_Car() {
super();
doors = 0;
passengers = 0;
}
//
public SP2017LAB3_Car(String vin, String model, String color, String make,
int year, int miles, int door, int passenger){
super(vin, model, color, make, year, miles);
doors = door;
passengers = passenger;
}
public int getDoors(){
return doors;
}
public void setDoors(int door){
doors = door;
}
public int getPassengers(){
return passengers;
}
public void setPassengers(int passenger){
passengers = passenger;
}
public void printCar(){
super.toString();
System.out.println("Car make: t" + make + " Model: t" + model + " Number of
passengers: " + passengers +
" Number of doors: " + doors);
}
public void carInfo(){
System.out.println("How many passengers can legally ride in the car?");
passengers = keyboard.nextInt();
System.out.println("How many doors does the car have?");
doors = keyboard.nextInt();
}
}
***Motorcycle***
import java.util.Scanner;
publicclass SP2017LAB3_Motorcycle extends SP2017LAB3_Vehicle {
privatestatic Scanner keyboard = new Scanner(System.in);
boolean sideCars;
String hasSideCar;
public SP2017LAB3_Motorcycle (){
super();
sideCars = false;
}
public SP2017LAB3_Motorcycle (String vin, String model, String color, String make,
int year, int miles) {
super(vin, model, color, make, year, miles);
sideCars = false;
}
publicvoid setSideCars(boolean sideCar){
sideCars = sideCar;
}
publicboolean getSideCars(){
return sideCars;
}
publicvoid printMotorcycle(){
super.toString();
if (sideCars == true){
hasSideCar = "Yes";
}
else{
hasSideCar = "No";
}
System.out.println("Motorcycle make: t" + make + " Model: t" + model + " Has
side car: " + hasSideCar);
}
}
***VehicleDealerShop***
import java.util.Scanner;
//
public class SP2017LAB3_VehicleDealerShop {
static SP2017LAB3_Vehicle newNode = null;
static String option = null, choice = null;
//
private static Scanner keyboard = new Scanner(System.in);
//
public static void main(String[]args){
//
SP2017LAB3_Vehicle inform = new SP2017LAB3_Vehicle();
//
SP2017LAB3_VehicleUnsortedOptimizedArray array = new
SP2017LAB3_VehicleUnsortedOptimizedArray();
while(true){
//
System.out.println("1: Insert a car or motorcycle");
System.out.println("2. Test for the encapsulation of the data structure");
System.out.println("3. Remove a car or motorcycle");
System.out.println("4. Update information of a car or motorcycle");
System.out.println("5. Show all vehicles");
System.out.println("6. Exit");
//
int selection = Integer.parseInt(keyboard.nextLine());
//
switch(selection){
case 1:
//
System.out.println("*** TASK: INSERT and FETCH A CAR OR A MOTORCYCLE
***");
System.out.println("Do you wish to insert a car or motorcycle? Y/N");
option = keyboard.nextVehicleDealerShopLine();
if (option == "Y" || option == "y"){
System.out.println("What is the vin number for the car or motorcycle?");
System.out.println("What is the vin number for the car or motorcycle?");
inform.vin = keyboard.nextLine();
System.out.println("What is the color of the vehicle?");
inform.color = keyboard.nextLine();
System.out.println("What is the year of the vehicle?");
inform.year = keyboard.nextInt();
System.out.println("What is the make of the vehicle?");
inform.make = keyboard.nextLine();
System.out.println("What is the model of the vehicle?");
inform.model = keyboard.nextLine();
System.out.println("Is the vehicle a car? Y/N");
choice = keyboard.nextLine();
if (choice == "Y" || choice == "y"){
System.out.println("How many passengers can legally ride in the car?");
inform.passengers = keyboard.nextInt();
System.out.println("How many doors does the car have?");
inform.doors = keyboard.nextInt();
}
else{
System.out.println("Does the motorcycle have a sidecar? Y/N");
inform.sideCar = keyboard.nextLine();
}
array.insert(newNode);
}
else{
System.out.println("What is the vin number for the car or motorcycle?");
array.fetch(inform.vin);
}
//
case 2:
//
System.out.println("*** TASK: TEST FOR DATA ENCAPSULATION ***");
case 3:
//
case 4:
//
case 5:
//
case 6:
//
}
}
}
}
***VehicleUnsortedOptimizedArray***
public class SP2017LAB3_VehicleUnsortedOptimizedArray {
private int next;
private int size;
private SP2017LAB3_Vehicle[] data;
public SP2017LAB3_VehicleUnsortedOptimizedArray(){
next = 0;
size = 25;
data = new SP2017LAB3_Vehicle[size];
}
public boolean insert(SP2017LAB3_Vehicle newNode){
if (next >= size)
return false;
data[next] = newNode.deepCopy();
if(data[next] == null)
return false;
next = next +1;
return true;
}
public SP2017LAB3_Vehicle fetch(String targetKey){
SP2017LAB3_Vehicle node;
SP2017LAB3_Vehicle temp;
int i = 0;
while(i< next && !(data[i].compareTo(targetKey) == 0)){
i++;
}
if(i== next)
return null;
node = data[i].deepCopy();
if(i != 0){
temp = data[i - 1];
data[i - 1] = data[i];
data[i] = temp;
}
return node;
}
public boolean delete(String targetKey){
int i = 0;
while(i < next && !(data[i].compareTo(targetKey) == 0)){
i++;
}
if(i == next)
return false;
data[i] = data[next - 1];
data[next - 1] = null;
next = next - 1;
return true;
}
public boolean update(String targetKey, SP2017LAB3_Vehicle newNode){
if(delete(targetKey) == false)
return false;
else if(insert(newNode) == false)
return false;
else
return true;
}
}
COSC2436 – Lab3
1
Solution
A)
import java.util.Scanner;
public class SP2017LAB3_Vehicle{
private static Scanner keyboard = new Scanner(System.in);
protected String vin, model, sideCar;
protected String color;
protected String make;
protected int year, miles, passengers, doors;
public SP2017LAB3_Vehicle() {
vin = null;
model = null;
color = null;
make = null;
year = 0;
miles = 0;
}
//parameter constructor
public SP2017LAB3_Vehicle(String vin, String model, String color, String make,
int year, int miles){
this.vin = vin;
this.model = model;
this.color = color;
this.make = make;
this.year = year;
this.miles = miles;
}
public void setVin(String vin){
this.vin = vin;
}
public String getVin(){
return vin;
}
public void setColor(String color){
this.color = color;
}
public String getColor(){
return color;
}
public void setMake(String make){
this.make = make;
}
public String getMake(){
return make;
}
public void setYear(int year){
this.year = year;
}
public int getYear(){
return year;
}
public void setMiles(int miles){
this.miles = miles;
}
public int getMiles(){
return miles;
}
public void forward(){
System.out.println("How far forward would you like to go?");
miles = keyboard.nextInt();
System.out.println("Move forward " + miles + " mile(s)");
}
public void backward(){
System.out.println("How far backward would you like to go?");
miles = keyboard.nextInt();
System.out.println("Move backward " + miles + " mile(s)");
}
public void left(){
System.out.println("Turn left");
}
public void right(){
System.out.println("Turn right");
}
public String toString() {
String infoOutput = "VIN:t" + vin + " Color:t" + color + " Year:t";
return infoOutput;
}
public SP2017LAB3_Vehicle deepCopy(){
SP2017LAB3_Vehicle clone = new SP2017LAB3_Vehicle(vin, model, color, make, year,
miles);
return clone;
}
public int compareTo(String targetKey){
return(vin.compareTo(targetKey));
}
}
import java.util.Scanner;
public class SP2017LAB3_Car extends SP2017LAB3_Vehicle{
private static Scanner keyboard = new Scanner(System.in);
int doors;
int passengers;
public SP2017LAB3_Car() {
super();
doors = 0;
passengers = 0;
}
public SP2017LAB3_Car(String vin, String model, String color, String make,
int year, int miles, int door, int passenger){
super(vin, model, color, make, year, miles);
doors = door;
passengers = passenger;
}
public int getDoors(){
return doors;
}
public void setDoors(int door){
doors = door;
}
public int getPassengers(){
return passengers;
}
public void setPassengers(int passenger){
passengers = passenger;
}
public void printCar(){
super.toString();
System.out.println("Car make: t" + make + " Model: t" + model + " Number of
passengers: " + passengers +
" Number of doors: " + doors);
}
public void carInfo(){
System.out.println("How many passengers can legally ride in the car?");
passengers = keyboard.nextInt();
System.out.println("How many doors does the car have?");
doors = keyboard.nextInt();
}
}
import java.util.Scanner;
public class SP2017LAB3_Motorcycle extends SP2017LAB3_Vehicle {
private static Scanner keyboard = new Scanner(System.in);
boolean sideCars;
String hasSideCar;
public SP2017LAB3_Motorcycle (){
super();
sideCars = false;
}
public SP2017LAB3_Motorcycle (String vin, String model, String color, String make,
int year, int miles) {
super(vin, model, color, make, year, miles);
sideCars = false;
}
public void setSideCars(boolean sideCar){
sideCars = sideCar;
}
public boolean getSideCars(){
return sideCars;
}
public void printMotorcycle(){
super.toString();
if (sideCars == true){
hasSideCar = "Yes";
}
else{
hasSideCar = "No";
}
System.out.println("Motorcycle make: t" + make + " Model: t" + model + " Has side car:
" + hasSideCar);
}
}
import java.util.Scanner;
//
public class SP2017LAB3_VehicleDealerShop {
static SP2017LAB3_Vehicle newNode = null;
static String option = null, choice = null;
//
private static Scanner keyboard = new Scanner(System.in);
//
public static void main(String[]args){
//
SP2017LAB3_Vehicle inform = new SP2017LAB3_Vehicle();
//
SP2017LAB3_VehicleUnsortedOptimizedArray array = new
SP2017LAB3_VehicleUnsortedOptimizedArray();
while(true){
//
System.out.println("1: Insert a car or motorcycle");
System.out.println("2. Test for the encapsulation of the data structure");
System.out.println("3. Remove a car or motorcycle");
System.out.println("4. Update information of a car or motorcycle");
System.out.println("5. Show all vehicles");
System.out.println("6. Exit");
//
int selection = Integer.parseInt(keyboard.nextLine());
//
switch(selection){
case 1:
//
System.out.println("*** TASK: INSERT and FETCH A CAR OR A MOTORCYCLE ***");
System.out.println("Do you wish to insert a car or motorcycle? Y/N");
option = keyboard.nextVehicleDealerShopLine();
if (option == "Y" || option == "y"){
System.out.println("What is the vin number for the car or motorcycle?");
System.out.println("What is the vin number for the car or motorcycle?");
inform.vin = keyboard.nextLine();
System.out.println("What is the color of the vehicle?");
inform.color = keyboard.nextLine();
System.out.println("What is the year of the vehicle?");
inform.year = keyboard.nextInt();
System.out.println("What is the make of the vehicle?");
inform.make = keyboard.nextLine();
System.out.println("What is the model of the vehicle?");
inform.model = keyboard.nextLine();
System.out.println("Is the vehicle a car? Y/N");
choice = keyboard.nextLine();
if (choice == "Y" || choice == "y"){
System.out.println("How many passengers can legally ride in the car?");
inform.passengers = keyboard.nextInt();
System.out.println("How many doors does the car have?");
inform.doors = keyboard.nextInt();
}
else{
System.out.println("Does the motorcycle have a sidecar? Y/N");
inform.sideCar = keyboard.nextLine();
}
array.insert(newNode);
}
else{
System.out.println("What is the vin number for the car or motorcycle?");
array.fetch(inform.vin);
}
//
case 2:
System.out.println("*** TASK: TEST FOR DATA ENCAPSULATION ***");
case3:
//
}
}
}
}
public class SP2017LAB3_VehicleUnsortedOptimizedArray {
private int next;
private int size;
private SP2017LAB3_Vehicle[] data;
public SP2017LAB3_VehicleUnsortedOptimizedArray(){
next = 0;
size = 25;
data = new SP2017LAB3_Vehicle[size];
}
public boolean insert(SP2017LAB3_Vehicle newNode){
if (next >= size)
return false;
data[next] = newNode.deepCopy();
if(data[next] == null)
return false;
next = next +1;
return true;
}
public SP2017LAB3_Vehicle fetch(String targetKey){
SP2017LAB3_Vehicle node;
SP2017LAB3_Vehicle temp;
int i = 0;
while(i< next && !(data[i].compareTo(targetKey) == 0)){
i++;
}
if(i== next)
return null;
node = data[i].deepCopy();
if(i != 0){
temp = data[i - 1];
data[i - 1] = data[i];
data[i] = temp;
}
return node;
}
public boolean delete(String targetKey){
int i = 0;
while(i < next && !(data[i].compareTo(targetKey) == 0)){
i++;
}
if(i == next)
return false;
data[i] = data[next - 1];
data[next - 1] = null;
next = next - 1;
return true;
}
ReactDEEP.DEEPCopyNode(editorState.getSelection().getStartKey())
return true;
}
}

More Related Content

Similar to This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf

Goal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfGoal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdf
arsmobiles
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
admin463580
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdf
enodani2008
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docx
Isaac9LjWelchq
 
College for Women Department of Information Science
College for Women  Department of Information Science  College for Women  Department of Information Science
College for Women Department of Information Science
WilheminaRossi174
 
Create a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdfCreate a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdf
archanacomputers1
 

Similar to This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf (20)

Java doc Pr ITM2
Java doc Pr ITM2Java doc Pr ITM2
Java doc Pr ITM2
 
Public class race track {public static void main(string[] args
Public class race track {public static void main(string[] argsPublic class race track {public static void main(string[] args
Public class race track {public static void main(string[] args
 
Object Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. ArrayObject Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. Array
 
Goal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdfGoal The goal of this assignment is to help students understand the.pdf
Goal The goal of this assignment is to help students understand the.pdf
 
Competition 1 (blog 1)
Competition 1 (blog 1)Competition 1 (blog 1)
Competition 1 (blog 1)
 
Please the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdfPlease the following is the currency class of perious one- class Curre.pdf
Please the following is the currency class of perious one- class Curre.pdf
 
R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?
 
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin XuSenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
SenchaCon 2016: Developing COSMOS Using Sencha Ext JS 5 - Shenglin Xu
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdf
 
L9
L9L9
L9
 
hello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docxhello- please dont just copy from other answers- the following is the.docx
hello- please dont just copy from other answers- the following is the.docx
 
IBM SpaceX Capstone Project
IBM SpaceX Capstone ProjectIBM SpaceX Capstone Project
IBM SpaceX Capstone Project
 
Vb net1
Vb net1Vb net1
Vb net1
 
C# Programming Help
C# Programming HelpC# Programming Help
C# Programming Help
 
College for Women Department of Information Science
College for Women  Department of Information Science  College for Women  Department of Information Science
College for Women Department of Information Science
 
College for women department of information science
College for women  department of information science  College for women  department of information science
College for women department of information science
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
 
A machine learning model for average fuel consumption in heavy vehicles
A machine learning model for average fuel consumption in heavy vehiclesA machine learning model for average fuel consumption in heavy vehicles
A machine learning model for average fuel consumption in heavy vehicles
 
Vehicle Parking System Project
Vehicle Parking System ProjectVehicle Parking System Project
Vehicle Parking System Project
 
Create a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdfCreate a system to simulate vehicles at an intersection. Assume th.pdf
Create a system to simulate vehicles at an intersection. Assume th.pdf
 

More from bharatchawla141

A 71-year-old male patient comes to the hospital after having been p.pdf
A 71-year-old male patient comes to the hospital after having been p.pdfA 71-year-old male patient comes to the hospital after having been p.pdf
A 71-year-old male patient comes to the hospital after having been p.pdf
bharatchawla141
 
What is the function in homworts Where can one find homwortsS.pdf
What is the function  in homworts  Where can one find homwortsS.pdfWhat is the function  in homworts  Where can one find homwortsS.pdf
What is the function in homworts Where can one find homwortsS.pdf
bharatchawla141
 

More from bharatchawla141 (20)

Explain how HPV leads to cervical cancer and oral cancer. Include.pdf
Explain how HPV leads to cervical cancer and oral cancer. Include.pdfExplain how HPV leads to cervical cancer and oral cancer. Include.pdf
Explain how HPV leads to cervical cancer and oral cancer. Include.pdf
 
Consider L = {a^nb^2nc^P p 0}. Prove L is not a context-free langu.pdf
Consider L = {a^nb^2nc^P  p  0}. Prove L is not a context-free langu.pdfConsider L = {a^nb^2nc^P  p  0}. Prove L is not a context-free langu.pdf
Consider L = {a^nb^2nc^P p 0}. Prove L is not a context-free langu.pdf
 
Differentiate between analog and digital signals.SolutionIn ana.pdf
Differentiate between analog and digital signals.SolutionIn ana.pdfDifferentiate between analog and digital signals.SolutionIn ana.pdf
Differentiate between analog and digital signals.SolutionIn ana.pdf
 
describe two properties of iPS and ES cells, including the meaning i.pdf
describe two properties of iPS and ES cells, including the meaning i.pdfdescribe two properties of iPS and ES cells, including the meaning i.pdf
describe two properties of iPS and ES cells, including the meaning i.pdf
 
Coffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdf
Coffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdfCoffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdf
Coffman Company issued 1,000,000 10 year 10 percent bonds January 1,.pdf
 
A JAR file contains an image named images Fall.png. Java class na.pdf
A JAR file contains an image named images Fall.png. Java class na.pdfA JAR file contains an image named images Fall.png. Java class na.pdf
A JAR file contains an image named images Fall.png. Java class na.pdf
 
A 71-year-old male patient comes to the hospital after having been p.pdf
A 71-year-old male patient comes to the hospital after having been p.pdfA 71-year-old male patient comes to the hospital after having been p.pdf
A 71-year-old male patient comes to the hospital after having been p.pdf
 
You are carrying out experiments in cell fusion by fusing together ce.pdf
You are carrying out experiments in cell fusion by fusing together ce.pdfYou are carrying out experiments in cell fusion by fusing together ce.pdf
You are carrying out experiments in cell fusion by fusing together ce.pdf
 
Write an MPI program that implements a shell-sort like parallel algo.pdf
Write an MPI program that implements a shell-sort like parallel algo.pdfWrite an MPI program that implements a shell-sort like parallel algo.pdf
Write an MPI program that implements a shell-sort like parallel algo.pdf
 
Which of the following are roles of proteins Pick ALL that apply..pdf
Which of the following are roles of proteins Pick ALL that apply..pdfWhich of the following are roles of proteins Pick ALL that apply..pdf
Which of the following are roles of proteins Pick ALL that apply..pdf
 
When are a persons fellowship, autonomy, and competence face threa.pdf
When are a persons fellowship, autonomy, and competence face threa.pdfWhen are a persons fellowship, autonomy, and competence face threa.pdf
When are a persons fellowship, autonomy, and competence face threa.pdf
 
What is the function in homworts Where can one find homwortsS.pdf
What is the function  in homworts  Where can one find homwortsS.pdfWhat is the function  in homworts  Where can one find homwortsS.pdf
What is the function in homworts Where can one find homwortsS.pdf
 
Two paragraph opinion about the film editing of the movie LIFE OF .pdf
Two paragraph opinion about the film editing of the movie LIFE OF .pdfTwo paragraph opinion about the film editing of the movie LIFE OF .pdf
Two paragraph opinion about the film editing of the movie LIFE OF .pdf
 
True or False The aDDM fixes the SV reference problem by assuming t.pdf
True or False The aDDM fixes the SV reference problem by assuming t.pdfTrue or False The aDDM fixes the SV reference problem by assuming t.pdf
True or False The aDDM fixes the SV reference problem by assuming t.pdf
 
The number of visits to public libraries increased from 1.4 billion i.pdf
The number of visits to public libraries increased from 1.4 billion i.pdfThe number of visits to public libraries increased from 1.4 billion i.pdf
The number of visits to public libraries increased from 1.4 billion i.pdf
 
The first table contains data of the Student entry. Attributes are Si.pdf
The first table contains data of the Student entry. Attributes are Si.pdfThe first table contains data of the Student entry. Attributes are Si.pdf
The first table contains data of the Student entry. Attributes are Si.pdf
 
Save for Later 12) Viruses, adware and spyware are referred to collec.pdf
Save for Later 12) Viruses, adware and spyware are referred to collec.pdfSave for Later 12) Viruses, adware and spyware are referred to collec.pdf
Save for Later 12) Viruses, adware and spyware are referred to collec.pdf
 
Sustainability Sustainability is an important consideration for any.pdf
Sustainability Sustainability is an important consideration for any.pdfSustainability Sustainability is an important consideration for any.pdf
Sustainability Sustainability is an important consideration for any.pdf
 
Research health data stewardship and in your post show why it is imp.pdf
Research health data stewardship and in your post show why it is imp.pdfResearch health data stewardship and in your post show why it is imp.pdf
Research health data stewardship and in your post show why it is imp.pdf
 
Read carefully. Im not sure if the point class is correct but postin.pdf
Read carefully. Im not sure if the point class is correct but postin.pdfRead carefully. Im not sure if the point class is correct but postin.pdf
Read carefully. Im not sure if the point class is correct but postin.pdf
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 

Recently uploaded (20)

Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
NLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptxNLC-2024-Orientation-for-RO-SDO (1).pptx
NLC-2024-Orientation-for-RO-SDO (1).pptx
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Salient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptxSalient features of Environment protection Act 1986.pptx
Salient features of Environment protection Act 1986.pptx
 

This is the assignmentOBJECTIVESAfter finishing this lab, stude.pdf

  • 1. This is the assignment: OBJECTIVES After finishing this lab, students can have the following: Understand how to declare an unsorted-optimized array data structure Know how to insert nodes to the structure, fetch a node with a key field of node, update the information of a node and delete a node from the structure Verify that the nodes in the unsorted-optimized array data structure are fully encapsulated. Students will be familiar with the ArrayList and apply all the basic operation to access nodes Also, students recognize that ArrayList is a heterogeneous data structure that can store nodes of any type of objects. REQUIREMENT STATEMENT A car dealer needs an application that can help the shop to do the following tasks: 1.Insert a car or a motocycle 2.Test for the encapsulation of the data structure 3.Remove a car or a motocycle 4.Update information of a car or a motocycle 5.Show All vehicles 6.Exit Also, the owner of the shop asks for: -Using the Unsorted Optimized Array data structure for the application and apply Inheritance and polymorphism of Object Oriented Programming -Requiement for output: The car’s information is displayed as below (for example) VIN: 123A456B Color: White Year: 2014 Car make: Toyota Model: Sienna Number of passengers: 8 Number of doors: 4 The motocycle’s information is displayed as below (for example VIN: 321BC654 Color: Grey Year: 2015 Motocycle make: Honda Model: PCX150 Has side car: no -After a task from the menu, the application should allow users to continue using the application and only terminate when users select Exit COSC2436 – Lab3
  • 2. 1 TASK INSERT -Display the message: “*** TASK: INSERT and FETCH A CAR OR A MOTOCYCLE ***” -Allow users to enter the information of a car or a motocyle from the keyboard -Insert the car/motocycle to the data structure -Fetch the information of car/motocycle by its VIN from the data structure that have entered to the structure to ensure that the car/motocycle is in the structure TEST FOR ENCAPSULATION -Display the message: “*** TASK: TEST FOR DATA ENCAPSULATION ***” -Create a test car with the following information typed from the keyboard: -Insert this test car to the data structure -Modify the the color of the test car with different color -Declare an object of car named “copy” and assign the node that is fetched from the data structure with the target key as VIN of test car -Display information of the object named copy -Compare the color of test car with the color of object copy. If they are different then display the message: “The Unsorted Optimized Array structure has the encapsulation”; otherwise display “The Unsorted Optimized Array structure does not have the encapsulation” TASK UPDATE -Display: “***TASK: UPDATE INFORMATION OF A CAR OR A MOTOCYCLE *** “ - Create an object of class Car named newNode -Fetch a node with the VIN is the same VIN of test car then assign to newNode, therefore, the newNode has the same VIN with the test car -Change the color of the newNode to different color -Update the data structure with with the newNode -Fetch with the key as the key of test car. If the node resulted from fetch has different color from the test car the display the message “Update test car successfully”; otherwise display “Update test car failed” TASK DELETE -Display: “ *** TASK: DELETE A CAR OR A MOTOCYCLE ***” -Delete the node with the VIN as SP2017 that was not inserted to the data structure, print out the result of task delete (output: false) -Delete the node with the VIN of the above test car, print the result (output: true) -Fetch with the key as the VIN of the test car, print out the result (output: null) TASK SHOW ALL -Call showAll to display all nodes on the data structure
  • 3. WHAT WE NEED TO KNOW TO DO THE PROGRAM -Review how to declare the Inheritance relationship between 2 classes -How to write the constructor, toString or other methods of child classes to inherit from the super class -How to apply polymorphism to the main -Understand what is Unsorted Optimized Array structure, how initialize the Unsorted Optimized Array data structure -How 4 operations of Unsorted Optimized Array structure work UML and PSUEDO-CODE You should provide the UML of super class, and 2 child classes The pseudo-code is provided in the requirement, you do not need to rewrite; just follow step by step to write the code COSC2436 – Lab3 2 HOW TO DO THE LAB part1 -After provide UML and read the pseudo-code, start the Java editor -Create the project name SP2017LAB3_PART1_yourLastname -Add super class named SP2017LAB3_Vehicle_yourLastname that maintain Vin number, color, make, model, year. It also has some methods, such as, mutator, accessor, and toString, method forward (accept the amount of distance in miles, for example, 25, then display “move forward 25 miles”), method backward (accept the amount of distance in miles, for example 3 then display the message “move backward 3 miles”), turn left (display word “Turn left”) and turn right (display word “Turn Rright”) -Add child class named SP2017LAB3_Car_yourLastName inherits from above class Vehicle. It has more data members, such as, number of passengers, number of doors -Add child class named SP2017LAB3_Motocycle_yourLastName inherits from above class Vehicle. It has more data members, such as, has side car (boolean) -Add a data structure class named SP2017LAB3_VehicleUnsortedOptimizedArray_yourLastName that maintain size(int), a vehicle array and next (int) to hold the location where the new node is inserted to the structure. Also, the class has the methods for 4 operations: insert, fetch, delete, update and showAll that display all the nodes in the structure. ( see the code on page 103 for your reference) -Add a driver class name SP2017LAB3_VehicleDealerShop_yourLastname that do the requirement asking for PART2: OBJECTIVES: Practice using Java ArrayList class. REQUIREMENT and HOW TO DO THE LAB PART2
  • 4. Add the following part to the previous project with the following step by strep (pseudo-code) -Declare a data structure of ArrayList with the size 25 -Insert 3 cars/motocycles with information that are entered from the keyboard -Show all 3 nodes that have inserted to the ArrayList data structure -Use a for loop to insert number 1 to 100 to the above data structure of ArrayList -Display the size of the above ArrayList. -Remove the one above car/motocycle from the ArrayList data structure with one of the VIN displyed at above showAll(). Then display the size of the ArrayList structure -Get and display the information of nodes at the location 45. Change the value at location 45 to 2016. Display the information at location 45 again -Use JOptionPane to display the message: “Congratulation! You are successful on ArrayList with four operations: add, get, remove and set” This is the code I have so far: ***Vehicle Class*** import java.util.Scanner; public class SP2017LAB3_Vehicle{ // private static Scanner keyboard = new Scanner(System.in); protected String vin, model, sideCar; protected String color; protected String make; protected int year, miles, passengers, doors; // default constructor public SP2017LAB3_Vehicle() { vin = null; model = null; color = null; make = null; year = 0; miles = 0; } //parameter constructor public SP2017LAB3_Vehicle(String vin, String model, String color, String make,
  • 5. int year, int miles){ this.vin = vin; this.model = model; this.color = color; this.make = make; this.year = year; this.miles = miles; } // mutator method public void setVin(String vin){ this.vin = vin; } // accessor method public String getVin(){ return vin; } public void setColor(String color){ this.color = color; } public String getColor(){ return color; } public void setMake(String make){ this.make = make; } public String getMake(){ return make;
  • 6. } public void setYear(int year){ this.year = year; } public int getYear(){ return year; } public void setMiles(int miles){ this.miles = miles; } public int getMiles(){ return miles; } public void forward(){ System.out.println("How far forward would you like to go?"); miles = keyboard.nextInt(); System.out.println("Move forward " + miles + " mile(s)"); } public void backward(){ System.out.println("How far backward would you like to go?"); miles = keyboard.nextInt(); System.out.println("Move backward " + miles + " mile(s)"); } public void left(){ System.out.println("Turn left"); } public void right(){
  • 7. System.out.println("Turn right"); } // Standard output list public String toString() { String infoOutput = "VIN:t" + vin + " Color:t" + color + " Year:t"; return infoOutput; } public SP2017LAB3_Vehicle deepCopy(){ SP2017LAB3_Vehicle clone = new SP2017LAB3_Vehicle(vin, model, color, make, year, miles); return clone; } public int compareTo(String targetKey){ return(vin.compareTo(targetKey)); } } ***Car*** import java.util.Scanner; public class SP2017LAB3_Car extends SP2017LAB3_Vehicle{ private static Scanner keyboard = new Scanner(System.in); int doors; int passengers; public SP2017LAB3_Car() { super(); doors = 0; passengers = 0; } // public SP2017LAB3_Car(String vin, String model, String color, String make,
  • 8. int year, int miles, int door, int passenger){ super(vin, model, color, make, year, miles); doors = door; passengers = passenger; } public int getDoors(){ return doors; } public void setDoors(int door){ doors = door; } public int getPassengers(){ return passengers; } public void setPassengers(int passenger){ passengers = passenger; } public void printCar(){ super.toString(); System.out.println("Car make: t" + make + " Model: t" + model + " Number of passengers: " + passengers + " Number of doors: " + doors); } public void carInfo(){ System.out.println("How many passengers can legally ride in the car?"); passengers = keyboard.nextInt(); System.out.println("How many doors does the car have?"); doors = keyboard.nextInt(); } }
  • 9. ***Motorcycle*** import java.util.Scanner; publicclass SP2017LAB3_Motorcycle extends SP2017LAB3_Vehicle { privatestatic Scanner keyboard = new Scanner(System.in); boolean sideCars; String hasSideCar; public SP2017LAB3_Motorcycle (){ super(); sideCars = false; } public SP2017LAB3_Motorcycle (String vin, String model, String color, String make, int year, int miles) { super(vin, model, color, make, year, miles); sideCars = false; } publicvoid setSideCars(boolean sideCar){ sideCars = sideCar; } publicboolean getSideCars(){ return sideCars; } publicvoid printMotorcycle(){ super.toString(); if (sideCars == true){ hasSideCar = "Yes"; } else{ hasSideCar = "No";
  • 10. } System.out.println("Motorcycle make: t" + make + " Model: t" + model + " Has side car: " + hasSideCar); } } ***VehicleDealerShop*** import java.util.Scanner; // public class SP2017LAB3_VehicleDealerShop { static SP2017LAB3_Vehicle newNode = null; static String option = null, choice = null; // private static Scanner keyboard = new Scanner(System.in); // public static void main(String[]args){ // SP2017LAB3_Vehicle inform = new SP2017LAB3_Vehicle(); // SP2017LAB3_VehicleUnsortedOptimizedArray array = new SP2017LAB3_VehicleUnsortedOptimizedArray(); while(true){ // System.out.println("1: Insert a car or motorcycle"); System.out.println("2. Test for the encapsulation of the data structure"); System.out.println("3. Remove a car or motorcycle"); System.out.println("4. Update information of a car or motorcycle"); System.out.println("5. Show all vehicles"); System.out.println("6. Exit");
  • 11. // int selection = Integer.parseInt(keyboard.nextLine()); // switch(selection){ case 1: // System.out.println("*** TASK: INSERT and FETCH A CAR OR A MOTORCYCLE ***"); System.out.println("Do you wish to insert a car or motorcycle? Y/N"); option = keyboard.nextVehicleDealerShopLine(); if (option == "Y" || option == "y"){ System.out.println("What is the vin number for the car or motorcycle?"); System.out.println("What is the vin number for the car or motorcycle?"); inform.vin = keyboard.nextLine(); System.out.println("What is the color of the vehicle?"); inform.color = keyboard.nextLine(); System.out.println("What is the year of the vehicle?"); inform.year = keyboard.nextInt(); System.out.println("What is the make of the vehicle?"); inform.make = keyboard.nextLine(); System.out.println("What is the model of the vehicle?"); inform.model = keyboard.nextLine(); System.out.println("Is the vehicle a car? Y/N"); choice = keyboard.nextLine(); if (choice == "Y" || choice == "y"){ System.out.println("How many passengers can legally ride in the car?"); inform.passengers = keyboard.nextInt(); System.out.println("How many doors does the car have?"); inform.doors = keyboard.nextInt(); } else{
  • 12. System.out.println("Does the motorcycle have a sidecar? Y/N"); inform.sideCar = keyboard.nextLine(); } array.insert(newNode); } else{ System.out.println("What is the vin number for the car or motorcycle?"); array.fetch(inform.vin); } // case 2: // System.out.println("*** TASK: TEST FOR DATA ENCAPSULATION ***"); case 3: // case 4: // case 5: // case 6: // } } } } ***VehicleUnsortedOptimizedArray*** public class SP2017LAB3_VehicleUnsortedOptimizedArray { private int next; private int size;
  • 13. private SP2017LAB3_Vehicle[] data; public SP2017LAB3_VehicleUnsortedOptimizedArray(){ next = 0; size = 25; data = new SP2017LAB3_Vehicle[size]; } public boolean insert(SP2017LAB3_Vehicle newNode){ if (next >= size) return false; data[next] = newNode.deepCopy(); if(data[next] == null) return false; next = next +1; return true; } public SP2017LAB3_Vehicle fetch(String targetKey){ SP2017LAB3_Vehicle node; SP2017LAB3_Vehicle temp; int i = 0; while(i< next && !(data[i].compareTo(targetKey) == 0)){ i++; } if(i== next) return null; node = data[i].deepCopy(); if(i != 0){ temp = data[i - 1]; data[i - 1] = data[i]; data[i] = temp;
  • 14. } return node; } public boolean delete(String targetKey){ int i = 0; while(i < next && !(data[i].compareTo(targetKey) == 0)){ i++; } if(i == next) return false; data[i] = data[next - 1]; data[next - 1] = null; next = next - 1; return true; } public boolean update(String targetKey, SP2017LAB3_Vehicle newNode){ if(delete(targetKey) == false) return false; else if(insert(newNode) == false) return false; else return true; } } COSC2436 – Lab3 1 Solution A) import java.util.Scanner; public class SP2017LAB3_Vehicle{ private static Scanner keyboard = new Scanner(System.in);
  • 15. protected String vin, model, sideCar; protected String color; protected String make; protected int year, miles, passengers, doors; public SP2017LAB3_Vehicle() { vin = null; model = null; color = null; make = null; year = 0; miles = 0; } //parameter constructor public SP2017LAB3_Vehicle(String vin, String model, String color, String make, int year, int miles){ this.vin = vin; this.model = model; this.color = color; this.make = make; this.year = year; this.miles = miles; } public void setVin(String vin){ this.vin = vin; } public String getVin(){ return vin; } public void setColor(String color){ this.color = color;
  • 16. } public String getColor(){ return color; } public void setMake(String make){ this.make = make; } public String getMake(){ return make; } public void setYear(int year){ this.year = year; } public int getYear(){ return year; } public void setMiles(int miles){ this.miles = miles; } public int getMiles(){ return miles; } public void forward(){ System.out.println("How far forward would you like to go?"); miles = keyboard.nextInt(); System.out.println("Move forward " + miles + " mile(s)");
  • 17. } public void backward(){ System.out.println("How far backward would you like to go?"); miles = keyboard.nextInt(); System.out.println("Move backward " + miles + " mile(s)"); } public void left(){ System.out.println("Turn left"); } public void right(){ System.out.println("Turn right"); } public String toString() { String infoOutput = "VIN:t" + vin + " Color:t" + color + " Year:t"; return infoOutput; } public SP2017LAB3_Vehicle deepCopy(){ SP2017LAB3_Vehicle clone = new SP2017LAB3_Vehicle(vin, model, color, make, year, miles); return clone; } public int compareTo(String targetKey){ return(vin.compareTo(targetKey)); } } import java.util.Scanner; public class SP2017LAB3_Car extends SP2017LAB3_Vehicle{ private static Scanner keyboard = new Scanner(System.in); int doors; int passengers;
  • 18. public SP2017LAB3_Car() { super(); doors = 0; passengers = 0; } public SP2017LAB3_Car(String vin, String model, String color, String make, int year, int miles, int door, int passenger){ super(vin, model, color, make, year, miles); doors = door; passengers = passenger; } public int getDoors(){ return doors; } public void setDoors(int door){ doors = door; } public int getPassengers(){ return passengers; } public void setPassengers(int passenger){ passengers = passenger; } public void printCar(){ super.toString(); System.out.println("Car make: t" + make + " Model: t" + model + " Number of passengers: " + passengers + " Number of doors: " + doors);
  • 19. } public void carInfo(){ System.out.println("How many passengers can legally ride in the car?"); passengers = keyboard.nextInt(); System.out.println("How many doors does the car have?"); doors = keyboard.nextInt(); } } import java.util.Scanner; public class SP2017LAB3_Motorcycle extends SP2017LAB3_Vehicle { private static Scanner keyboard = new Scanner(System.in); boolean sideCars; String hasSideCar; public SP2017LAB3_Motorcycle (){ super(); sideCars = false; } public SP2017LAB3_Motorcycle (String vin, String model, String color, String make, int year, int miles) { super(vin, model, color, make, year, miles); sideCars = false; } public void setSideCars(boolean sideCar){ sideCars = sideCar; } public boolean getSideCars(){ return sideCars;
  • 20. } public void printMotorcycle(){ super.toString(); if (sideCars == true){ hasSideCar = "Yes"; } else{ hasSideCar = "No"; } System.out.println("Motorcycle make: t" + make + " Model: t" + model + " Has side car: " + hasSideCar); } } import java.util.Scanner; // public class SP2017LAB3_VehicleDealerShop { static SP2017LAB3_Vehicle newNode = null; static String option = null, choice = null; // private static Scanner keyboard = new Scanner(System.in); // public static void main(String[]args){ // SP2017LAB3_Vehicle inform = new SP2017LAB3_Vehicle(); // SP2017LAB3_VehicleUnsortedOptimizedArray array = new SP2017LAB3_VehicleUnsortedOptimizedArray(); while(true){ //
  • 21. System.out.println("1: Insert a car or motorcycle"); System.out.println("2. Test for the encapsulation of the data structure"); System.out.println("3. Remove a car or motorcycle"); System.out.println("4. Update information of a car or motorcycle"); System.out.println("5. Show all vehicles"); System.out.println("6. Exit"); // int selection = Integer.parseInt(keyboard.nextLine()); // switch(selection){ case 1: // System.out.println("*** TASK: INSERT and FETCH A CAR OR A MOTORCYCLE ***"); System.out.println("Do you wish to insert a car or motorcycle? Y/N"); option = keyboard.nextVehicleDealerShopLine(); if (option == "Y" || option == "y"){ System.out.println("What is the vin number for the car or motorcycle?"); System.out.println("What is the vin number for the car or motorcycle?"); inform.vin = keyboard.nextLine(); System.out.println("What is the color of the vehicle?"); inform.color = keyboard.nextLine(); System.out.println("What is the year of the vehicle?"); inform.year = keyboard.nextInt(); System.out.println("What is the make of the vehicle?"); inform.make = keyboard.nextLine(); System.out.println("What is the model of the vehicle?"); inform.model = keyboard.nextLine(); System.out.println("Is the vehicle a car? Y/N"); choice = keyboard.nextLine(); if (choice == "Y" || choice == "y"){ System.out.println("How many passengers can legally ride in the car?"); inform.passengers = keyboard.nextInt();
  • 22. System.out.println("How many doors does the car have?"); inform.doors = keyboard.nextInt(); } else{ System.out.println("Does the motorcycle have a sidecar? Y/N"); inform.sideCar = keyboard.nextLine(); } array.insert(newNode); } else{ System.out.println("What is the vin number for the car or motorcycle?"); array.fetch(inform.vin); } // case 2: System.out.println("*** TASK: TEST FOR DATA ENCAPSULATION ***"); case3: // } } } } public class SP2017LAB3_VehicleUnsortedOptimizedArray { private int next; private int size; private SP2017LAB3_Vehicle[] data; public SP2017LAB3_VehicleUnsortedOptimizedArray(){ next = 0; size = 25;
  • 23. data = new SP2017LAB3_Vehicle[size]; } public boolean insert(SP2017LAB3_Vehicle newNode){ if (next >= size) return false; data[next] = newNode.deepCopy(); if(data[next] == null) return false; next = next +1; return true; } public SP2017LAB3_Vehicle fetch(String targetKey){ SP2017LAB3_Vehicle node; SP2017LAB3_Vehicle temp; int i = 0; while(i< next && !(data[i].compareTo(targetKey) == 0)){ i++; } if(i== next) return null; node = data[i].deepCopy(); if(i != 0){ temp = data[i - 1]; data[i - 1] = data[i]; data[i] = temp; } return node; } public boolean delete(String targetKey){ int i = 0;
  • 24. while(i < next && !(data[i].compareTo(targetKey) == 0)){ i++; } if(i == next) return false; data[i] = data[next - 1]; data[next - 1] = null; next = next - 1; return true; } ReactDEEP.DEEPCopyNode(editorState.getSelection().getStartKey()) return true; } }