Assignment Objectives By the end of this assignment you shou

Assignment Objectives
By the end of this assignment you should be able to design, code, run and test original Java programs featuring arrays of objects.
Special Instructions
For this assignment and for most of the assignments for the remainder of the semester you will not be writing code that takes input from the keyboard or produces output with print statements. Rather, you will write original methods that take arguments and return values to the calling method (in this case, main). You will also no longer be including your own main methods in submitted work. Rather, for each assignment you will be provided with a driver class which contains the main method. Inside this main method you will write code to test your method, but you will not submit those tests for grading. For this assignment, the file containing the driver class is called Homework6Driver.java. Again, when it comes time to submit your work, you will submit only the .java file(s) containing your methods, and not the driver class. During grading we will use our own driver classes to test your methods.
To get you started on the homework we have posted on Blackboard the files CarRepairShop.java, which contains method stubs, and Homework6Driver.java, which has the main method. Stubs are method dec- larations that have no bodies (or have very minimal bodies). You will fill in the bodies of these methods for homework. Do not, under any circumstance, change the method headers. The testing driver class will be expect- ing exactly those methods declared in CarRepairShop.java.
Note: If you change the method headers and the testing driver class does not compile as a result, you will receive a ZERO on the assignment.
Note: Do NOT add a main method to CarRepairShop.java. You may, however, write any other methods as you wish to solve the homework problems. They must be included inside CarRepairShop.java.
Wolfie’s Car Repair Shop
For this assignment you will be completing a program that manages cars and car repairs at Wolfie’s Car Repair Shop. The program is menu-driven. The menu can be found in Homework6Driver.java. Provided in that fileisaseriesofmethodsthatbeginwiththeprefixmain .Thosemethodsrequestinputfromtheuserandthen call methods from the class CarRepairShop. It is these methods in the CarRepairShop that you will be implementing for homework.
In essence you will be implementing a very simple database system that uses arrays and possibly a handful of other variables to store data. The methods you write will implement basic “CRUD” functionality, as it is known in the database world: Create, Read, Update and Delete data records.
Because a major goal of this assignment is to give you practice working with arrays of objects, you are not permit- ted to use the ArrayList class or any other kind of collection except for arrays. The grading software will ana- lyze your code and search for the use of classes outside the java.lang package. If you import ANY packages or use any fully-qualified class names to use classes outside of java.lang (e.g., java.util.ArrayList), you will receive NO credit for the homework assignment.

Methods to Implement
Implement the following methods that can be found in CarRepairShop.java. You may create any additional methods and classes you like to complete this homework assignment. Be sure to submit all extra .java files your code needs to compile. Do not submit the driver class. Any files containing a main() method will be deleted when your homework is downloaded for grading.
Please note that none of these methods asks the user to give input. Also, none of them produces any output to the screen.
1. int addNewCar(String VIN, String make, int year) (1 point)
Adds a new car to the database with the provided VIN, make (e.g., Ford, Honda, Hyundai, etc.) and year of manufacture. If a car with the given VIN already exists in the database, the method returns ?1 and makes no changes to the database. Otherwise, the method returns the number of cars in the database after adding this new car.
2. int addRepairTicket(String VIN, double cost, String description) (1 point)
Adds a new repair ticket to the database for the car with the provided VIN, repair cost and repair description. If no car with the given VIN exists in the database, the method returns ?1 and makes no changes to the database. Otherwise, the method returns the repair ticket number. The first ticket added to the database has ticket number 1, the second has ticket number 2, etc. Ticket numbers always increase. For example, suppose 4 tickets were added and then two were deleted. The next ticket added would be assigned ticket number 5.
3. double getRepairCost(int ticketNum) (2 points)
Returns the cost of the repair associated with the provided repair ticket number. If no repair ticket with the given number exists in the database, the method returns ?1.0. Under no circumstances may the method make changes to the database.
4. double getTotalRepairCosts(String VIN) (2 points)
Returns the total of all repair costs for the car with the provided VIN. If no car with the given VIN exists in the database, the method returns ?1.0. Under no circumstances may the method make changes to the database.
5. String getWorstCarMake() (3 points)
Returns the make of car that had the greatest total number of repairs. Note that the method does not return the sum of the costs. Rather, it counts how many times each make of car was repaired and returns the make of the car having the greatest count. If there are no cars in the database, the method returns null. Under no circumstances may the method make changes to the database.
6. boolean updateRepairCost(int ticketNum, double newCost) (2 points)
Updates the cost for the repair with the given ticket number to newCost and then returns true. If no repair ticket with the given number exists in the database, the method returns false and makes no changes to the database.
7. boolean deleteRepair(int ticketNum) (2 points)
Deletes the repair with the given ticket number from the database and then returns true. If no repair ticket with the given number exists in the database, the method returns false and makes no changes to the database.
8. boolean deleteAllRepairsForCar(String VIN) (2 points) Deletes all repairs for the car with the given VIN from the database and then returns true. If no car with
the given VIN exists in the database, the method returns false and makes no changes to the database.
9. boolean deleteCarAndRepairs(String VIN) (3 points)
Deletes the car and all repairs for the car with the given VIN from the database and then returns true. If no car with the given VIN exists in the database, the method returns false and makes no changes to the database.

public class CarRepairShop {  

   public int addNewCar(String vin, String make, int year) {
       return -8;
   }
  
   public int addRepairTicket(String vin, double cost, String description) {
       return -7;
   }
  
   public double getRepairCost(int ticketNum) {
       return 23.4;
   }
  
   public double getTotalRepairCosts(String vin) {
       return 29.12;
   }

   public String getWorstCarMake() {
       return \"Go-Kart\";
   }
  
   public boolean updateRepairCost(int ticketNum, double newCost) {
       return false;
   }
  
   public boolean deleteRepair(int ticketNum) {
       return false;
   }
  
   public boolean deleteAllRepairsForCar(String VIN) {
       return false;
   }
  
   public boolean deleteCarAndRepairs(String VIN) {
       return false;
   }
}

Assignment Objectives By the end of this assignment you should be able to design, code, run and test original Java programs featuring arravs of obiects. Special Instructions For this assignment and for most of the assignments for the remainder of the semester you will not be writing code that takes input from the keyboard or produces output with print statements. Rather, you will write original methods that take arguments and return values to the calling method (in this case, main). You will also no longer be including your own main methods in submitted work. Rather, for each assignment you will be provided with a driver class which contains the main method. Inside this main method vou will write code to test your method but you will not submit those tests for grading. For this assignment, the file containing the driver class is called Homework6Driver.iava.

Solution


class Cars{
public String vin;
public String make;
public int year;
public Cars(String _vin, String _make, int _year){
vin = _vin;
make = _make;
year = _year;

}
}

class Repair_ticket{
  
public String vin;
public double cost;
public String description;
public int ticketNum;

public Repair_ticket(String _vin, double _cost, String _description, int _ticketNum){
vin = _vin;
cost = _cost;
description = _description;
ticketNum = _ticketNum;

}
}
public class CarRepairShop {

public int num_cars;
public int max_tickets;
public int current_ticket;
public int max_cars;
public Cars[] car_array;
public Repair_ticket[] repair_ticket_array;

public CarRepairShop(){
num_cars = 0;
max_cars = 10;
max_tickets = 10;
current_ticket = 0;

}
public int addNewCar(String vin, String make, int year) {

/*
Adds a new car to the database with the provided VIN,
make (e.g., Ford, Honda, Hyundai, etc.) and year of manufacture.
If a car with the given VIN already exists in the database,
the method returns 1 and makes no changes to the database.
Otherwise, the method returns the number of cars in the database
after adding this new car.
*/
for (int i = 0; i < num_cars ; i++ ) {
if(car_array[i].vin.equals(vin)){
return -1;
}
}
Cars car = new Cars(vin,make,year);
car_array[num_cars] = car;
num_cars +=1;
return num_cars;
}
  
public int addRepairTicket(String vin, double cost, String description) {
/*
Adds a new repair ticket to the database for the car with the provided VIN,
repair cost and repair description. If no car with the given VIN exists in
the database, the method returns 1 and makes no changes to the database.
Otherwise, the method returns the repair ticket number
*/

for (int i = 0; i < num_cars ; i++ ) {
if(car_array[i].vin.equals(vin)){

repair_ticket_array[current_ticket] = new Repair_ticket(vin, cost, description,current_ticket+1);
current_ticket +=1;
return current_ticket;
  
}
}

return -1;
}
  
public double getRepairCost(int ticketNum) {
/*
Returns the cost of the repair associated with the provided repair
ticket number. If no repair ticket with the given number exists in the database,
the method returns 1.0. Under no circumstances may the method make changes
to the database.
*/
for (int i = 0; i < current_ticket ; i ++ ) {
if(repair_ticket_array[i].ticketNum == ticketNum){
return repair_ticket_array[i].cost;
}
}
return -1.0;

}
  
public double getTotalRepairCosts(String vin) {
/*
Returns the total of all repair costs for the car with the provided VIN. If no car with the given VIN exists in the database, the method returns 1.0. Under no circumstances may the method make changes to the database.
*/
double sum = 0.0;
boolean flag = false;
for (int i = 0; i < current_ticket ; i ++ ) {
if(repair_ticket_array[i] != null && repair_ticket_array[i].vin.equals(vin)){
sum += repair_ticket_array[i].cost;
flag = true;
}
}
if(!flag) return -1.0;
return sum;
}
public String getWorstCarMake() {
/*
Returns the make of car that had the greatest total number of repairs.
Note that the method does not return the sum of the costs.
Rather, it counts how many times each make of car was repaired and
returns the make of the car having the greatest count. If there are no cars in the
database, the method returns null
*/
String ans = null;
double maxi = 0.0;
for (int i = 0; i < num_cars ; i++ ) {
if(car_array[i]!= null){
if(maxi < getTotalRepairCosts(car_array[i].vin)){
ans = car_array[i].vin;
}
}
}

return ans;
}
  
public boolean updateRepairCost(int ticketNum, double newCost) {
/*
Updates the cost for the repair with the given ticket number to newCost
and then returns true. If no repair ticket with the given number exists
in the database
*/
for (int i = 0; i < current_ticket ; i ++ ) {
if(repair_ticket_array[i] != null && repair_ticket_array[i].ticketNum == ticketNum){
repair_ticket_array[i].cost = newCost;
return true;
}
}

return false;
}
  
public boolean deleteRepair(int ticketNum) {
/*
Deletes the repair with the given ticket number from the database and then
returns true. If no repair ticket with the given number exists in the database,
the method returns false and makes no changes to the database.
*/

for (int i = 0; i < current_ticket ; i ++ ) {
if(repair_ticket_array[i] != null && repair_ticket_array[i].ticketNum == ticketNum){
repair_ticket_array[i] = null;
return true;
}
}

return false;

}
  
public boolean deleteAllRepairsForCar(String VIN) {
boolean flag = false;
for (int i = 0; i < current_ticket ; i ++ ) {
if(repair_ticket_array[i]!= null && repair_ticket_array[i].vin.equals(VIN) ) {
repair_ticket_array[i] = null;
flag = true;

}
}

return flag;
}
  
public boolean deleteCarAndRepairs(String VIN) {

for (int i = 0; i < current_ticket ; i ++ ) {
if(repair_ticket_array[i]!= null && repair_ticket_array[i].vin.equals(VIN) ) {
repair_ticket_array[i] = null;
  

}
}
boolean flag = false;
for (int i = 0; i < num_cars ; i++ ) {
if(car_array[i]!= null && car_array[i].vin.equals(VIN)){
car_array[i] = null;
flag = true;
}
}

return flag;
}

  
}

Assignment Objectives By the end of this assignment you should be able to design, code, run and test original Java programs featuring arrays of objects. Special
Assignment Objectives By the end of this assignment you should be able to design, code, run and test original Java programs featuring arrays of objects. Special
Assignment Objectives By the end of this assignment you should be able to design, code, run and test original Java programs featuring arrays of objects. Special
Assignment Objectives By the end of this assignment you should be able to design, code, run and test original Java programs featuring arrays of objects. Special
Assignment Objectives By the end of this assignment you should be able to design, code, run and test original Java programs featuring arrays of objects. Special
Assignment Objectives By the end of this assignment you should be able to design, code, run and test original Java programs featuring arrays of objects. Special

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site