1 The Character Interface For the purposes of this project, a Character has the
ID: 3915617 • Letter: 1
Question
1 The Character Interface For the purposes of this project, a Character has the following characteristics: An equipped weapon An equipped set of armor pieces A list of items, weapons, armor, or otherwise, that are not currently equipped. This list is called the "inventory." . Each armor piece has a "slot ID" associated with it. Each slot ID represents a part of the body where armor can be worn, for instance, head, chest, feet, etc. For each slot ID / body part, only one piece of armor can be equipped. For instance, if slot ID 3 represents the feet and iron Boots with slot ID = 3 are equipped, then it would be illegal to equip Leather Shoes that also have slot ID 3. However, it would be legal to simultaneously equip Iron Boots with slot ID = 3 and Leather Jacket with slot ID : 0. More details on armor and slot IDs are provided in the description of the Armor interface. An implementation of the Character interface must, at a minimum, contain the following methods Iterator inventory Returns an iterator that goes through the items in the inventory (that is, items that are not equipped as armor or a weapon). The items should be sorted in descending value-to-weight ratio (see the description of the Item interface for details).Explanation / Answer
import java.util.Iterator;
import java.util.List;
import java.util.Set;
public class CharacterImplementation implements Character {
private Weapon weapon;
private Set<Armor> pieces;
private List<Item> inventory;
@Override
public Iterator<Item> inventory() {
return null;
}
@Override
public void addItem(Item itemTemplate) {
if (itemTemplate == null)
throw new NullPointerException("");
if (itemTemplate instanceof Weapon)
weapon = (Weapon) itemTemplate;
if (itemTemplate instanceof Armor)
if (!pieces.contains((Armor) itemTemplate)) {
pieces.add((Armor) itemTemplate);
}
}
@Override
public void dropItem() {
// TODO Auto-generated method stub
}
@Override
public double getTotalWeight() {
// TODO Auto-generated method stub
return 0;
}
@Override
public Armor getEquippedArmor(int slot) throws IllegalArgumentException{
Ar
if(slot > 6 || slot < 0)
throw new IllegalArgumentException("invalid Slot Id found");
Iterator<Armor> itr = pieces.iterator();
while(itr.hasNext()) {
if(itr.next().getSlotId() == slot)
}
return null;
}
@Override
public int getTotalArmorRating() {
// TODO Auto-generated method stub
return 0;
}
@Override
public void equipArmor(Armor armor) {
// TODO Auto-generated method stub
}
@Override
public void unequipArmor(int slot) {
// TODO Auto-generated method stub
}
@Override
public Weapon getEquippedWeapon() {
// TODO Auto-generated method stub
return null;
}
@Override
public void equipWeapon(Weapon weapon) {
// TODO Auto-generated method stub
}
@Override
public void unequipWeapon() {
// TODO Auto-generated method stub
}
@Override
public void optimizeInventory(double maximumWeight) {
// TODO Auto-generated method stub
}
@Override
public void optimizeEquipment() {
// TODO Auto-generated method stub
}
public static void main(String[] args) {
Character char1 = new CharacterImplementation();
Item item1 = new ItemImpl();
Item item11 = new ItemImpl();
Item item12 = new ItemImpl();
Item item13 = new ItemImpl();
Item item14 = new ItemImpl();
Item item15 = new ItemImpl();
Item item16 = new ItemImpl();
Item item2 = new Armor();
Item item3 = new Weapon();
char1.addItem(item1);
char1.addItem(item11);
char1.addItem(item12);
char1.addItem(item13);
char1.addItem(item14);
char1.addItem(item15);
char1.addItem(item16);
char1.addItem(item2);
char1.addItem(item3);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.