• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    해결됨

궁금합니다

23.02.02 01:36 작성 23.02.03 02:54 수정 조회수 146

0

package hijavapractice;

 

public class Man {

public static final int COFFEE=3000;//오직 한개만 존재 값을 변동시킬수 없음

public static final int DONUT=2500;

private String name;//이름 변수

private int amount;//합계 변수

 

public Man() {//생성자 함수

this.amount=10000;

}

public Man(String name) {

this();//생성자를 다시 부르는 것.(this.amount=10000과 같은것)

this.name=name;

}

public void buyCoffee(int count) {

//this.amount=COFFEE*count;__1

this.Subamount(COFFEE, count);

//this.amount-=3000*count;과 같은말

//커피값은 변동할수도 있기때문에 전역변수로 뺀다//전역변수로 뺀꺼 쓰기

}

public void buyDonut(int count) {

//this.amount=DONUT*count;__1

this.Subamount(DONUT, count);

}//전역변수에 있는 도넛츠를 뺌

//-->함수를 뺄꺼임 도넛츠와 커피 즉 재료만 다르기 때문에

private void Subamount(int price, int count){//private으로 나만 부를수 있게 해놓은것 가격과 갯수

this.amount-=price*count;//부가세까지 포함한다면

}

 

 

public static void main1(String[] args) {

 

}

//getter setter 함수 생성

public String getName() {

return name;

}

 

public void setName(String name) {

this.name = name;

}

 

public int getAmount() {

return amount;

}

 

public void setAmount(int amount) {

this.amount = amount;

}

 

public String toString() {

return this.name+"님의 잔액은"+this.amount+"원 입니다";

}

//출력하기

public static void main(String[] args) {

Man hong=new Man("hong");

Man john=new Man("JOHN");

 

hong.buyCoffee(1);

hong.buyDonut(2);

 

john.buyCoffee(2);

john.buyDonut(1);

 

System.out.println("hong=" + hong.getAmount());

System.out.println("john=" + john.getAmount());

}

}

=====================
전체코드인데 제가 볼드체로 해놓은 저 main에서 오류가 나서 main1으로 바꿨더니 실행이 정상적으로 되었습니다. main 이름을 rename해야 된다고 떠서 클릭해서 해결한건데 왜 그런 오류가 뜨는건가요? 또한 처음에는 두번째 볼드 부분 main을 main1으로 고쳤을때는 실행했을때 결과값이 나오지 않았습니다. 그 이유는 무엇일까요?

답변 1

답변을 작성해보세요.

0

안녕하세요

실행해 보니 잘 나옵니다.

image

main 함수를 rename하라고 나오는 것은, 이미 main 함수가 있어서 그래요.

main 함수는 하나만 있어야 하니까요.

 

감사합니다~