Code&Data Insights

[JAVA] Lab Review (1,2) 본문

Algorithm

[JAVA] Lab Review (1,2)

paka_corn 2022. 1. 29. 03:29

 

 

2022.01.28

 

 

# Lab 1 - 클래스, 인스턴트 생성

 

 

Q)

(1) Matching 클래스 만들기 

    attributes - String firstWord / String secondWord / Int count 

 

(2) constructors와 method 생성하기 

  - private void match() method : firstWord와 secondWord에 담긴 공통 글자수 세기, count attribute 수정 

                                                         이 method는 모든 constructors에서 부를 수 있어야 한다. 

    

     - default constructor : firstWord&secondWord = null / count = 0 로 세팅한다 

 

     -  copy constructor 

 

     -  constructor : 3 arguments를 가지고 그에 맞는 parameters을 패스한다.

 

     -  Mutator and accessor methods

 

     - equals() method 

 

     - toString() method

 

 

 

---------------------------------------

 

 

 

A)

(1) Matching 클래스 만들기 

   

 

(2) constructors와 method 생성하기 

  - private void match() method : firstWord와 secondWord에 담긴 공통 글자수 세기, count attribute 수정 

                                                         이 method는 모든 constructors에서 부를 수 있어야 한다. 

 

단어의 글자 수가 다를 수 있으므로, 먼저 어떤 단어가 긴지 비교 후 length를 정한다. charAt(index)로 같은 캐릭터가 있는지 비교한다. 

    

     - default constructor : firstWord&secondWord = null / count = 0 로 세팅한다 

 

     -  copy constructor

 

     -  constructor : 3 arguments를 가지고 그에 맞는 parameters을 패스한다.

 

     -  Mutator and accessor methods

 

 

     - equals() method 

 

     - toString() method

 

 - driver(instance설정 후 output) 

결과는 toString의 return 문장과 count는 2개

 

 

 

 

*******

---> 아직 equals()로 객체를 비교하는 개념이 헷갈린다. 

 

https://edu.goorm.io/learn/lecture/41/%EB%B0%94%EB%A1%9C%EC%8B%A4%EC%8A%B5-%EC%83%9D%ED%99%9C%EC%BD%94%EB%94%A9-%EC%9E%90%EB%B0%94-java/lesson/39244/equals

 

 

 

 

 

# Lab 2

 

 

Q)

(1) Sphere 클래스 생성 

    attributes - double radius

 

(2) constructors & method 생성

 

     - default constructor: one parameter for radius r.

 

     -  copy constructor 

 

     -  Mutator and accessor methods

 

     - equals() method : return true if objects have the same radius.

 

     -  getArea() method :  구의 면적을 계산 ( Area = 4 * radius * radius * Math.PI )

 

     - toString() method: return radius and the area of the object.

 

     -  Static getTotalArea() method :  array of shperes를 인풋으로 받고, 전체 array안의 object의 총 면적을 계산한다.

 

     -  Driver method:  three instances of the sphere class to demonstrate the correctness of implementation.

 

 

 

 

 

---------------------------------------

 

 

 

 

 

A)

(1) Sphere 클래스 생성 

    attributes - double radius

 

 

 

(2) constructors & method 생성

 

     - default constructor: one parameter for radius r.

 

     -  copy constructor 

 

     -  Mutator and accessor methods

 

     - equals() method : return true if objects have the same radius.

 

     -  getArea() method :  구의 면적을 계산 ( Area = 4 * radius * radius * Math.PI )

 

     -  toString() method: return radius and the area of the object.

 

 

     -  Static getTotalArea() method :  array of shperes를 인풋으로 받고, 전체 array안의 object의 총 면적을 계산한다.

 

     -  Driver method:  three instances of the sphere class to demonstrate the correctness of implementation.

 

 

 

 

 

Comments