以前にこれを行ったことがあり、以前のプログラムでは機能していましたが、この特定のプログラムは機能しないため、私の問題は私を混乱させます。メソッド typeInput とpopularNumber を、渡した 2 つの変数と共に使用する必要があるだけですが、メイン メソッドでそれらをエラーなしで呼び出すことはできません。「)」または「;」のいずれか 必要な場所に括弧とセミコロンがあるように見えます。私はそれが迅速な修正であると確信しており、それを修正する方法を学んでいただければ幸いです. ありがとうございました!
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;
}
}