Question

Wolfies Car Repair Shop For this assignment you will be completing a program that manages cars and car repairs at Wolfies C

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Working code implemented in Java and appropriate comments provided for better understanding:

Here I am attaching code for these files:

  • CarRepairShop.java
  • Ticket.java
  • Car.java
  • Homework6Driver.java

Source code for CarRepairShop.java:

public class CarRepairShop {
//declaring variables
private int carsCount = 0;
private int tickCount = 0;
private Car[] vehicles = new Car[carsCount + 1];
private Ticket[] tickets = new Ticket[tickCount + 1];

public int addNewCar(String vin, String make, int year) {//we can add car by taking VIN, make and year
int i;
Car[] t = new Car[vehicles.length + 1];
for (i = 0; i<vehicles.length; i++) {
Car car = vehicles[i];
if (car != null) {
t[i] = new Car(car);
}
}
String VIN;
for (i = 0; i<vehicles.length; i++) {
if (vehicles[i] != null) {
VIN = vehicles[i].getVin();
if (VIN.equals(vin)) {
return -1;
}
}
}
t[carsCount] = new Car(vin, make, year);
carsCount++;
vehicles = new Car[carsCount + 1];
for (i = 0; i<vehicles.length; i++) {
Car car = t[i];
if (car != null) {
vehicles[i] = new Car(car);
}
}
return carsCount;
}
public int addRepairTicket(String vin, double cost, String description) {//we can add repairticket by taking vin, cost and description
int i, tempCount = 0;
Ticket[] t = new Ticket[tickets.length + 1];
for (i = 0; i<tickets.length; i++) {
Ticket ticket = tickets[i];
if (ticket != null) {
t[i] = new Ticket(ticket);
}
}
String VIN;
for (i = 0; i<vehicles.length; i++) {
if (vehicles[i] != null) {
VIN = vehicles[i].getVin();
if (VIN.equals(vin)) {
tempCount++;
}
}
}
if (tempCount==0) return -1;
t[tickCount] = new Ticket(vin, cost, description);
tickCount++;
tickets = new Ticket[tickCount + 1];
for (i = 0; i<tickets.length; i++) {
Ticket ticket = t[i];
if (ticket != null) {
tickets[i] = new Ticket(ticket);
}
}
return tickCount;
}
public double getRepairCost(int ticketNum) {//we can get cost of repair using ticket id
if (ticketNum > tickets.length) return -1;
if (ticketNum <= 0) return -1;
if (tickets[ticketNum-1] != null) {
double cost = tickets[ticketNum - 1].getCost();
return cost;
}
else return -1;
}
public double getTotalRepairCosts(String vin) {//we can get total cost of all repairs
int noCarCheck = 0, i;
for (i = 0; i<vehicles.length - 1; i++) {
if (vehicles[0] == null) {
if (vehicles[i].getVin().equals(vin)) {
noCarCheck++;
}
}
}
if (noCarCheck == 0) return -1;
double cost = 0;
for (i = 0; i<tickets.length - 1; i++) {
if (tickets[i] != null) {
if (tickets[i].getVin().equals(vin)) {
cost += tickets[i].getCost();
}
}
}
return cost;
}

public String getWorstCarMake() { //we can get worst car based on most tickets
int carCheck = 0, i, count = 0, j, tempCount;
String vin, element = "", tempElement, make = "";
String[] ticketArray = new String[tickets.length - 1];
for (i = 0; i<vehicles.length - 1; i++) {
if (vehicles[i] != null) carCheck++;
}
if (carCheck == 0) return null;
for (i = 0; i<tickets.length - 1; i++) {
if (tickets[i] != null) {
vin = tickets[i].getVin();
ticketArray[i] = vin;
}
}
for (i = 0; i<ticketArray.length; i++) {
tempElement = ticketArray[i];
tempCount = 0;
for (j = 0; j<ticketArray.length; j++) {
if (ticketArray[j].equals(tempElement)) tempCount++;
}
if (tempCount > count) {
element = tempElement;
count = tempCount;
}
}
for (i = 0; i<vehicles.length - 1; i++) {
if (vehicles[i] != null) {
String VIN = vehicles[i].getVin();
if (VIN.equals(element)) {
make = vehicles[i].getMake();
break;
}
}
}
return make;
}

public boolean updateRepairCost(int ticketNum, double newCost) {//we can update cost of repair using ticket id
if (ticketNum > tickets.length) return false;
if (ticketNum <= 0) return false;
if (tickets[ticketNum - 1] != null) {
tickets[ticketNum - 1].setCost(newCost);
return true;
}
else return false;
}

public boolean deleteRepair(int ticketNum) { //we can delete car using ticket id
if (ticketNum > tickets.length) return false;
if (ticketNum <= 0) return false;
if (tickets[ticketNum - 1] != null) {
tickets[ticketNum - 1] = null;
return true;
}
else return false;
}

public boolean deleteAllRepairsForCar(String VIN) { //we can remove all repairs from car
int noCarCheck = 0, i;
for (i = 0; i<vehicles.length - 1; i++) {
if (vehicles[0] == null) {
if (vehicles[i].getVin().equals(VIN)) {
noCarCheck++;
}
}
}
if (noCarCheck == 0) return false;
for (i = 0; i<tickets.length - 1; i++) {
if (tickets[i] != null) {
if (tickets[i].getVin().equals(VIN)) {
tickets[i] = null;
}
}
}
return true;
}

public boolean deleteCarAndRepairs(String VIN) { //we can remove car and its repairs
int noCarCheck = 0, i;
for (i = 0; i<vehicles.length - 1; i++) {
if (vehicles[i] != null) {
if (vehicles[i].getVin().equals(VIN)) {
noCarCheck++;
}
}
}
if (noCarCheck == 0) return false;
for (i = 0; i<vehicles.length - 1; i++) {
if (vehicles[i] != null) {
if (vehicles[i].getVin().equals(VIN)) {
vehicles[i] = null;
}
}
}
for (i = 0; i<tickets.length - 1; i++) {
if (tickets[i] != null) {
if (tickets[i].getVin().equals(VIN)) {
tickets[i] = null;
}
}
}
return true;
}
}

Code Screenshots:

Source code for Ticket.java:

public class Ticket {
//declaring variables
private String vin;
private double cost;
private String description;

public Ticket(String vin, double cost, String description) { //default constructor with parameters
this.vin = vin;
this.cost = cost;
this.description = description;
}

public void setCost(double newCost) { //we can set new cost of ticket
cost = newCost;
}

public String getVin() { //we can get VIN number using this function
return vin;
}

public double getCost() { //we can get cost of ticket
return cost;
}

public String getDescription() { //we can get description of ticket
return description;
}

public Ticket(Ticket ticket) {
this(ticket.getVin(), ticket.getCost(), ticket.getDescription());
}

}

Code Screenshots:

Source code for Car.java:

public class Car { //Car class
//declaring variables
private String vin;
private String make;
private int year;

public Car(String vin, String make, int year) { //default constructor with parameters
this.vin = vin;
this.make = make;
this.year = year;
}

public String getVin() { //we can get vin number of car
return vin;
}

public String getMake() { //we can get make of car
return make;
}

public int getYear() { //we can get year of car released
return year;
}

public Car(Car car) {
this(car.getVin(), car.getMake(), car.getYear());
}
}

Code Screenshots:

Source code for Homework6Driver.java:

import java.util.Scanner;

public class Homework6Driver {

private static Scanner input = new Scanner(System.in);
private static CarRepairShop shop = new CarRepairShop();

public static void main(String[] args) {
int entry;
String[] entries = {
"Add a new car to the database",
"Record repair ticket ID for car",
"Get repair cost by ticket ID",
"Get car's total repair costs using VIN ID",
"Get car having highest total number of repairs",
"Update repair cost by ticket ID",
"Delete a repair ticket by ticket ID",
"Delete all tickets of repairs using VIN ID",
"Delete car and its repairs using VIN ID",
"Exit Program"
};

System.out.println("Welcome to Car Repair Shop!");
do {
System.out.println("\nCar Repair Shop Main Menu");
System.out.println("----------------------------------");
  
for (int i = 0; i < entries.length; i++) {
System.out.println((i < entries.length-1 ? i+1 : 0) + ". " + entries[i]);
}

System.out.print("Make your entry: ");
entry = input.nextInt();

switch (entry) {
case 1: Driver_addNewCar(); //add car to database
break;
case 2: Driver_addRepairTicket(); //generate ticket for repair
break;
case 3: Driver_getRepairCost(); //we can get cost of repair
break;
case 4: Driver_getTotalRepairCosts(); //get cost of total repairs
break;
case 5: Driver_getWorstCarMake(); //gets car with more repairs
break;
case 6: Driver_updateRepairCost(); //update cost of repair
break;
case 7: Driver_deleteRepair(); //remove ticket of repair
break;
case 8: Driver_deleteAllRepairsForCar();// removes all repairs
break;
case 9: Driver_deleteCarAndRepairs();// remove car and its repairs
break;
case 0: System.exit(0); //exit
default:
System.out.println("Invalid entry. Try again.");
}

} while (entry != 0);

input.close();
}

public static void Driver_addNewCar() {
String vin, make;
int year, carNumber;
input.nextLine();
System.out.print("Enter VIN of Car: ");
vin = input.nextLine();
System.out.print("Enter year of Car: ");
year = input.nextInt();
input.nextLine();
System.out.print("Enter make of Car: ");
make = input.nextLine();

carNumber = shop.addNewCar(vin, make, year);
if (carNumber != -1)
System.out.println("Car #" + carNumber + " successfully added.");
else
System.out.println("Error: Entered car was already exists in database.");
}
public static void Driver_addRepairTicket() {
String vin, desc;
int ticketNumber;
double cost;
input.nextLine();
System.out.print("Enter VIN ID of Car: ");
vin = input.nextLine();
System.out.print("Enter the cost of repair: ");
cost = input.nextDouble();
input.nextLine();
System.out.print("Enter the repair description: ");// description problem
desc = input.nextLine();
ticketNumber = shop.addRepairTicket(vin, cost, desc);
if (ticketNumber != -1)
System.out.println("Repair ticket #" + ticketNumber + " successfully added.");
else
System.out.println("Invalid: can't record repair in database.");
}
public static void Driver_getRepairCost() {
int ticketNumber;
double cost;
System.out.print("Enter repair ticket ID: ");
ticketNumber = input.nextInt();
cost = shop.getRepairCost(ticketNumber);
if (cost != -1)
System.out.printf("Repair ticket #" + ticketNumber + " had a cost of $%.2f\n", cost);
else
System.out.println("Invalid ticket number entered.");
}
public static void Driver_getTotalRepairCosts() {
String vin;
double total;
input.nextLine();
System.out.print("Enter VIN: ");
vin = input.nextLine();
total = shop.getTotalRepairCosts(vin);
if (total != -1)
System.out.printf("Total costs to repair car with VIN " + vin + " was $%.2f\n", total);
else
System.out.println("Invalid VIN ID entered");
}
public static void Driver_getWorstCarMake() {
String worstCarMake = shop.getWorstCarMake();
if (worstCarMake == null)
System.out.println("No tickets in database.");
else
System.out.println("The car make with most repairs is: " + worstCarMake);
}

public static void Driver_updateRepairCost() {
int ticketNumber;
boolean success;
double updatedCost;
System.out.print("Enter repair ticket number: ");
ticketNumber = input.nextInt();
System.out.print("Enter new cost of repair: ");
updatedCost = input.nextDouble();
success = shop.updateRepairCost(ticketNumber, updatedCost);
if (success)
System.out.printf("Repair ticket #" + ticketNumber + " updated cost of $%.2f\n", updatedCost);
else
System.out.println("Invalid ticket number entered.");
}
public static void Driver_deleteRepair() {
int ticketNumber;
boolean success;
System.out.print("Enter repair ticket ID: ");
ticketNumber = input.nextInt();
success = shop.deleteRepair(ticketNumber);
if (success)
System.out.println("Repair ticket #" + ticketNumber + " deleted.");
else
System.out.println("Invalid ticket number entered.");
}
public static void Driver_deleteAllRepairsForCar() {
String vin;
boolean success;
input.nextLine();
System.out.print("Enter VIN: ");
vin = input.nextLine();
success = shop.deleteAllRepairsForCar(vin);
if (success)
System.out.println("Deleted repairs for car with VIN " + vin + " from database.");
else
System.out.println("Invalid VIN ID entered.");
}
public static void Driver_deleteCarAndRepairs() {
String vin;
boolean success;
input.nextLine();
System.out.print("Enter VIN ID: ");
vin = input.nextLine();
success = shop.deleteCarAndRepairs(vin);
if (success)
System.out.println("Deleted car with VIN ID" + vin + " from database.");
else
System.out.println("Invalid VIN ID entered.");
}
}

Code Screenshots:

Output Screenshots:

Hope it helps, if you like the answer give it a thumbs up. Thank you.

Add a comment
Know the answer?
Add Answer to:
Wolfie's Car Repair Shop For this assignment you will be completing a program that manages cars...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For Programming Assignment 3 you will be creating a program to manage cars in a dealership....

    For Programming Assignment 3 you will be creating a program to manage cars in a dealership. This will again be a menu driven system. The following is your menu: 1. Display Inventory 2. Add a vehicle 3. Update a vehicle 4. Delete a vehicle 5. Sort inventory by VIN 6. Search inventory by Model 7. Read inventory from file 8. Write inventory to file and exit our program will be class based with the following UML representing the classes: Dealer...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from...

    Programming Assignment #2 (Arrays) I. The Assignment This assignment is to take your Garage class from the previous assignment and modify it so that it uses an array of Car objects as the principal data structure instead of an ArrayList-of-Car. This is an example of the OOP principle of information hiding as your Car and test classes will not have to be modified at all. Unless you broke encapsulationon the previous assignment, that is   II. Specifications Specifications for all 3...

  • Use BlueJ to write a program that reads a sequence of data for several car objects...

    Use BlueJ to write a program that reads a sequence of data for several car objects from an input file. It stores the data in an ArrayList<Car> list . Program should work for input file containing info for any number of cars. (You should not assume that it will always be seven lines in the input file). Use notepad to create input file "inData.txt". File should be stored in the same folder where all files from BlueJ for this program...

  • The ABC Car Service & Repair Centers are owned by the SILENT car dealer; ABC services...

    The ABC Car Service & Repair Centers are owned by the SILENT car dealer; ABC services and repairs only SILENT cars. Three ABC Car Service & Repair Centers provide service and repair for the entire state. Each of the three centers is independently managed and operated by a shop manager, a receptionist, and at least eight mechanics. Each center maintains a fully stocked parts inventory. Each center also maintains a manual file system in which each car’s maintenance history is...

  • Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one me...

    Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu...

  • LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT...

    LAB 7-Movie List Program Goali Your assignment is to write a C++program to implement the ADT List by creating a list of movies. This assignment will help you practice: multiple file programming, classes, pablic and private methods, dynamie memory, constructors and destructors, arrays and files Implementation the required classes This lab assignment gives you the opportunity to practice creating classes and using dynamic memory in one of There are two classes to implement: Movie and MovieList. As you can see...

  • 3. You own a car towing business and car repair shop. Your business includes three tow trucks, and numerous hydraulics and lots of tools and car parts for working on cars. You do not own the real...

    3. You own a car towing business and car repair shop. Your business includes three tow trucks, and numerous hydraulics and lots of tools and car parts for working on cars. You do not own the real property or buildings in which you run the business, however, you have a five-year lease for the land and buildings. You have a large following in the community and have established lots of good will for your reputable business which makes significant yearly...

  • I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline...

    I need an OUTLINE ONLY (pseudocode/comments). DO NOT DO THE PROGRAMMING ASSIGNMENT. Part I: PA3 Outline (10 points). Create an outline in comments/psuedocode for the programming assignment below. Place your comments in the appropriate files: main.cpp, functions.h, dealer.cpp, dealer.h, dealer.cpp (as noted below). Place into a file folder named LastnamePA3, the zip the content and hand in a zip file to Canvas. Part II: PA3: Car Dealership (40 points) For Programming Assignment 3 you will be creating a program to...

  • CSC 143 Weekly Exercise: Satisfying Slurps For this assignment, imagine you have been hired to create...

    CSC 143 Weekly Exercise: Satisfying Slurps For this assignment, imagine you have been hired to create a program to manage drink orders at a local coffee shop. The coffee shop is known for changing their menu frequently, and people come to the shop in anticipation of getting unusual, but delicious, drinks. Since the drinks change so frequently, your program will need to have the flexibility to handle this. Accordingly, you decide to create classes that can be used to price...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT