Reputation: 27
my problem is confusing me because I have done this before and it worked in previous programs but this particular program will not work. I just need to use the method typeInput and popularityNumber with the 2 variables I passed to them but I cannot call them in my main method without error. Either a ")" or ";" expected occurs, and it looks to me like there are parenthesis and semi colons where needed. I'm sure it's a quick fix and would appreciate learning how to fix it. Thank you!
public static void main(String[] args) {
// TODO code application logic here
nameInput();
typeInput(Scanner keyboard, CartoonStar star);
popularityNumber();
}
/**
*
* @param name
*/
public static void nameInput() {
System.out.println("What is the name of the cartoon character : ");
Scanner keyboard = new Scanner(System.in);
CartoonStar star = new CartoonStar();
String name = keyboard.next();
star.setName(name);
}
public static void typeInput(Scanner keyboard, CartoonStar star){
System.out.println("What is the cartoon character type: 1 = FOX,2 = CHICKEN,3 = RABBIT,4 = MOUSE,5 = DOG,\n"
+ "6 = CAT,7 = BIRD,8 = FISH,9 = DUCK,10 = RAT");
switch (keyboard.nextInt())
{case 1 :
star.setType(CartoonType.FOX);
break;
case 2 :
star.setType(CartoonType.CHICKEN);
break;
case 3 :
star.setType(CartoonType.RABBIT);
break;
case 4 :
star.setType(CartoonType.MOUSE);
break;
case 5 :
star.setType(CartoonType.DOG);
break;
case 6 :
star.setType(CartoonType.CAT);
break;
case 7 :
star.setType(CartoonType.BIRD);
break;
case 8 :
star.setType(CartoonType.FISH);
break;
case 9 :
star.setType (CartoonType.DUCK);
break;
case 10 :
star.setType(CartoonType.RAT);
break;
}
}
public static void popularityNumber(Scanner keyboard, CartoonStar star){
System.out.println("What is the cartoon popularity number?");
int popularity = keyboard.nextInt();
star.setPopularityIndex(popularity);
System.out.println(star.getName() + star.getType() + star.getPopularityIndex());
}
}
CartoonStar class (just in case you want it):
public class CartoonStar {
private String name;
private CartoonStar.CartoonType type;
enum CartoonType {
FOX(1),CHICKEN(2),RABBIT(3),MOUSE(4),DOG(5),CAT(6),BIRD(7),FISH(8),DUCK(9),RAT(10);
private final int animalType;
private static Map <Integer, CartoonType> map = new HashMap <Integer, CartoonType>();
private CartoonType(int animalType){
this.animalType=animalType;
}
public int getAnimlType(){
return animalType;}
}//enum types
private int popularityIndex; //1 to 10 10 being the most popular
public CartoonStar() {
}//end no argument construtor
public CartoonStar(String name,CartoonStar.CartoonType type, int popularityIndex) {
setName(name);
setType(type);
setPopularityIndex(popularityIndex);
}//end full constructor
//getters and setters
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setType(CartoonStar.CartoonType type) {
this.type = type;
}
public CartoonStar.CartoonType getType() {
return type;
}
public void setPopularityIndex(int popularityIndex){
this.popularityIndex = popularityIndex;
}
public int getPopularityIndex(){
return popularityIndex;
}
}
Upvotes: 0
Views: 144
Reputation: 89169
In your main method, you call your method as follows:
typeInput(Scanner keyboard, CartoonStar star);
The typeInput
method expects a declared keyboard
and declared star
. You have called it incorrectly.
Your best option will be as follows:
public static void main(String[] args) {
// TODO code application logic here
nameInput();
popularityNumber();
}
public static void nameInput() {
System.out.println("What is the name of the cartoon character : ");
Scanner keyboard = new Scanner(System.in);
CartoonStar star = new CartoonStar();
String name = keyboard.next();
star.setName(name);
typeInput(keyboard, star);
}
I added typeInput()
in your nameInput()
method and removed it from the main()
method.
Upvotes: 3