-1

I am at wits end. I don't understand what do i need to do to make the code work. I understand main() is static. but what makes my method non-static.

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);
        }
    }
}
Tunaki
  • 132,869
  • 46
  • 340
  • 423
louie33
  • 33
  • 1
  • 1
  • 4
  • 5
    It is not static because it does not have the keyword `static` before its definition. – SJuan76 Oct 04 '15 at 17:52
  • 1
    Making the method static will solve this error, but then he will have "Cannot make a static reference to the non-static field smallFamReunion" – Tunaki Oct 04 '15 at 17:56

2 Answers2

0

either make your method static.

public static void partySize()

or call it like this - new EventDemo().partySize()

Adil Shaikh
  • 44,509
  • 17
  • 89
  • 111
0

replace partySize(); with new EventDemo().partySize(); because only your class instance can call this method.

N Kumar
  • 1,302
  • 1
  • 18
  • 25