Question

In: Computer Science

Project Description In this project you will build a car configuration application in six units. Each...

Project Description

In this project you will build a car configuration application in six units. Each unit provides learning opportunities in Object Oriented Design. You are expected to document these lessons and apply them in the next unit. You will notice that the design guidance will taper off as you progress through units in Project 1. You will be expected to design on your own.

Project 1 - Unit 1

In this project you will build a Car Configuration Application using Java. In this unit you will develop a “reference” base object model, read a text file to build the reference base object model and archive it using Serialization.

I would like you to start with a proof of concept – so we will first build the underlying object using normal Java Classes and Inner Classes.

For our proof of concept please consider the following requirements:

We will build Ford's Focus Wagon ZTW model with these options:

  • ● Color - Fort Knox Gold Clearcoat Metallic, Liquid Grey Clearcoat Metallic, Infra-Red Clearcoat, Grabber Green Clearcoat Metallic, Sangria Red Clearcoat Metallic, French Blue Clearcoat Metallic, Twilight Blue Clearcoat Metallic, CD Silver Clearcoat Metallic, Pitch Black Clearcoat, Cloud 9 White Clearcoat

  • ● Transmission - automatic or manual

  • ● Brakes/Traction Control - Standard, ABS, or ABS with Advance Trac

  • ● Side Impact Airbags - present or not present

  • ● Power Moonroof - present or not present
    Configuration options and cost data:

Base Price

$18,445

Color

No additional cost

Transmission

0 for automatic, $­815 for standard (this is a "negative option")

Brakes/Traction Control

$0 for standard, $400 for ABS, $1625 for ABS with Advance Trac

Side Impact Air Bags

$0 for none, $350 if selected

Power Moonroof

$0 for none, $595 if selected

Your Deliverable:

Design and code classes for these requirements and write a driver program to instantiate a Ford Wagon ZTW object and write it to a file. Test your code with a couple of instances of Forward Wagon ZTW.

Solutions

Expert Solution

package file;

import java.io.*;
import java.util.*;

// Defines class CarConfiguration implements Serializable interface
class CarConfiguration implements Serializable
{
   // Instance variables to store car configuration information
   String carName;
   double basePrice;
   String color;
   String transmission;
   String brakesOrTractionControl;
   String sideImpactAirbags;
   String powerMoonroof;
  
   // Instance variables to store calculated cost
   double transmissionCost;
   double brakesOrTractionControlCost;
   double sideImpactAirbagsCost;
   double powerMoonroofCost;
   double finalCost;
  
   // Default constructor to assign default values to instance variables
   CarConfiguration()
   {
       basePrice = 0.0;
       carName = color = transmission = brakesOrTractionControl =
               sideImpactAirbags = powerMoonroof = null;
       transmissionCost = brakesOrTractionControlCost = sideImpactAirbagsCost =
       powerMoonroofCost = finalCost = 0.0;
   }// End of default constructor
  
   // Parameterized constructor to assign parameter values to instance variables
   CarConfiguration(double basePrice, String carName, String color,
           String transmission, String brakesOrTractionControl,
           String sideImpactAirbags, String powerMoonroof)
   {
       this.basePrice = basePrice;
       this.carName = carName;
       this.color = color;
       this.transmission = transmission;
       this.brakesOrTractionControl =brakesOrTractionControl;
       this.sideImpactAirbags = sideImpactAirbags;
       this.powerMoonroof = powerMoonroof;
   }// End of parameterized constructor
  
   // Overloads method to return car configuration information
   public String toString()
   {
       return "\n Base Price: $" + basePrice + "\n Car Name: " + carName +
               "\n Color: " + color +
               "\n Transmission: " + transmission +
               "\n Transmission Cost: $" + transmissionCost +
               "\n Brakes / Traction Control: " + brakesOrTractionControl +
               "\n Brakes / Traction Control Cost: $" + brakesOrTractionControlCost +
               "\n Side Impact Airbags: " + sideImpactAirbags +
               "\n Side Impact Airbags Cost: $" + sideImpactAirbagsCost +
               "\n Power Moonroof: " + powerMoonroof +
               "\n Power Moonroof Cost: $" + powerMoonroofCost +
               "\n Final Amount: $" + finalCost + "\n";
   }// End of method
}// End of class CarConfiguration

// Driver class definition
public class CarConfigurationApplication
{
   // Creates an array list to store CarConfiguration objects
   ArrayList<CarConfiguration> cars = new ArrayList<>();
  
   // Method to calculate each type cost and final amount
   void calculateCost()
   {
       // Loops till number of records       
       for(int c = 0; c < cars.size(); c++)
       {
           // Checks if transmission is automatic
           if(cars.get(c).transmission.equalsIgnoreCase("automatic"))
               // Assigns the amount 0.0
               cars.get(c).transmissionCost = 0.0;
          
           // Otherwise transmission is manual
           else
               // Assigns the amount 815.0
               cars.get(c).transmissionCost = 815.0;
          
           // Checks if brakes/tractionControl is standard
           if(cars.get(c).brakesOrTractionControl.equalsIgnoreCase("standard"))
               cars.get(c).brakesOrTractionControlCost = 0.0;
          
           // Otherwise checks if brakes/tractionControl is ABS
           else if(cars.get(c).brakesOrTractionControl.equalsIgnoreCase("ABS"))
               cars.get(c).brakesOrTractionControlCost = 400.0;
          
           // Otherwise brakes/tractionControl is ABS with Advance Trac
           else
               cars.get(c).brakesOrTractionControlCost = 1625.0;
          
           // Checks if side impact airbags is present
           if(cars.get(c).sideImpactAirbags.equalsIgnoreCase("present"))
               cars.get(c).sideImpactAirbagsCost = 350.0;
          
           // Otherwise side impact airbags is not present
           else
               cars.get(c).sideImpactAirbagsCost = 0.0;
          
           // Checks if power moonroof is present
           if(cars.get(c).powerMoonroof.equalsIgnoreCase("present"))
               cars.get(c).powerMoonroofCost = 595.0;
          
           // Otherwise power moonroof is not present
           else
               cars.get(c).powerMoonroofCost = 0.0;
          
           // Calculates final cost
           cars.get(c).finalCost = cars.get(c).basePrice +
                   cars.get(c).transmissionCost +
                   cars.get(c).brakesOrTractionControlCost +
                   cars.get(c).sideImpactAirbagsCost +
                   cars.get(c).powerMoonroofCost;
                  
       }// End of for loop
   }// End of method
  
   // Method to read records from file
   void readRecords()
   {
       // Scanner class object created for file
       Scanner readF = null;
      
       // try block begins
       try
       {          
           // Opens the file for reading
           // Scanner class constructor take File class object as parameter
           // File class constructor takes file name as parameter
           readF = new Scanner(new File("carConfig.txt"));
          
           // Loops till end of record
           // hasNextLine method returns true if any
           // data available in file
           while(readF.hasNextLine())
           {
               // Reads a record
               String record = readF.nextLine();
               // Split the record with comma delimiter
               String each[] = record.split(", ");
               // Creates an object using parameterized constructor
               // adds it to array list
               cars.add(new CarConfiguration(Double.parseDouble(each[0]),
                       each[1], each[2], each[3], each[4], each[5], each[6]));
           }// End of while loop              
       }// End of try block
                  
       // Catch block to handle FileNotFoundException exception
       catch(FileNotFoundException fe)
       {
           System.out.print("\n Unable to open the file for reading.");
       }// End of catch block
      
       // Calls the method to calculate cost
       calculateCost();
      
       // Closes the Scanner class object for file
       readF.close();
   }// End of method
  
   // Method to write records to file (serialize an Object)
   void writeFile()
   {         
       // try block begins
       try
       {
           // Creates an object of the class FileOutputStream to open the file
           FileOutputStream fileOutStr = new FileOutputStream("carConfigAmt.txt");
          
           // Creates an object of the class ObjectOutputStream to write object
           ObjectOutputStream outObj = new ObjectOutputStream(fileOutStr);
          
           // Calls the method to write array list objects
           outObj.writeObject(cars);
          
           // Close the object stream
           outObj.close();
           // Closer the file
           fileOutStr.close();
       }// End of try block
      
       // Catch block to handle FileNotFoundException
       catch(FileNotFoundException e)
       {
           e.printStackTrace();
       }// End of catch block
      
       // Catch block to handle IOException
       catch(IOException e)
       {
           e.printStackTrace();
       }// End of catch block
   }// End of method
  
   // Method to read records from file (deserialize an Object)
   void readFile()
   {
       // try block begins
       try
       {
           // Creates an object of the class FileInputStream to open the file
           FileInputStream fileInStr = new FileInputStream("carConfigAmt.txt");
          
           // Creates an object of the class ObjectInputStream to read object
           ObjectInputStream inObj = new ObjectInputStream(fileInStr);
          
           // Calls the method to read object and displays it
           System.out.println("Car Configuration: \n" +
                   inObj.readObject().toString());
          
           // Close the object stream
           inObj.close();
           // Closer the file
           fileInStr.close();
       }
       // End of try block
      
       // Catch block to handle ClassNotFoundException
       catch(ClassNotFoundException e)
       {
           e.printStackTrace();
       }// End of catch block
      
       // Catch block to handle FileNotFoundException
       catch(FileNotFoundException e)
       {
           e.printStackTrace();
       } // End of catch block
      
       // Catch block to handle IOException
       catch(IOException e)
       {
           e.printStackTrace();
       }// End of catch block
   }// End of method
  
   // main method definition
   public static void main(String []ss)
   {
       // Creates an object of class CarConfigurationApplication
       CarConfigurationApplication cca = new CarConfigurationApplication();
      
       // Calls the method to read records from file
       cca.readRecords();
       // Calls the method to write records with amount
       cca.writeFile();
       // Calls the method to read records from file and displays it
       cca.readFile();
   }// End of main method
}// End of driver class

Sample Output:

Car Configuration:
[
Base Price: $560000.0
Car Name: Ford Wagon ZTW
Color: Fort Knox Gold Clearcoat Metallic
Transmission: automatic
Transmission Cost: $0.0
Brakes / Traction Control: ABS
Brakes / Traction Control Cost: $400.0
Side Impact Airbags: present
Side Impact Airbags Cost: $350.0
Power Moonroof: present
Power Moonroof Cost: $595.0
Final Amount: $561345.0
,
Base Price: $890000.0
Car Name: Centro
Color: Liquid Grey Clearcoat Metallic
Transmission: manual
Transmission Cost: $815.0
Brakes / Traction Control: ABS with Advance Trac
Brakes / Traction Control Cost: $1625.0
Side Impact Airbags: not present
Side Impact Airbags Cost: $0.0
Power Moonroof: present
Power Moonroof Cost: $595.0
Final Amount: $893035.0
]

carConfig.txt file contents

560000.00, Ford Wagon ZTW, Fort Knox Gold Clearcoat Metallic, automatic, ABS, present, present
890000.00, Centro, Liquid Grey Clearcoat Metallic, manual, ABS with Advance Trac, not present, present


Related Solutions

Project Description In this project you will build a car configuration application in six units. Each...
Project Description In this project you will build a car configuration application in six units. Each unit provides learning opportunities in Object Oriented Design. You are expected to document these lessons and apply them in the next unit. You will notice that the design guidance will taper off as you progress through units in Project 1. You will be expected to design on your own. Project 1 - Unit 1 In this project you will build a Car Configuration Application...
Project Description In this project you will build a car configuration application in six units. Each...
Project Description In this project you will build a car configuration application in six units. Each unit provides learning opportunities in Object Oriented Design. You are expected to document these lessons and apply them in the next unit. You will notice that the design guidance will taper off as you progress through units in Project 1. You will be expected to design on your own. Project 1 - Unit 1 In this project you will build a Car Configuration Application...
Suppose you are responsible for a project to build an application that is going to collect...
Suppose you are responsible for a project to build an application that is going to collect all the training opportunities for any summer training program. The purpose of the application is to allow the user to search for the most suitable opportunity for him using different search criteria such as GPA and salary. How you would make a Risk Management plan for such a project? I want a Risk Management plan for this project. thanks.
Project Description The objective of this project is to design, simulate and build a speech filter....
Project Description The objective of this project is to design, simulate and build a speech filter. The design should operate on less that ±6 Volts DC. Please keep in mind that you should monitor the cost of the design components. Therefore you will need to determine the frequency band of speech and investigate low power options for the design. After reviewing the various tradeoffs which happens after design and simulations, you should then order the parts for the actual design....
The organization is a project to build a car manufacturing facility. The job for me is...
The organization is a project to build a car manufacturing facility. The job for me is just to set up the facility and deliver it to clients. As soon as my job is completed, the clients have started manufacturing the cars Context You are working as a project manager in your chosen case organisation and a senior manager has asked for your assistance with understanding and resolving two current problems (refer below). The senior manager has asked that you provide...
You would like to build a classifier for an Autism early detection application. Each data point...
You would like to build a classifier for an Autism early detection application. Each data point in the dataset represents a patient. Each patient is described by a set of attributes such as age, sex, ethnicity, communication and development figures, etc. You know from domain knowledge that autism is more prevalent in males than females. If the dataset you are using to build the classifier is noisy, contains redundant attributes and missing values. If you are considering a decision tree...
This week you have researched configuration management tools. As a project manager, what configuration management tool...
This week you have researched configuration management tools. As a project manager, what configuration management tool would you recommend using, and why?
Assess the six stages of BI application development and evaluate the primary activity of each.
Assess the six stages of BI application development and evaluate the primary activity of each.
3. If you are required to build Wind Turbine for industrial application, which factors will you...
3. If you are required to build Wind Turbine for industrial application, which factors will you consider? Hint: Approach the question through creative thinking.
Description: In this lab, you build an extended star network, in which the computers are connected...
Description: In this lab, you build an extended star network, in which the computers are connected in a physical star and a logical bus topology, and the computers form the outer arms of the extended star. The center of the extended star should be a device that creates one collision domain per port. Build the network with as much equipment as you have available, distributing computers evenly around the outer edges of the extended star. Draw the final topology and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT