Commit 543b1550 authored by a.guest's avatar a.guest

initial

parents
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).
File added
## Little Lucy's Fabledrealm
Little Lucy is running a fantasy roleplaying game for her friends. She's a busy computer science student who doesn't have time to think up new adventure ideas every week so she has created an app to generate random adventures for her. Lucy needs your help in documenting the application design.
### Assessment Exercise 4
You need to create UML diagrams for this project.
* **Class Diagram** showing the classes in the application and their relationships to each other. Remember a class diagram shows the class structure as it exists throughout the life of the application. It does not show objects.
* **Object Diagram** just after the application generates this weeks adventure. (i.e. just after line 6 in App.java finishes running). This diagram should show all the objects that exist at that point and how they are linked to each other.
* **Sequence Diagram** showing the objects and methods involved in the line of code `Adventure thisWeek = generator.generateAdventure();` (line 8 in App.java).
### Marking
25 marks are available for this exercise. This breaks down as follows.
* Class Diagram - 10 marks
* Object Diagram - 5 marks
* Sequence Diagram - 10 marks
## 6 Submission
Your project should be uploaded to your gitlab account and you should submit a link to the gitlab project, alongside the rest of the assessment, through moodle, by 12 noon 16/05/22.
\ No newline at end of file
public class Adventure {
// Private member variables
private String location;
private String bossMonster;
private String monster;
private String goal;
private String treasure;
// constructor
public Adventure() {
}
public String getDescription() {
return "The adventure is to " + goal + " at " + location + ". A " + bossMonster + " and thier " + monster + " are there. The treasure is " + treasure + ".";
}
// getters
public String getLocation() { return location; }
public String getBossMonster() { return bossMonster; }
public String getMonster() { return monster; }
public String getGoal() { return goal; }
public String getTreasure() { return treasure; }
public void setLocation(String location) { this.location = location; }
public void setBossMonster(String bossMonster) { this.bossMonster = bossMonster; }
public void setMonster(String monster) { this.monster = monster; }
public void setGoal(String goal) { this.goal = goal; }
public void setTreasure(String treasure) { this.treasure = treasure; }
}
\ No newline at end of file
import java.util.ArrayList;
public class AdventureGenerator {
public enum OptionType {
LOCATION,
BOSS_MONSTER,
MONSTER,
GOAL,
TREASURE
}
private Option locations = new Option();
private Option bossMonsters = new Option();
private Option monsters = new Option();
private Option goals = new Option();
private Option treasures = new Option();
public AdventureGenerator() {
}
public void add(OptionType type, String option) {
switch (type) {
case LOCATION :
locations.add(option);
break;
case BOSS_MONSTER :
bossMonsters.add(option);
break;
case MONSTER :
monsters.add(option);
break;
case GOAL :
goals.add(option);
break;
case TREASURE :
treasures.add(option);
break;
default :
break;
}
}
public String getRandom(OptionType type) {
switch (type) {
case LOCATION :
return(locations.getRandom());
case BOSS_MONSTER :
return(bossMonsters.getRandom());
case MONSTER :
return(monsters.getRandom());
case GOAL :
return(goals.getRandom());
case TREASURE :
return(treasures.getRandom());
default :
return "";
}
}
public boolean valid(OptionType type, String option) {
switch (type) {
case LOCATION :
return(locations.isValid(option));
case BOSS_MONSTER :
return(bossMonsters.isValid(option));
case MONSTER :
return(monsters.isValid(option));
case GOAL :
return(goals.isValid(option));
case TREASURE :
return(treasures.isValid(option));
default :
return false;
}
}
public Adventure generateAdventure() {
Adventure adv = new Adventure();
adv.setLocation(getRandom(OptionType.LOCATION));
adv.setBossMonster(getRandom(OptionType.BOSS_MONSTER));
adv.setMonster(getRandom(OptionType.MONSTER));
adv.setGoal(getRandom(OptionType.GOAL));
adv.setTreasure(getRandom(OptionType.TREASURE));
return adv;
}
}
File added
public class App {
public static void main(String[] args) throws Exception {
AdventureGenerator generator = new AdventureGenerator();
setupGenerator(generator);
Adventure thisWeek = generator.generateAdventure();
System.out.println(thisWeek.getDescription());
}
public static void setupGenerator(AdventureGenerator gen) {
gen.add(AdventureGenerator.OptionType.LOCATION, "Castle");
gen.add(AdventureGenerator.OptionType.LOCATION, "Ruin");
gen.add(AdventureGenerator.OptionType.LOCATION, "Dungeon");
gen.add(AdventureGenerator.OptionType.LOCATION, "Island");
gen.add(AdventureGenerator.OptionType.LOCATION, "Mountain");
gen.add(AdventureGenerator.OptionType.BOSS_MONSTER, "Orc Warlord");
gen.add(AdventureGenerator.OptionType.BOSS_MONSTER, "Goblin Chief");
gen.add(AdventureGenerator.OptionType.BOSS_MONSTER, "Elf Wizard");
gen.add(AdventureGenerator.OptionType.BOSS_MONSTER, "Dwarf King");
gen.add(AdventureGenerator.OptionType.BOSS_MONSTER, "Dragon");
gen.add(AdventureGenerator.OptionType.MONSTER, "Goblins");
gen.add(AdventureGenerator.OptionType.MONSTER, "Orcs");
gen.add(AdventureGenerator.OptionType.MONSTER, "Lizardlings");
gen.add(AdventureGenerator.OptionType.MONSTER, "Elves");
gen.add(AdventureGenerator.OptionType.MONSTER, "Dwarves");
gen.add(AdventureGenerator.OptionType.GOAL, "Rescue Prince(ss)");
gen.add(AdventureGenerator.OptionType.GOAL, "Steal Jewellry");
gen.add(AdventureGenerator.OptionType.GOAL, "Scout Area");
gen.add(AdventureGenerator.OptionType.GOAL, "Collect Magic Fruit");
gen.add(AdventureGenerator.OptionType.GOAL, "Solve Mystery");
gen.add(AdventureGenerator.OptionType.TREASURE, "Magic Sword");
gen.add(AdventureGenerator.OptionType.TREASURE, "Lots Of Gold");
gen.add(AdventureGenerator.OptionType.TREASURE, "Flying Carpet");
gen.add(AdventureGenerator.OptionType.TREASURE, "Treasure Map");
gen.add(AdventureGenerator.OptionType.TREASURE, "Strange Crown");
}
}
## Little Lucy's Fabledrealm
Little Lucy is running a fantasy roleplaying game for her friends. She's a busy computer science student who doesn't have time to think up new adventure ideas every week so she has created an app to generate random adventures for her. Lucy needs your help in documenting the application design.
### Assessment Exercise 4
You need to create UML diagrams for this project.
* **Class Diagram** showing the classes in the application and their relationships to each other. Remember a class diagram shows the class structure as it exists throughout the life of the application. It does not show objects.
* **Object Diagram** just after the application generates this weeks adventure. (i.e. just after line 6 in App.java finishes running). This diagram should show all the objects that exist at that point and how they are linked to each other.
* **Sequence Diagram** showing the objects and methods involved in the line of code `Adventure thisWeek = generator.generateAdventure();` (line 8 in App.java).
### Marking
25 marks are available for this exercise. This breaks down as follows.
* Class Diagram - 10 marks
* Object Diagram - 5 marks
* Sequence Diagram - 10 marks
## 6 Submission
Your project should be uploaded to your gitlab account and you should submit a link to the gitlab project, alongside the rest of the assessment, through moodle, by 12 noon 16/05/22.
\ No newline at end of file
import java.util.ArrayList;
public class Option {
private ArrayList<String> items = new ArrayList<String>();
public void add(String item) {
if (!items.contains(item)) {
items.add(item);
}
}
public String getRandom() {
int index = (int)(Math.random() * items.size());
return(items.get(index));
}
public String get(int index) {
return(items.get(index));
}
public boolean isValid(String item) {
if (items.contains(item)) {
return true;
}
else
{
return false;
}
}
public int size() {
return items.size();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment