Lab2

Lab2 프로젝트 디렉토리 안에 모든 파일(src/*.java & bin/*.class)와 보고서 (2~3장)를 넣고 Lab2_학번_이름.zip 압축한 후 e-learning(http://lms.dankook.ac.kr/index.jsp)으로 제출 ()

Lab2 – Basics (method, for, foreach, if, switch, do/while, while, array 활용)

수업블로그에 2.Basic 안에 TemperatureConverter 클래스 참고하여, 본인이 원하는 Converter 클래스를 추가작성한다 (예시: degree <-> radian 변환, kilometer <-> mile 변환,  kilogram <-> pound 변환, 등등).

http://www.unitconverters.net/

Object-Oriented Programming (OOP)

Object − objects have states and behaviors.
Class – defines the grouping of data and code, the “type” of an object
Instance – a specific allocation of a class
Message – sent to objects to make them act
Method – a “function” that an object knows how to perform
Local Variables − variables defined inside methods, constructors or blocks
Instance Variables – variables within a class but outside any method (a specific piece of data belonging to an object)
Class Variables − variables declared within a class, outside any method, with the static keyword
Encapsulation – keep implementation private and seperate from interface
Polymorphism – different objects, same interface
Inheritance – hierarchical organization, share code, customize or extend behaviors

Lab1

Lab1 프로젝트 디렉토리 안에 모든 파일(src/*.java & bin/*.class)와 보고서 (2~3장)를 넣고 Lab1_학번_이름.zip 압축한 후 e-learning(http://lms.dankook.ac.kr/index.jsp)으로 제출 (10점)

Lab1 – Basics (method, for, foreach, if, switch, do/while, while, array 활용) 코드 분석 보고서 &

(수업블로그에 2.Basic 안에 ArithmeticOperator 클래스 참고하여) 본인이 원하는 method나 routine를 추가 작성한다.

보고서는 출력해서 수업시작 전에 제출한다.

 

getUserInputIntegerBetween

static public int getUserInputIntegerBetween(int min, int max) {
int value = 0;
Scanner scan = new Scanner(System.in);
do {
System.out.printf(“Please enter value [%d-%d]: “, min, max);
try {
value = scan.nextInt();
}
catch (Exception e) {
System.out.printf(“Error! Please re-enter!\n”);
scan.next();
continue;
}
} while (value < min || value > max);
return value;
}

getUserInputDouble using try-catch

static public double getUserInputDouble() {
double value;
Scanner scan = new Scanner(System.in);
while(true) {
try {
value = scan.nextDouble();
break;
}
catch (Exception e) {
System.out.print(“Error! Please re-enter [double value]: “);
scan.next();
}
}
return value;
}