inflearn logo
강의

Course

Instructor

@Sico - Learning Java Properly (Complete Basics)

Java Basics 07 - Array & ArrayList

궁금합니다

Resolved

318

urisai02109

1 asked

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으로 고쳤을때는 실행했을때 결과값이 나오지 않았습니다. 그 이유는 무엇일까요?

java

Answer 1

0

seniorcoding

안녕하세요

실행해 보니 잘 나옵니다.

image

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

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

 

감사합니다~

 

동일성 동등성

0

8

1

안녕하세요 치킨 디도스 이벤트 보고 흉내내보려 들어왔습니다..

0

12

1

47번 리턴 관련 질문

0

18

1

실무 내용 문의드려요

0

24

2

IO활용-회원관리예제1 샘플코드 문의

0

19

1

join에대해 질문드립니다.

0

19

1

pg사가 있다고 가정하면

0

25

1

중급 1편 학습 방향에 대해 조언 부탁드립니다

0

32

1

To-Do App

0

27

1

강의노트 접속 불가

0

28

2

Kafka Cluster 구성도 질문

0

23

1

15강 중 에러가 났는데 해결이 안되어 질문 남깁니다.

0

469

1

자바 중급 강의

0

621

1

객체란 무엇인가요?

0

1086

1

하이자바에서 커밋눌렀는데 작업한 코드가 안뜹니다.

0

346

1

MomandSon Drink함수

0

303

1

소수의 합 ArrayList

0

267

1

.getAmount

0

243

1

전화번호 끝자리 ****로 출력

0

497

3

함수재정의(override)

0

256

1

6강 클래스 객체 내용

0

209

1

java 유료화 관련

0

449

2

private임에도 print가 되는 이유문의(Man class문제)

0

183

1

정리차원에서 듣고있습니다.

0

216

1