Question
Hi, the problem below is primarily complete. I just need assistance with the portion highlighted in bold. I'm not sure how to code for a
Hi, the problem below is primarily complete. I just need assistance with the portion highlighted in bold. I'm not sure how to code for a method that accepts a list of items and automatically maximizes the items based on weight (25 tons or less).
Below I have list the assignment instructions in italics, primary base code, Item class, Equipable subclass, Consumable subclass, and Weapon subclass.
ASSIGNMENT INSTRUCTIONS
While out on a standard run we stop in at our local fence and try to sell some of our items. When we board his ship we notice that we are the only people on board, so we instantly start grabbing things and loading them on our ship and get ready to run. While grabbing things we realize that we are going to run out of space extremely quickly and we should prioritize what we grab to maximize our financial gain while staying under our weight limit.
We dont have time to figure this out now as Gweedar might come back at any moment and catch us stealing from him which would result in our instant death.
Create an algorithm that maximizes the amount of money we will get if we ever come across this situation again. We will call this method ransack and it should accept a large list of items and return the optimal list of items we should grab based on our weight limit.
We must now store our items in a file and read from the file if prompted by the user. You can create a file with the list of items so you never have to type them in again, and you can control the items that are introduced to our world.
Items have attributes such as Name, Weight, Value, Durability and ID. (Create an object called Item)
We now classify our items by separating them into 3 distinct categories Equipable, Consumable or Weapon. (You must implement these 3 classes that are subclasses of Item and they must have at least 3 unique attributes in each subclass)
We can carry an unlimited number of items, as long as they dont exceed the maximum weight of the cargo bay, 25 Tons. (Use an ArrayList that checks an items weight before placing it in the cargo hold)
We need to be able to add and remove items by their name.
We need to be able to search for a specific type of item in our cargo bay based on the items name and one of its attributes (Implement 2 searches one on name and another on any attribute you choose).
We need to be able to sort items by their names alphabetically in descending order (A-Z)
We need to know how many of each item we have in our cargo bay and display their attributes.
We must also add a partial search (think of this as a filter option).
(1 PRIMARY BASE CODE
import java.util.*; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Scanner;
public class Assignment9 { public static void main(String[] args){ new Assignment9(); }
public Assignment9() { Scanner input = new Scanner(System.in); Item temp = new Item(); ArrayList
private void addItem(ArrayList
System.out.print("Is it a projectile (Y/N): "); String Projectile = input.nextLine(); String y = "y"; if(y.equalsIgnoreCase(Projectile.trim())){ ((Weapon)temp).setProjectile(true); } else{ ((Weapon)temp).setProjectile(false); } cargohold.add(temp); } }
private void removeItem(ArrayList
for (Item x : cargohold) { if (x.getName().equalsIgnoreCase(item)) { System.out.println(x.getName() + " found"); itemfound = 1; break; } } if(itemfound == 0){ System.out.println("Item NOT found"); } } private void searchByAttribute (ArrayList
} private void displayItem(ArrayList
(2 ITEM CLASS
public class Item_3 { String name; String ID; String category; Double weight; String value; String durability; public String getName() { return name; }
public void setName(String name) { this.name = name; } public String getID() { return ID; }
public void setID(String ID) { this.ID = ID; } public Double getWeight(){ return weight; } public void setWeight(Double weight){ this.weight = weight; } public String getValue(){ return value; } public void setValue(String value){ this.value = value; } public String getDurability(){ return durability; } public void setDurability(String durability){ this.durability = durability; }
//Create accessors and mutators for your triats. public void setCategory(String category) { this.category = category; } public String getCategory() { return category; } }
(3 EQUIPABLE SUBCLASS
public class Equipable extends Item { // instance variables - replace the example below with your own private String Color; boolean outfit; private int Size; public String getColor() { return Color; }
public void setColor(String Color) { this.Color = Color; }
public boolean isoutfit() { return outfit; }
public void setoutfit(boolean outfit) { this.outfit = outfit; }
public int getSize() { return Size; }
public void setSize(int Size) { this.Size = Size; } }
(4 CONSUMABLE SUBCLASS
public class Consumable extends Item { String Color; public boolean food; public boolean water; public boolean healthy;
public Consumable() {
}
// Create an overridden constructor here public Consumable(boolean food, boolean water, boolean healthy) { this.food = food; this.water = water; this.healthy = healthy; }
public boolean isFood() { return food; }
public void setFood(boolean food) { this.food = food; } public boolean isWater() { return water; }
public void setWater(boolean water) { this.water = water; } public String getColor() { return Color; }
public void setColor(String Color) { this.Color = Color; } public boolean isHealthy() { return healthy; }
public void setHealthy(boolean healthy) { this.healthy = healthy; } void Name(){ super.getName(); } void ID(){ super.getID(); } }
(4 WEAPON SUBCLASS
public class Weapon extends Item { String Color; public boolean projectile;
public Weapon() {
}
// Create an overridden constructor here public Weapon(boolean projectile) { this.projectile = projectile; }
public boolean isProjectile() { return projectile; }
public void setProjectile(boolean projectile) { this.projectile = projectile; } public String getColor() { return Color; }
public void setColor(String Color) { this.Color = Color; } //from super void Name(){ super.getName(); } void ID(){ super.getID(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started