To get experience working on Java programs combining multiple classes, constructors, methods, array lists, enumerations, and static methods.
For this assignment, you will write a program which models the inventory system of a role playing game. In these types of games, players can carry around a set of items called their "inventory".
Each item has a descriptive name, a weight, a value and a strength. The value indicates how much the player could sell the item to a merchant for. The strength only applies to some items (like weapons and armor) and indicates how powerful the item is.
The weight comes into play because the player can only carry a fixed upper limit. If picking up a new item would cause the player to go over their weight limit, then they cannot pick it up (at least until they drop something else).
The system will let the player do the following things:
For this project, I'd suggest making the following set of classes and methods. Of course you can add other methods if you find them helpful.
Below is a UML diagram of the project:
Below is an example run to give you an idea of how this can work. Your program doesn't have to work exactly the same way. Also, the items you generate will of course be different.
------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 2 The Old Boot was added to your inventory. ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 2 The Iron Long Sword was added to your inventory. ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 2 The Fork was added to your inventory. ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 2 The Rusty Iron Armor was added to your inventory. ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 1 Item Weight Value Strength Old Boot 6 5 0 Iron Long Sword 17 19 22 Fork 6 5 0 Rusty Iron Armor 18 11 9 ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 3 Drop an item Item Weight Value Strength 1. Old Boot 6 5 0 2. Iron Long Sword 17 19 22 3. Fork 6 5 0 4. Rusty Iron Armor 18 11 9 5. Cancel : 1 You dropped the Old Boot ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 4 Equip a Weapon Item Weight Value Strength 1. Iron Long Sword 17 19 22 2. Cancel : 1 You equipped the Iron Long Sword ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 5 Equip Armor Item Weight Value Strength 1. Rusty Iron Armor 18 11 9 2. Cancel : 1 You equipped the Rusty Iron Armor ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 1 Item Weight Value Strength Iron Long Sword 17 19 22 (equipped weapon) Fork 6 5 0 Rusty Iron Armor 18 11 9 (equipped armor) ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 2 The Lockpick was added to your inventory. ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 2 The Broom was added to your inventory. ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 2 The Steel Armor was added to your inventory. ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 5 Equip Armor Item Weight Value Strength 1. Rusty Iron Armor 18 11 9 2. Steel Armor 15 15 21 3. Cancel : 2 You equipped the Steel Armor ------------------ 1. Print inventory 2. Add random item 3. Drop item 4. Equip Weapon 5. Equip Armor 6. Exit : 6
When writing your program, also be sure to:
A solution to this project can be seen here:
You should submit your program by uploading all of the .java files to Canvas.
Copyright © 2024 Ian Finlayson | Licensed under a Creative Commons BY-NC-SA 4.0 License.