So I've looked at a few examples on the site and haven't found anything needed. The exercise I'm trying to do is to link the enum class to the switch statement found at the bottom of the page.
The exercise question for this small part is: "The talk method should ask the user to input a phrase, which should be printed on the console. An Entertainment Robot can walk any number of paces in one of four directions (forwards, backwards, left, right). Therefore the walk method should ask the user how many paces they wish the robot to take and in which direction. Note you must validate the user’s input. The directions must be stored as an enum and accessed appropriately."
Enum class:
package robot;
public enum Directions {
FORWARD, BACKWARD, LEFT, RIGHT;
}
Main class:
package robot;
import java.util.Scanner;
public class EntertainmentRobot extends Robot implements Walk, Talkable {
private Directions direction;
public EntertainmentRobot(double height, double weight, String manufacturer, String name) {
super(height, weight, manufacturer, name);
setEnergy(10);
setEnergyUnitsRequired(0.75);
}
// ACCESSOR METHOD
public Directions getDirection() {
return direction;
}
// MUTATOR METHOD
public void setDirection(Directions direction) {
this.direction = direction;
}
@Override
public void start() {
System.out.println("-----I AM THE ENTERAINIMENT ROBOT-----");
}
@Override
public void stop() {
System.out.println("I have stopped entertaining people.");
}
@Override
public void doTask() {
// TODO Auto-generated method stub
}
@Override
public void doTask(Scanner in) {
System.out.println("I am entertaining people.");
System.out.println("How many people would you like to play with me?");
int times = in.nextInt();
for (int i = 0; i < times; i++) {
play();
}
System.out.println(" ");
}
public String toString() {
return "[Name= " + getName() + "\nWeight= " + getWeight() + "\nHeight:" + getHeight() + "\nManufacturer: "
+ getManufacturer() + "\nPurpose: " + getPurpose() + "]";
}
public void play() {
if (getEnergy() >= energyRequired()) {
energyComsumption();
} else {
System.out.println("\n-----WHOOPS-----");
System.out.println("I do not have enough energy to study");
regenerate();
System.out.println("I must get more energy");
System.out.println("I have regenerated my energy");
}
}
@Override
public void talk(Scanner in) {
System.out.println("Please enter a phrase for me to speak: ");
String talk = in.nextLine();
System.out.println("You asked me to say the following phrase: " + talk);
}
@Override
public void walk(Scanner in) {
System.out.println("Would you like me to walk? [YES/NO]");
String walk = in.nextLine();
if (walk.equalsIgnoreCase("Yes")) {
}
}
public void directionChoice(Scanner in) {
System.out.println("For how many paces?");
int paces = in.nextInt();
System.out.println("1 - FORWARD" + "2 - BACKWARD" + "3 - LEFT" + "4 - RIGHT");
switch (paces) {
case 1:
break;
case 2:
}
}
}