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");
}
}
}

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 Concepts

Authors: David M Kroenke, David J Auer

6th Edition

ISBN: 0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

7. Where Do We Begin?

Answered: 1 week ago

Question

What is the most important part of any HCM Project Map and why?

Answered: 1 week ago