Question: *************************JAVA: I need help on part 3************************** This is a continuation HW assignment first Part is Hero class, second part is Party class, and third

*************************JAVA: I need help on part 3**************************

This is a continuation HW assignment first Part is Hero class, second part is Party class, and third part is Main.java create a menu-driven prorgram using the first two classes.

I am very confused by the instructions for part 3

Instructions:

Part 1:

Hero Class

Properties: name: String , int: rupees

Constructors: Working constructor: sets both Working constructor: sets name, rupees default to 0 Default constructor: sets name to empty string, and rupees to 0

Getters/Setters: total of 4 methods

Methods: findRupees: int - uses helper method to increment value spendRupees: int - uses helper method to decrement value isEmpty: boolean - returns true if name is empty toString: String - holds name and rupees

Helper methods: adjustRupees: void - method adjusts the total rupee value

Part 2 Party Class

Properties: partySize: int - size of the array title: String - title of the group of hero heros: Hero [ } - array of Hero objects

Constructors: Working constructor: sets partySize and title, then initializes the array

Getters/Setters: total of 6 methods

Methods: getHero: Hero - method takes in an integer representing the index, then returns the Hero in that position isEmpty: boolean - returns true if name is empty, checks a single slot isEmpty: boolean - overloaded function checks if all slots are empty toString: String - displays the title of the party, then displays only those with names Helper methods: none

***************************Part 3 Party Class****************************

Instructions

Using your Hero.java and Party.java classes from the two journals, create a menu-driven program which utilizes a main menu and a hero menu to demonstrate usage of your class objects.

Main menu options: display heros - should use the party class toString method select hero - should call a method that calls a subMenu, pass in a Hero as a parameter exit game - display a simple good bye/exit message.

hero menu options:

create hero - should just change the hero name in that slot

add rupees - should simply prompt for the amount, then use Hero method to add rupees

spend rupees - should simply prompt for the amount, then use Hero method to spend rupees

return - should return to the main menu

main java program should have the following methods:

createBorder - you know how to do this already

displayMenu - see other examples

getUserSelection

Create a border

declare and initialize a char option to 'a' or 'A'

display the title of the menu

using a for-loop display options

getUserSelection - returns a char

use a Scanner to get user input for a char (this will be for your menu option)

Use Character.toLowerCase or the bitwise operation we did in other exercises

getIntValue - returns an int

create a scanner object, or pass one in. This method should work both for getting the index and for amount of rupees. You will prompt the user in main before calling this method. This method only gets and returns user input.

getHeroName - returns a String

prompt user for the hero name in main, not in function

runMainMenu

should use an array of options as in directions

infinite while-loop

display the menu "Main Menu"

utilize a switch and the getUserSelection()

runHeroMenu

same as runMainMenu, except this is "Hero Menu" and you will use different options

before displaying the menu, if the Hero selected happens to have a name already, display their info

NOTE:

In main, you will only create a new Party, giving it a limit and a title. Then, you will call runMainMenu, that is it.

Main.java

public class Joural_6 {

public static void main(String[] args) { //Object Hero Her = new Hero("Heroes Names"); // Print System.out.println(Her); //Call Method Her.findRupees(); //Print System.out.println(Her);

//Call Method Her.findRupees(); //Print System.out.println(Her); //Object Party par = new Party(3, "heros"); //Print System.out.println(par.isEmpty());

//array par.heros[0] = Her; //Print System.out.println(par.isEmpty());

System.out.println(par); } }

Hero Class

public class Hero {

String name; int Rupees;

public Hero() { name = ""; Rupees = 0; }

public Hero(String name) { this.name = name; }

public Hero(String name, int Rupees) { this.name = name; this.Rupees = Rupees; }

public int findRupees() { Rupees++; return Rupees; }

public int spendRupees() { Rupees--; return Rupees; }

public boolean isEmpty(String name) { if (name.isEmpty()) { return true; } else { return false; } }

public String toString() { String result;

result = this.name + ": " + this.Rupees;

return result; }

public void adjustRupees(int R) { Rupees = R; } }

Party Class

public class Party { //Properties String title; int partySize; Hero heros[]; //Constructors public Party(int partySize, String title) { this.partySize = partySize; this.title = title; heros = new Hero[partySize]; }

public Party(int partySize, String title, Hero[] heros) { this.partySize = partySize; this.title = title; this.heros = heros; }

//Methods public Hero getHero(int i) { if (i < partySize) { return heros[i]; } else { return null; } }

boolean isEmpty(int i) { return heros[i] == null; }

boolean isEmpty() { for (int i = 0; i < partySize; i++) { if (heros[i] != null) { return false; } } return true; }

@Override public String toString() { return "Party" + "{ partySize = " + partySize + ",title ='" + title + '\'' + ", heros = " + Arrays.toString(heros)+ '}'; } }

What I need help with:******************Part 3 = New-menu driven program main.Java******************

My attempt: (Really don't understand instructions properly so not sure if any of this is correct, please help guide)

import java.util.Random; import java.util.Scanner;

public class Assignment_ {

public static final String BORDER = createBorder(30, '=');

{ //create array of chars return new String(new char[size]).replace('\0', sym);

Scanner input = new Scanner(System.in);

//Main Menu options switch (main) { case 1: displayHeros(); break; case 2: slectHero(); break; case 3: exitGame(); break; }

//Hero menu Options switch (hero) { case 1: createHero(); break; case 2: addRupees(); break; case 3: spendRupees(); case 4: displayMenu(); break; }

displayMenu();

getUserSelection();

getUserSelection();

getIntValue();

getHeroName();

runMainMenu();

runHeroMenu(); }

public static void main(String[] args) { //declare and initialize a constant border final String BORDER = createBorder(30, '=');

}

} //Methods exitGame() { System.out.println("Good bye"); }

// Method for border public static String createBorder(int size, char sym) { return new String(new char[size]).replace('\0', sym); }

public static String createBorder() { return createBorder(30, '='); }

displayMenu() { //main menu options: System.out.println("Display Heros"); System.out.println("Select Heros"); System.out.println("Exit game"); System.out.println("Please enter your choice:");

option = scanner.nextInt(); return option;

System.out.println("Create Hero "); System.out.println("Add rupees "); System.out.println("Send rupees "); System.out.println("Return"); System.out.println("Please enter your choice:");

option = scanner.nextInt(); return option; } //getUserSelection, Create a border, declare and initialize a char option to 'a' or 'A', //display the title of the menu using a for-loop display options getUserSelection() { // display outer border System.out.println(BORD); char option = 'a' }

//use a Scanner to get user input for a char (this will be for your menu option) //Use Character.toLowerCase or the bitwise operation we did in other exercises getUserSelection (char a) { Scanner input = new Scanner(System.in); user_input = input.nextString; return char a; String str1 = "".toLowerCase(); System.out.println("")+ str1; } //create a scanner object, or pass one in. //This method should work both for getting the index and for amount of rupees. //You will prompt the user in main before calling this method. //This method only gets and returns user input. getIntValue() { int 1; return int 1; }

//prompt user for the hero name in main, not in function getHeroName { return String help; }

//should use an array of options as in directions //infinite while-loop //display the menu "Main Menu" //utilize a switch and the getUserSelection() runMainMenu {

}

//same as runMainMenu, except this is "Hero Menu" and you will use different options //before displaying the menu, if the Hero selected happens to have a name already, //display their info runHeroMenu {

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!