수직적 확장: 내부 구조를 바꾸는 것이기 때문에 리부팅해야 함
수평적 확장: 컴퓨터 추가하는 것
매트릭: 측정값
cpu사용량이 많으면 늘리고 적으면 자동으로 줄이게 함.
Azure Spot: 종량제나 입찰 등, 24시간 사용에는 부적합.
직렬콘솔 -----
로그인
sudo su
apt update
apt install stress
stress --cpu 1 --timeout 300 & 5분동안 cpu 부하
top cpu 확인
오늘은 VMSS 생성과 Load Balancer 생성을 해봤다. LB 생성 이후 VMSS를 연결하려고 만들다가 진단 스토리지 사용자 계정을 빼먹고 만들었더니 직렬 콘솔에 들어가지지가 않았다... 다시 싹 지우고 만들었더니 됐다ㅎㅎ...
보안 쪽은 이해가 어려워서 그냥 단순하게 들었다. AWS에서 포트로 고생을 좀 했기에 현업에서는 포트 보안을 복잡하게 해서 많이 쓴다는 게 기억에 남았다...
OMG😱 어제 한 번 휘리릭 들었던 걸 자유자재로 쓸 수 있으리라곤 생각 못 했지만... 퀴즈 풀려고 하니까 인터페이스 말곤 생각이 안 났다ㅋㅋㅋ 결국 인터페이스만 써먹어서 풀었다. 음... 내가 생각했던 건 포켓몬처럼 나오게 하는 거였는데, 결과는 내가 원하는 대로 나왔지만 객체 상속을 전혀 못 써먹은 것 같아서 슬펐다... 아무튼 답안 코드를 보니 눈이 번쩍 떠지더랬다. 진짜 게임을 만드는 것만 같아서 재밌었다.
interface Human {
void Walkable(String name, int age, int x, int y);
void Runnable(int x, int y);
void Swimable(int x, int y);
}
class Child implements Human {
private String name;
private int age, x, y;
private int speed = 5;
public void Walkable(String name, int age, int x, int y) {
this.name = name;
this.age = age;
printLoaction();
this.x = x;
this.y = y;
System.out.println(age+"세 "+name+"은(는) 속도 "+speed+", 위치 ("+x+", "+y+")로 걸어간다.");
}
public void Runnable(int x, int y) {
printLoaction();
this.x = x;
this.y = y;
System.out.println(age+"세 "+name+"은(는) 속도 "+(speed+2)+", 위치 ("+x+", "+y+")로 뛰어간다.");
}
public void Swimable(int x, int y) {
printLoaction();
this.x = x;
this.y = y;
System.out.println(age+"세 "+name+"은(는) 속도 "+(speed+1)+", 위치 ("+x+", "+y+")로 수영해서 간다.");
}
public void printLoaction() {
System.out.println(age+"세 "+name+"의 현재 위치는 ("+x+", "+y+") 이다.");
}
}
public class Main {
public static void main(String[] args) {
Child child = new Child();
child.Walkable("자식", 19, 1, 1);
child.Runnable(2, 2);
child.Swimable(3, -1);
}
}
// 19세 자식의 현재 위치는 (0, 0) 이다.
// 19세 자식은(는) 속도 5, 위치 (1, 1)로 걸어간다.
// 19세 자식의 현재 위치는 (1, 1) 이다.
// 19세 자식은(는) 속도 7, 위치 (2, 2)로 뛰어간다.
// 19세 자식의 현재 위치는 (2, 2) 이다.
// 19세 자식은(는) 속도 6, 위치 (3, -1)로 수영해서 간다.
위는 내 엉망진창 코드^^;; 부모 조부모는 생략...
아래는 감탄만 나오는 답안 코드...
public class Human {
String name;
int age;
int speed;
int x, y;
public Human(String name, int age, int speed, int x, int y) {
this.name = name;
this.age = age;
this.speed = speed;
this.x = x;
this.y = y;
}
public Human(String name, int age, int speed) {
this(name, age, speed, 0, 0);
}
public String getLocation() {
return "("+x+", "+y+")";
}
protected void printWhoAmI() {
System.out.println("My name is "+name+", aged "+age+".");
}
}
이렇게 자식, 부모, 조부모 모두 해당하게 되는 클래스 Human을 선언해서 이름, 나이, 속도 그리고 위치를 받는다. 일단 이렇게 크게 선언해 두고,
public class Child extends Human implements Walkable, Runnable, Swimable{
public Child(String name, int age) {
super(name, age, 5);
}
@Override
public void run(int x, int y) {
printWhoAmI();
System.out.println("run speed: " + (speed + 2));
this.x = x;
this.y = y;
System.out.println("ran to " + getLocation());
}
@Override
public void swim(int x, int y) {
printWhoAmI();
System.out.println("swim speed: " + (speed + 1));
this.x = x;
this.y = y;
System.out.println("swam to " + getLocation());
}
@Override
public void walk(int x, int y) {
printWhoAmI();
System.out.println("walk speed: " + speed);
this.x = x;
this.y = y;
System.out.println("walked to " + getLocation());
}
}
위치를 변수로 받는 인터페이스들(해당 되는 것만)과 Human 클래스를 상속받는 Child 클래스를 만든다. 속도는 지정해준다.
부모와 조부모도 해당 되는 인터페이스와 Human 클래스를 상속받아 만들고 속도 지정.
public class Main {
public static void main(String[] args) {
Human child = new Child("자식",19);
Human parents = new Parents("부모",48);
Human grandParents = new GrandParents("조부모",74);
Human[] humans = {grandParents, parents, child};
for (Human human: humans) {
System.out.println(human.name + ", 나이: "+human.age+", 속도: "+human.speed+", 현재 위치: "+human
.getLocation());
}
System.out.println("<활동 시작>");
for (Human human: humans) {
if (human instanceof Walkable){
((Walkable) human).walk(1,1);
System.out.println("------------------");
}
if (human instanceof Runnable){
((Runnable) human).run(2,2);
System.out.println("------------------");
}
if (human instanceof Swimable){
((Swimable) human).swim(3,-1);
System.out.println("------------------");
}
}
}
}
//자식, 나이: 19, 속도: 5, 현재 위치: (0, 0)
//<활동 시작>
//My name is 자식, aged 19.
//walk speed: 5
//walked to (1, 1)
//------------------
//My name is 자식, aged 19.
//run speed: 7
//ran to (2, 2)
//------------------
//My name is 자식, aged 19.
//swim speed: 6
//swam to (3, -1)
//------------------
Human으로 선언해 이름과 나이를 변수로 받고, 배열에 넣어준다.
for-each문을 사용해 각 상세 사항을 출력한다.
한 번 더 for-each문을 사용, instanceof를 사용해서 해당 인터페이스를 상속받는 지 확인 후 출력한다.
오늘은 JAVA 강의에서 앞서 배운 문법들을 복습하는 시간을 가졌다.
자료형에서부터 연산자 그리고 강의에서 가볍게 넘어간 Scanner 클래스?에 대해서 배웠다.
그리고 배열을 그냥 println했을 때 나오는 게 주소값이구나... 찾아볼 생각을 못 했다. 배웠는데 이게 주소값일 줄이야.
자료형 변수명 = 값;
하나의 클래스 안에서는 같은 변수명을 사용할 수 없다.
Scanner scanner = new Scanner(System.in);
System.out.println("나이: ");
int age = scanner.nextInt();
System.out.println("나이는 " + age + "살 입니다.");
System.out.println("주소: ");
scanner.nextLine();
String addr = scanner.nextLine();
System.out.println("주소는 " + addr + "입니다.");
위처럼 하나의 스캐너 변수로 두 번 입력받는 건 팀원분이 소중한 질문을 해주셔서 나도 덩달아 배울 수 있었다. 버퍼 비우기를 해줘야 다음 문자열 값을 입력받을 수 있었다.
참고
이 글로 미루어 보아 age2에서 또 버퍼 비우기를 위해 scanner.nextLine()을 쓰게 되면 거기서 Enter값이 nextInt()에서 인식해 계속 공백?Enter?가 나오는 것 같았다. 여러 번은 못 쓸 듯 싶다😅
Scanner scanner = new Scanner(System.in);
int age, age2;
String addr;
System.out.println("나이: ");
age = scanner.nextInt();
System.out.println("A의 나이는 " + age + "살 입니다.");
System.out.println("주소: ");
scanner.nextLine();
addr = scanner.nextLine();
System.out.println("주소는 " + addr + "입니다.");
System.out.println("age2: ");
age2 = scanner.nextInt();
System.out.println("B의 나이는 " + age2 + "살 입니다.");
scanner.close();