我在智慧结束。我不明白我需要做什么才能使代码工作。我知道main()是静态的。但是什么使我的方法非静态。
package ch5Hw;
import java.util.Scanner;
public class EventDemo {
int eventId;
int numOfguests;
Event largeWedding= new Event( eventId, numOfguests);
Event smallFamReunion= new Event(eventId, numOfguests);
Event hugeFestival=new Event (eventId, numOfguests);
Scanner keyboard= new Scanner(System.in);
public static void main(String[] args) {
partySize();//ERROR HERE..Cannot make a static reference to the non-static method partySize() from the type EventDemo
}
public void partySize() {
System.out.println("Please enter an identification integer for Wedding");
eventId = keyboard.nextInt();
System.out.println("Please enter the number of guests for your Family Reunion");
numOfguests = keyboard.nextInt();
if (numOfguests < Event.CUTOFF_NUMBER) {
smallFamReunion.setEventNumber(eventId);
smallFamReunion.setNumberOfGuests(numOfguests);
}
else if (numOfguests >= Event.CUTOFF_NUMBER && eventId < 100) {
largeWedding.setEventNumber(eventId);
largeWedding.setNumberOfGuests(numOfguests);
}
else {
hugeFestival.setEventNumber(eventId);
hugeFestival.setNumberOfGuests(numOfguests);
}
}
}
答案 0 :(得分:0)
制作方法static
。
public static void partySize()
或者像这样称呼它 -
new EventDemo().partySize()
答案 1 :(得分:0)
将partySize();
替换为new EventDemo().partySize();
,因为只有您的类实例可以调用此方法。