Level1
1) 사각형 만들기
public class Square {
int width;
int height;
public Square(int width, int height) {
this.width = width;
this.height = height;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
public int calculateArea() {
return width*height;
}
}
2) 원 만들기
public class Circle {
int radius;
public Circle(int radius) {
this.radius = radius;
}
public int getRadius() {
return this.radius;
}
public double calculateArea() {
return 3.14*radius*radius;
}
}
3) 아이유 프로필 출력하기
class Person {
String name;
int age;
boolean student;
double weight;
Person(String name, int age, boolean student, double weight) {
this.name = name;
this.age = age;
if (student) {
this.student = true;
} else {
this.student = false;
}
this.weight = weight;
}
void printProfile() {
System.out.println("이름 : " + name);
System.out.println("나이 : " + age);
System.out.println("대학생인가요? : " + student);
System.out.println("몸무게 : " + weight);
}
}
4) 학생들의 국어, 영어 점수 출력하기
import java.util.*;
class Student {
String name = "";
int KoreanScore = 0;
int EnglishScore = 0;
Student(String name, int Korean, int English) {
this.name = name;
this.KoreanScore = Korean;
this.EnglishScore = English;}
String getName() {
return this.name;}
int getKoreanScore() {
return this.KoreanScore;}
int getEnglishScore() {
return this.EnglishScore;}
}
public class Score {
public static void main(String[] args) {
List<Student> students = new ArrayList<Student>();
students.add(new Student("제이슨", 87, 92));
students.add(new Student("레이첼", 82, 92));
students.add(new Student("리사", 92, 88));
for (int i = 0; i < students.size(); i++) {
System.out.println("이름 : " + students.get(i).getName());
System.out.println("국어 : " + students.get(i).getKoreanScore());
System.out.println("영어 : " + students.get(i).getEnglishScore());
}
}
}
5) 계좌 만들기
class Account {
String number;
String name;
double balance;
public Account(){
this.balance=0;
}
public Account(String number, String name) {
this.number = number;
this.name = name;
}
public String getAccountNumber() {
return number;
}
public void deposit(int amount) {
balance += amount;
}
public void withdraw(int amount) {
balance -= amount;
}
public double getBalance() {
return balance;
}
}
6) 아이유 프로필 출력하기2
class Person {
String name;
int age;
boolean student;
double weight;
Person(String name, int age, boolean student, double weight) {
this.name = name;
this.age = age;
if (student) {
this.student = true;
} else {
this.student = false;
}
this.weight = weight;
}
Person(String name, String age, boolean student, String weight) {
this.name = name;
this.age = Integer.parseInt(age);
if (student) {
this.student = true;
} else {
this.student = false;
}
this.weight = Double.parseDouble(weight);
}
Person(String name, int age, boolean student, String weight) {
this.name = name;
this.age = age;
if (student) {
this.student = true;
} else {
this.student = false;
}
this.weight = Double.parseDouble(weight);
}
Person(String name, String age, boolean student, double weight) {
this.name = name;
this.age = Integer.parseInt(age);
if (student) {
this.student = true;
} else {
this.student = false;
}
this.weight = weight;
}
void printProfile() {
System.out.println("이름 : " + name);
System.out.println("나이 : " + age);
System.out.println("대학생인가요? : " + student);
System.out.println("몸무게 : " + weight);
System.out.println("");
}
}
7) 계산기 만들기
class Calculator {
String name;
Calculator(String name){
this.name = name;}
String getOwner() {
return this.name;}
int add(int a, int b) {
return a + b;}
int minus(int a, int b) {
return a - b;}
int multiply(int a, int b) {
return a * b;}
double divide(double a, double b) {
return a / b;}
double divide(String a, String b){
return Double.parseDouble(a) / Double.parseDouble(b);}
}
Class의 의의는 이해한 것 같지만 논리적으로 연결되는 큰 흐름을 파악하는데 아직 많은 시간이 들어서 확신을 가지고 코드를 구현하지 못했다. 다음주에는 아직 듣지 못한 유데미 강의와 자바의 정석으로 다시 공부해서 스터디에서 배운 개념들의 전체적인 틀을 잡아야겠다.
안녕하세요 수현님! 미션 잘 수행해주셨네요😄 그래도 조금씩 클래스에 대해 감을 잡아가시는 것 같아 다행이네요! 블로그에 적어주신 대로 나중에 다시 유데미 강의나 자바의 정석으로 한 번 더 클래스에 대한 개념을 접하시면, 조금은 더 편하게 익히 실 수 있을거에요~!