Skip to content

Conversation

@OHHAKO
Copy link
Member

@OHHAKO OHHAKO commented Dec 26, 2019

It's works but that's all
i really concerned about this 3.

  1. separate the method
    : once method, once function but what's standard?
    also i made all of code into just one class because tiny project size. is it okay?

  2. using the constructor
    : before the game i want to define the initial setting(like init())
    so is it okay to definition by constructor?

  3. class difinition with static
    some java convention say don't use the object when i call the class(static) parameter, class method.
    instead of using object, use class name
    so is it applied to all of case?

@jnsorn
Copy link
Contributor

jnsorn commented Dec 28, 2019

1. Standard for a method that functions as one

I don't know the standard of a method that functions as one. Also, I don't know if it really exists. But I think it will be helpful to think about the purpose of making a method once again. In other words, what the method does must be clear.

In addition, These are posts on how to write a good method. When I read it, I share a lot of things that I didn't know. He wrote an posting while doing an effective java study, and I think we should do an effective java study, too.

2. The need for class separation

Even though it is a small project, the reason why we are finally making this program is to study about java and OOP .. , so I think we should write the class separately.
If you don't know how to view the program object-oriented (how to design objects), I recommend reading THIS.

For your information, I implemented the program by creating

  • Computer : generate random numbers
  • Player : receive predictive values and decide whether or not to play a game.
  • Result : Storage of the result(number of ball, strike....)

3. Initialize using the constructor

Yes! that's what the constructor does.

4. static approach with class name

The purpose of code convention is readability, so I think from that point of view,
if you access static members through class name, you can expressly indicate that you used static members.

I wrote down my thoughts on your question. I'm studying, too, so there might be some mistakes 😅

Comment on lines 78 to 87
void board() {
while(true) {
game();
System.out.println("������ ���� �����Ϸ��� 1,"
+ " �����Ϸ��� 2�� �Է��ϼ��� .");
if(sc.nextInt()==2) {
break;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

게임 진행 여부와 답이 맞는지 판단할 때 do while을 사용해봐도 괜찮을 것 같아. do while을 사용하게 되면 따로 if문 처리 없이 while문의 조건을 통해 제어할 수 있으니까 😉

do {
	game();
	System.out.println("게임을 새로 시작하려면 1, 종료하려면 2를 입력하세요 .");
} while(sc.nextInt()==1)

Comment on lines 5 to 10
RandomNumber(){
this.number = ((int)(Math.random()*9)+1)*100
+((int)(Math.random()*9)+1)*10
+((int)(Math.random()*9)+1);
// System.out.println("���� ���� ="+number);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기능 요구사항에 서로 다른 수로 이루어진 3자리 수 라는 조건이 있는데, 이 코드는 난수를 생성할 때 중복된 수를 제외하는 처리가 안되어있음!

}

boolean judge() {
int i=0,j=0,n,un; //i�� ��Ʈ����ũ, j�� ��
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수가 무엇을 의미하는지 주석보다는 이름을 통해 알 수 있으면 좋을 것 같아

//ù��° �ڸ�
n = number/100;
un = userNumber/100;
if(stringNumber.contains(un+""))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if 안의 내용이 한 줄이어도 가독성을 위해 { } 로 묶어주면 좋을 것 같음

@OHHAKO
Copy link
Member Author

OHHAKO commented Dec 29, 2019

  1. 메서드 분리문제 => 메서드 목적을 한번 더 생각하라
  2. 클래스 분리문제 => OOP 고려해 클래스 분리하라. 작은 규모여도 적용하라
    (Computer,Player,Result 처럼 행동 주체로)
  3. 생성자 사용문제 => 초기 환경설정으로 사용
  4. 정적 클래스 접근 문제 => 정적 클래스의 변수와 메소드 호출할때, 객체이름 보다는 클래스 이름을 사용하는것이 '정적' 사용을 더 명시적으로 나타낸다.

@OHHAKO
Copy link
Member Author

OHHAKO commented Dec 29, 2019

[Code feedback]

  1. 조건 break 대신 do while 처리가 훨씬 clean
  2. 요구사항 '서로다른 수' 조건 반영하기
  3. 변수는 주석보단 이름으로 의미,역할을 나타내기
  4. if조건문에서 실행문이 짧아도 가독성을 위해 { }로 묶기

모두 반영해 commit, push 했습니다!

@jnsorn
Copy link
Contributor

jnsorn commented Jan 2, 2020

  • What is the role of RandomNumber class?
  • It would be good to check all Access Modifier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants