Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.ArrayList; import java.util.List; class Guitar { String color; String brand; String model; double price; boolean isSecondHand; String warehouse; int stockNumber; public Guitar ( String

import java.util.ArrayList;
import java.util.List;
class Guitar {
String color;
String brand;
String model;
double price;
boolean isSecondHand;
String warehouse;
int stockNumber;
public Guitar(String color, String brand, String model, double price, boolean isSecondHand, String warehouse, int stockNumber){
this.color = color;
this.brand = brand;
this.model = model;
this.price = price;
this.isSecondHand = isSecondHand;
this.warehouse = warehouse;
this.stockNumber = stockNumber;
}
}
class Inventory {
List guitars = new ArrayList<>();
public void addGuitar(Guitar guitar){
for (Guitar existingGuitar : guitars){
if (existingGuitar.brand.equals(guitar.brand) && existingGuitar.model.equals(guitar.model)){
existingGuitar.stockNumber++;
return;
}
}
guitars.add(guitar);
}
public Guitar searchGuitar(String brand, String model, double price){
for (Guitar guitarItem : guitars){
if (guitarItem.brand == brand && guitarItem.model == model && guitarItem.price == price){
return guitarItem;
}
}
return null;
}
}
public class Main {
public static void main(String[] args){
Inventory inventoryList = new Inventory();
Guitar guitar1= new Guitar("Purple", "Fender", "A573H",880.00, false, "Warehouse1",6);
inventoryList.addGuitar(guitar1);
Guitar guitar2= new Guitar("Yellow", "Yamaha", "B032T",1300.00, true, "Warehouse2",5);
inventoryList.addGuitar(guitar2);
Guitar lookingGuitar = inventoryList.searchGuitar("Fender","A573H",880.00);
if (lookingGuitar != null){
System.out.println("brand: "+ lookingGuitar.brand +" model: "+ lookingGuitar.model+" color: "+lookingGuitar.color+" isSecondhand: "+lookingGuitar.isSecondHand+" price: "+lookingGuitar.price+" Warehouse: "+lookingGuitar.warehouse+" Stock: "+lookingGuitar.stockNumber);
} else {
System.out.println("Guitar not exist");
}
}
} This is my code, i want to create two methods in inventory, one is addguitar, when i add the same guitar ,stocknumber increase one, another is removeguitar, stocknumber decrease one

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

What is paper chromatography?

Answered: 1 week ago

Question

Explain the cost of capital.

Answered: 1 week ago

Question

Define capital structure.

Answered: 1 week ago