For this assignment you will be creating an array of objects or a list of objects of car parts based on user input.
1. Create a Parts class with the following items
a. Properties for PartNum, Part Name, Part Description, and Cost
b. Must have a constructor
2. In the main you will need accomplish the following:
a. Ask the user how many objects they wish to enter
b. Create an array of parts objects
c. Loop appropriately to collect the data needed to populate the objects in the array
d. Next you will do the following:
i. Give the user a menu of all parts
ii. Ask the user which part they would like to view data on
iii. Create a method to print out the object selected by user values.
################# Parts.java ####################
/**
* The Class Parts.
*/
public class Parts {
/** The part num. */
private int partNum;
/** The part name. */
private String partName;
/** The part description. */
private String partDescription;
/** The cost. */
private double cost;
/**
* Instantiates a new parts.
*
* @param partNum the part num
* @param partName the part name
* @param partDescription the part description
* @param cost the cost
*/
public Parts(int partNum, String partName, String
partDescription, double cost) {
this.partNum = partNum;
this.partName = partName;
this.partDescription =
partDescription;
this.cost = cost;
}
/**
* Gets the part num.
*
* @return the part num
*/
public int getPartNum() {
return partNum;
}
/**
* Gets the part name.
*
* @return the part name
*/
public String getPartName() {
return partName;
}
/**
* Gets the part description.
*
* @return the part description
*/
public String getPartDescription() {
return partDescription;
}
/**
* Gets the cost.
*
* @return the cost
*/
public double getCost() {
return cost;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
return "Parts [partNum=" + partNum
+ ", " + (partName != null ? "partName=" + partName + ", " :
"")
+ (partDescription != null ? "partDescription="
+ partDescription + ", " : "") + "cost=" + cost + "]";
}
}
############# CarPartShop.java ###############
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class CarPartShop {
/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
try {
// Because of
limitation of scanner. I'm using Buffer reader.
BufferedReader
sc = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter how many car parts you need to add:
");
int numOfParts =
Integer.parseInt(sc.readLine());
Parts[] parts =
new Parts[numOfParts];
for (int i = 0;
i < numOfParts; i++) {
System.out.print("Enter part number: ");
int partNum =
Integer.parseInt(sc.readLine());
System.out.print("Enter part name: ");
String partName = sc.readLine();
System.out.println("Enter description:
");
String partDesc = sc.readLine();
System.out.println("Enter cost: ");
double cost =
Double.parseDouble(sc.readLine());
parts[i] = new Parts(partNum, partName,
partDesc, cost);
}
// showing
menu.
int partNum =
showMenu(parts, sc);
//showing part
details
for (Parts p :
parts) {
if (p.getPartNum() == partNum) {
System.out.println("Part
Number: " + p.getPartNum());
System.out.println("Part
Name: " + p.getPartName());
System.out.println("Part
Description: " + p.getPartDescription());
System.out.println("Cost: $"
+ p.getCost());
}
}
} catch (Exception e) {
// TODO: handle
exception
}
}
/**
* Show menu.
*
* @param parts the parts
* @param sc the sc
* @return the int
* @throws NumberFormatException the number format
exception
* @throws IOException Signals that an I/O exception
has occurred.
*/
private static int showMenu(Parts[] parts,
BufferedReader sc) throws NumberFormatException, IOException
{
for (Parts p : parts) {
System.out.println("Part Number: " + p.getPartNum() + " Name: " +
p.getPartName());
}
System.out.println("Enter part
number to show details: ");
return
Integer.parseInt(sc.readLine());
}
}

For this assignment you will be creating an array of objects or a list of objects...
JAVA program For this project you are to create an array of objects of your choice using java your Driver Class, Object Classes should all be named appropriately depending on what Classes and Objects you decide to create for this assignment. This project must give the user the ability to view and to change the elements of the array. Print your results (output) as a clear and informative statement. Your output should also include an explanation of what your program...
JAVA I. Using the Event Class created previously, create an array of objects; II. Demonstrate passing array reference to a method; III. Demonstrate creating array of objects that prints out only x 0.0 for all objects. PROJECT 5C - ARRAYS Create a new file called " EventArray5C". There are some "challenging" directions in this project. . 1.Prepare a document box (tell me that task(s) the application is to accomplish, how it will accomplish the tasks, the author of...
C# Visual Studios HelloWorld For this assignment, you'll work with first creating an array and populating it's values. Then, we'll use the values in the array to calculate the average. Since it's common for an average to result in numbers with decimal points, the array you create should be of type double[]. This program will need to use dynamic input from the user so perform the following steps: Ask the user how many numbers need to be added. Use this...
In C# you will be creating a car dealership app that will contain an Automobile class and three subclasses – Car, Truck, SUV. The properties for Automobile are as follows Base cost Model Make Year The Car will inherit Automobile and include the following: Tax break for better fuel option this calculation will be 2% The Truck will inherit Automobile and include the following: Incentive of $2000 off the cost The SUV will inherit Automobile and include the following: Extra...
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...
The purpose of this assignment is to get experience with an
array, do while loop and read and write file operations.
Your goal is to create a program that reads the exam.txt file
with 10 scores. After that, the user can select from a 4 choice
menu that handles the user’s choices as described in the details
below. The program should display the menu until the user selects
the menu option quit.
The project requirements:
It is an important part...
NOTE – You may use C++ - but you MAY NOT use #include <string> The goal is to use C-Style character array based strings. You will put all of your code in this file. You may use any technique we have learned so far. Specifications: This assignment is split into several parts. The goal is to get you used to working with C/C++ run-time arrays and strings. Part 0 – Create a Menu You should create a menu that gives...
Description For this assignment, you will maintain an array of bank accounts. You will declare a struct type called bankAcct and have an array of bankAcct with maximum size of 20, the members of the struct are shown below struct bankAcct { string first , last ; double amount ; long acctNo ; short pin ; }; Each member is described below • string first stores the user’s first name • string last stores the user’s last name • double...
Use your Car class from the previous Programming Assignment. For this assignment, create a new class that represents a Used Car Dealership. Your Java program will simulate an inventory system for the dealership, where the employees can manage the car information. Start by creating an array of 10 cars, with an "ID" of 0 through 9, and use the default constructor to create each car. For example, the third car in an array called cars would have ID 2. You...
The goal of this assignment is to give you some experience building a program that uses objects. You must work in teams of 2 to complete this assignment. You will use the BankAccount class you created in Lab 3 to create a banking program. The program must display a menu to the user to allow the user to select a transaction like deposit, withdraw, transfer, create a bank account, and quit the program. The program should allow a user to...