아하
검색 이미지
생활꿀팁 이미지
생활꿀팁생활
생활꿀팁 이미지
생활꿀팁생활
정중한상괭이185
정중한상괭이18521.04.16

자바 이클립스 에러 질문드려요

자꾸 이런 에러가 뜨면서 실행이 되지 않습니다.

환경설정 환경변수는 모두 제대로 설정했습니다.

뭐가 문제고 어떻게 해야할까요.. 시험기간인데 큰일이에요

아래는 코드 전문입니다.

package lab6; import java.util.ArrayList; import java.util.Date; import java.util.Scanner; class Staff extends Person{ private int staffID; private String dept; private Date dateHired; public static ArrayList<Staff> staffs = new ArrayList<>(); Staff(String n, String p, String d){ super(n, p); dept = d; } void printInfo() { super.printInfo(); System.out.println("staff id : " + staffID); System.out.println("DATE Hired : " + dateHired); System.out.println("dept : " + dept); } } class Customer extends Person { // Atrributes private int customerID; private String driverLicense; public static ArrayList<Customer> customers = new ArrayList<>(); // Operations Customer(String n, String p, String license) { super(n , p); driverLicense = license; } @Override public void printInfo() { super.printInfo(); System.out.println("customer ID : " + customerID); System.out.println("driverLicense : " + driverLicense); } } class Person { Scanner sc = new Scanner(System.in); // Attributes private int personID; private String name; private String phone; private static ArrayList<Person> persons = new ArrayList<>(); // Operations Person(String n, String p) { // Constructor n : name, p : phone this.name = n; this.phone = p; } void printInfo() { // System.out.println("person ID : " + personID); System.out.println("name : " + name); System.out.println("phone number : " + phone); } protected static void addPerson(Person p) { persons.add(p); // add the instance of Person that received as parameter } protected static Boolean deletePerson(Person p) { if (persons.isEmpty()) return false; else { persons.remove(p); return true; } } public void printAllPersons() { if (persons.isEmpty()) System.out.println("ArrayList<Person> persons are empty now"); else { for (int i = 0; i < persons.size(); i++) // print all the elements in ArrayList<Person> persons. Using // printInfo in ArrayList element persons.get(i).printInfo(); } } public class lab6 { public static void main(String[] args) { Customer customer1 = new Customer("heewon", "010-2323-9121", "da-2501"); Customer customer2 = new Customer("jiwon", "010-1111-1111", "da-2502"); Customer customer3 = new Customer("jisu", "010-4563-1243", "da-2503"); Customer.customers.add(customer1); Customer.customers.add(customer2); Customer.customers.add(customer3); Staff staff1 = new Staff("heesu", "010-2828-2828", "100000 won"); Staff staff2 = new Staff("jisun", "010-2213-2512", "1200000 won"); Staff staff3 = new Staff("mimin", "010-2828-1232", "400000 won"); Staff.staffs.add(staff1); Staff.staffs.add(staff2); Staff.staffs.add(staff3); }

55글자 더 채워주세요.
답변의 개수4개의 답변이 있어요!
  • 안녕하세요..

    코딩하시다가 괄호 '}' 가 빠지신것 같네요..

    수정소스 올려드립니다.

    package lab6;

    import java.util.ArrayList;

    import java.util.Date;

    import java.util.Scanner;

    class Staff extends Person{

    private int staffID;

    private String dept;

    private Date dateHired;

    public static ArrayList<Staff> staffs = new ArrayList<>();

    Staff(String n, String p, String d){

    super(n, p);

    dept = d;

    }

    void printInfo() {

    super.printInfo();

    System.out.println("staff id : " + staffID);

    System.out.println("DATE Hired : " + dateHired);

    System.out.println("dept : " + dept);

    }

    }

    class Customer extends Person {

    // Atrributes

    private int customerID;

    private String driverLicense;

    public static ArrayList<Customer> customers = new ArrayList<>();

    // Operations

    Customer(String n, String p, String license) {

    super(n , p);

    driverLicense = license;

    }

    @Override

    public void printInfo() {

    super.printInfo();

    System.out.println("customer ID : " + customerID);

    System.out.println("driverLicense : " + driverLicense);

    }

    }

    class Person {

    Scanner sc = new Scanner(System.in);

    // Attributes

    private int personID;

    private String name;

    private String phone;

    private static ArrayList<Person> persons = new ArrayList<>();

    // Operations

    Person(String n, String p) { // Constructor n : name, p : phone

    this.name = n;

    this.phone = p;

    }

    void printInfo() { //

    System.out.println("person ID : " + personID);

    System.out.println("name : " + name);

    System.out.println("phone number : " + phone);

    }

    protected static void addPerson(Person p) {

    persons.add(p); // add the instance of Person that received as parameter

    }

    protected static Boolean deletePerson(Person p) {

    if (persons.isEmpty())

    return false;

    else {

    persons.remove(p);

    return true;

    }

    }

    public void printAllPersons() {

    if (persons.isEmpty())

    System.out.println("ArrayList<Person> persons are empty now");

    else {

    for (int i = 0; i < persons.size(); i++) // print all the elements in ArrayList<Person> persons. Using

    // printInfo in ArrayList element

    persons.get(i).printInfo();

    }

    }

    }

    public class lab6 {

    public static void main(String[] args) {

    Customer customer1 = new Customer("heewon", "010-2323-9121", "da-2501");

    Customer customer2 = new Customer("jiwon", "010-1111-1111", "da-2502");

    Customer customer3 = new Customer("jisu", "010-4563-1243", "da-2503");

    Customer.customers.add(customer1); Customer.customers.add(customer2);

    Customer.customers.add(customer3);

    Staff staff1 = new Staff("heesu", "010-2828-2828", "100000 won");

    Staff staff2 = new Staff("jisun", "010-2213-2512", "1200000 won");

    Staff staff3 = new Staff("mimin", "010-2828-1232", "400000 won");

    Staff.staffs.add(staff1);

    Staff.staffs.add(staff2);

    Staff.staffs.add(staff3);

    }

    }


  • 정말 열심히 잘하셨는데 main이 에러 네요.ㅎ

    자바는 { } 로 메소드와 블럭을 묶기 때문에 { } 열고 닫고 를 잘해 줘야 합니다.

    그래서 줄을 잘 맞추기도 해야 하죠

    main 메소드의 위쪽 클래스의 마지막 메소드를 보면 닫는 } 가 빠졌어요

    public void printAllPersons() {

    if (persons.isEmpty())

    System.out.println("ArrayList<Person> persons are empty now");

    else {

    for (int i = 0; i < persons.size(); i++) // print all the elements in ArrayList<Person> persons. Using

    // printInfo in ArrayList element

    persons.get(i).printInfo();

    } //if ~ else 닫기

    } //printAllPerson 메소드 닫기

    } //Person 클래스 닫기


  • 안녕하세요

    오류메세지를 보니 static을 제거하라는것처럼 보이는데요.

    main 메소드의 static으로 선언되어있는것을 한번 지워서

    다시 빌드 진행 해보시면 될것같습니다.

    참고로 오류메세지의 아라 파란줄로있는게 오류를 줄이기위한 가이드라고 볼수있으니, 추후 오류가발생하면 해당오류를 보며 수정하시면 도움되실것같습니다.


  • 탈퇴한 사용자
    탈퇴한 사용자21.04.16

    안녕하세요.

    소스 상으로만 봤을 때에는 "public class lab6" 라고 선언이 "class Person" 안쪽에 있는거 같은데, 맞는지요?

    만약 Person 안에 있다면, lab6 클래스 안에서는 method 에 static을 붙일 수 없습니다.

    1. "public static class lab6"로 변경하거나,

    2. main method의 static을 제거하거나,

    3. static main method를 Person class 괄호 안쪽에 넣거나 등등 방법이 있습니다.