Notice
Recent Posts
Recent Comments
Link
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

괴발개발 개발하다

[ Java ] 자바 혼자 연습 본문

자바

[ Java ] 자바 혼자 연습

괴발새발개발자 2021. 7. 25. 22:59
package practice_Alone;

import java.util.ArrayList;
import java.util.Scanner;

public class FirstReview {
	
//	public static void printHello() {
//		System.out.println("Hello Hello~!!!! 하하하");

	public static void main(String[] args) {
		//printHello();

//		Scanner sc = new Scanner(System.in);
//		String name = sc.next();
//		int num = sc.nextInt();
//		System.out.println(name + "와" + num);
		
//		Student s2 = new Student(29, "홍길동");
//		System.out.println("나이는 " + s2.getNum()+ ", 이름은 " + s2.getName());
//		s2.setNum(30);
//		s2.setName("룰루");
//		System.out.println("내년에는 나이가 " + s2.getNum() + "이고, 이름은 " + s2.getName());

		Student[] es =new Student [3];
		
		Student s1 = new Student(1, "홍길동");
		Elementary s2 = new Elementary(2, "임꺽정");
		Middle s3 = new Middle(3, "김원봉");
		
		es[0] = s1;
		//es[0] = new Student(2, "최최최");
		es[1] = s2;
		es[2] = s3;
		
		System.out.println(es[1].getName());
		System.out.println(es[2].getNum());
		
		es[1].getupEarly();
		es[2].getupEarly();
		
		//for문
		for(int i = 0; i<es.length; i++) {
			es[i].study();
		}
		
		s1.setScore(100);
		s2.setScore(70);
		s3.setScore(90);
		
		System.out.println(s1.getName() + "의 점수는 " + s1.getScore() + "점");
		
		for(int i = 0; i<es.length; i++) {
			System.out.println(es[i].getName() + "의 점수는 " + es[i].getScore() + "점");
		}
		
		///////////////////////////////////////////////////////////////////
		
		FirstReview fr = new FirstReview();
		ClassA c = new ClassA();
		ClassA ca = new ClassA("박태환");
		
		ca.dec = 70;
		ca.setStr("연습연습연습");
		
		System.out.println(ca.dec);
		System.out.println(ca.getStr());
		
		//////////////////////////////////////////////////////////////////
		//배열 연습
		Student[] sArray = new Student[3];
		sArray[0] = new Student(1, "랄랄");
		sArray[1] = new Student(2, "꾸꾸");
		sArray[2] = new Student(3, "빠빠");
		
		sArray[0].setNum(11);
		sArray[1].setNum(22);
		sArray[2].setNum(33);
		
		for(int i = 0; i<sArray.length; i++) {
			System.out.println(sArray[i].getNum() + "이랑 " + sArray[i].getName());
		}
		
		//향상된 for문
		for(Student s : sArray) {
			System.out.println(s.getNum());
		}
		
		///////////////////////////////////////////////////////////////
		//ArrayList
		
		ArrayList<Student> sList = new ArrayList<Student>();
		Student stu = new Student(1, "ch");
		sList.add(stu);
		sList.add(new Student(2, "갱갱"));
		sList.add(new Student(3, "뿡"));
		
		sList.get(0).setNum(50);
		sList.get(1).setName("미스터");
		sList.get(2).setNum(58);
		
		for(int i = 0; i<sList.size(); i++) {
			System.out.println(sList.get(i).getNum() + " " + sList.get(i).getName());
		}
		
		for(Student s : sList) {
			System.out.println(s.getNum() + " " + s.getName());
		}
		
	}//main

}