Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the code in Java? Use a car as an object. One of the main purposes of th

ID: 3876553 • Letter: W

Question

What is the code in Java? Use a car as an object.

One of the main purposes of this assignment is to review and refresh many of the concepts covered in CSIS-1400 It also is an opportunity to demonstrate that you understood how to use doc comments and how to create jar files. Learning Objectives: Design and implement a class access class members of another class use an ArrayList use a static field "read user input from keyboard " provide user choices with a menu use repetition statements use selection statements override toString create a jar file that includes the Java source code "use doc comments to provide useful documentation for your code Description: In this assignment l encourage you to work with a partner so you can help each other refresh concepts that have beern covered in CSIS-1400. It is important to be responsive and that each partner contributes his/her fair share. If you have concerns about your partner bring it up as early as possible. First try to resolve the issue with your partner. If that is difficult talk to your instructure Each code file should include a comment on top that lists both students and the name of the assignment. Together write a program that keeps track of a list of items and that provides the user with a menu that allows the user to add, remove, list items, etc. For more details read the instructions belovw Instructions: Decide which items you would like to store in the list. (e.g. books, bikes, gemstones, etc.) It can by any thing but not cars (I used that for the example) and not people Create a class that represents the item you chose Here are some requirements your class needs to fulfill It can not be cars or people (see above) The class needs to have at least 3 attributes you are keeping track of (e.g. year, make, model) It needs to have two additional fields: o a unique id that cannot be changed once created (like a primary key in a database) o a static count that is used to initialize the id with a unique number Notice: At this point, we have a total of at least 5 attributes It needs a parameterized constructor It allows the user to provide values for all the attributes you are keeping track of but not for the id nor for the count. (in our case that would be 3 parameters: year, make, and model) The constructor creates a unique id e.g. an 8 digit number for each item based on the static field count. (e.g. 12345678+count++; In this example the smallest id would be 12345678) It needs a getter for each of the fields except for the static count (in our case that would be 4 getters) The static count should not be exposed to another class. It is only used to initialize the unique id in the

Explanation / Answer

Book.java

public class Book {

//Declaring static variable

private static int count = 12345671;

//Declaring instance variables

private int id;

private String name;

private double price;

private int year;

private int publishedYear;

//Parameterized constructor

public Book(String name, double price,int year) {

this.id = count++;

this.name = name;

this.price = price;

this.publishedYear=year;

}

// getters and setters

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public double getPrice() {

return price;

}

public void setPrice(double price) {

this.price = price;

}

public int getPublishedYear() {

return publishedYear;

}

public void setPublishedYear(int publishedYear) {

this.publishedYear = publishedYear;

}

//toString method is used to display the contents of an object inside it

@Override

public String toString() {

return name + " $" + price +" "+ year +" Id:" + id;

}

}

__________________

Test.java

import java.util.ArrayList;
import java.util.Scanner;

import com.cl.classes.Y;

public class Test {

public static void main(String[] args) {
// Declaring variables
String name;
double price;
int choice, year, id;

/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);

//Creating an ArrayList which holds Book class objects
ArrayList < Book > library = new ArrayList < Book > ();
Book b1 = new Book("The Man Without Qualities", 45.00, 2001);
Book b2 = new Book("A Thousand Splendid Suns ", 45.00, 2003);
Book b3 = new Book("Me Talk Pretty One Day ", 24.00, 2010);
Book b4 = new Book("Where the Wild Things Are ", 32.00, 2010);

//adding books to the library
library.add(b1);
library.add(b2);
library.add(b3);
library.add(b4);

/* This while loop continues to execute
* until the user enters a valid choice
*/
while (true) {
//displaying the menu
System.out.println(" :: Menu ::");
System.out.println("1.Display all items");
System.out.println("2.Add an item");
System.out.println("3.Find an item");
System.out.println("4.Delete an item");
System.out.println("5.Number of items in list");
System.out.println("6.Exit");
//getting the choice entered by the user
System.out.print(" Enter your selection :");
choice = sc.nextInt();
//Based on the user choice the corresponding case will be executed
switch (choice) {
case 1:
{
for (int i = 0; i < library.size(); i++) {
System.out.println(library.get(i));
}
continue;
}
case 2:
{
sc.nextLine();
System.out.print("Name :");
name = sc.nextLine();
System.out.print("Price :");
price = sc.nextDouble();
System.out.print("Year :");
year = sc.nextInt();

Book b = new Book(name, price, year);
library.add(b);

continue;
}
case 3:
{
int flag = 0;
System.out.print("Id:");
id = sc.nextInt();
for (int i = 0; i < library.size(); i++) {
if (library.get(i).getId() == id) {
System.out.println(library.get(i));
flag++;
}
}
if (flag == 0) {
System.out.println("** Book Not Found **");
}
continue;
}
case 4:
{
int flag = 0;
System.out.print("Id:");
id = sc.nextInt();
for (int i = 0; i < library.size(); i++) {
if (library.get(i).getId() == id) {
System.out.println(library.get(i) + " has been deleted.");
library.remove(i);
flag++;
}
}
if (flag == 0) {
System.out.println("** Book Not Found **");
}
continue;
}
case 5:
{
System.out.println("Number of Books :" + library.size());
continue;
}
case 6:
{

break;
}
default:
{
System.out.println("** Invalid Selection **");
continue;
}

}
break;

}

}

}

_________________

Output:


:: Menu ::
1.Display all items
2.Add an item
3.Find an item
4.Delete an item
5.Number of items in list
6.Exit

Enter your selection :1
The Man Without Qualities $45.0 0 Id:12345671
A Thousand Splendid Suns $45.0 0 Id:12345672
Me Talk Pretty One Day $24.0 0 Id:12345673
Where the Wild Things Are $32.0 0 Id:12345674

:: Menu ::
1.Display all items
2.Add an item
3.Find an item
4.Delete an item
5.Number of items in list
6.Exit

Enter your selection :2
Name :I Am America
Price :56
Year :2015

:: Menu ::
1.Display all items
2.Add an item
3.Find an item
4.Delete an item
5.Number of items in list
6.Exit

Enter your selection :1
The Man Without Qualities $45.0 0 Id:12345671
A Thousand Splendid Suns $45.0 0 Id:12345672
Me Talk Pretty One Day $24.0 0 Id:12345673
Where the Wild Things Are $32.0 0 Id:12345674
I Am America $56.0 0 Id:12345675

:: Menu ::
1.Display all items
2.Add an item
3.Find an item
4.Delete an item
5.Number of items in list
6.Exit

Enter your selection :3
Id:12345671
The Man Without Qualities $45.0 0 Id:12345671

:: Menu ::
1.Display all items
2.Add an item
3.Find an item
4.Delete an item
5.Number of items in list
6.Exit

Enter your selection :4
Id:12345672
A Thousand Splendid Suns $45.0 0 Id:12345672 has been deleted.

:: Menu ::
1.Display all items
2.Add an item
3.Find an item
4.Delete an item
5.Number of items in list
6.Exit

Enter your selection :5
Number of Books :4

:: Menu ::
1.Display all items
2.Add an item
3.Find an item
4.Delete an item
5.Number of items in list
6.Exit

Enter your selection :6

_______________Could you plz rate me well.Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote