목록JAVA (194)
WON.dev
package org.joonzis.ex; class Car{ void move() { System.out.println("움직인다."); } } class Ev extends Car{ void charging() { System.out.println("전기를 충전한다."); } } public class Ex03_Inheritance { public static void main(String[] args) { Ev ev = new Ev(); ev.charging(); ev.move(); } }
package org.joonzis.ex; class Person{ void sleep() { System.out.println("잔다"); } void eat(String food) { System.out.println(food + "먹는다"); } } class Student extends Person{ void study() { System.out.println("공부한다."); } } class Worker extends Person{ void work() { System.out.println("일한다."); } } public class Ex02_Inheritance { public static void main(String[] args) { Student stu = new Student(); ..
package org.joonzis.ex; // 부모 클래스 class Parent{ int number; void doParent() { System.out.println("doParent() 호출"); } } // 자식 클래스 class Child extends Parent{ void doChild() { System.out.println("doChild() 호출"); } } public class Ex01_Inheritance { public static void main(String[] args) { Child child = new Child(); child.number = 10; System.out.println(child.number); child.doParent(); child.doChild..
Q1. Test01.java 랜덤을 이용하여 로또 만들기. - 임의의 값 6개(중복 제거), 입력받는 값 6개를 비교하여 맞는 개수와 해당 번호를 출력 * 로또 및 선택 번호는 1~45 사이의 값 1. 임의의 값 6를 배열에 담는다(랜덤 이용) 2. 내가 선택한 값 6개를 배열에 담는다 (스캐너 이용) 3. 로또 번호 : 배열 내용 출력 4. 선택 번호 : 배열 내용 출력 5. 맞은 개수 : OO개 6. 맞은 번호 : 내용 나열 package org.joonzis.test; import java.util.Arrays; import java.util.Random; import java.util.Scanner; public class Test01 { public static void main(String[]..
package org.joonzis.ex; import java.util.Random; public class Ex01_Random { public static void main(String[] args) { /* * Random 클래스 * 1. 객체(인스턴스) 생성을 한다. * 2. 객체(인스턴스)의 메소드 호출로 난수를 발생시킨다. * 1) nextInt(): int 형 범위 내의 난수 발생 * 2) nextBoolean(): true or false * 3) nextLong(): long형 범위 내의 난수 발생 * 4) nextFloat(): 0 ~ 0.9999까지의 난수 발생(0이상 ~ 1미만) * 5) nextDouble(): 0 ~ 0.9999까지의 난수 발생(0이상 ~ 1미만) */ Rand..
Q1. Cricle.java - 필드 : double radius - 메소드 : Constructor, calcArea, output CricleMain.javaCircle 3개 생성 (반지름 입력 받아서 처리), 가장 크기가 큰 Circle 출력 ★ calcArea => Math.PI * Math.pow(radius, 2) output => 반지름, 크기 출력 Q2. Song.java- 필드 : String title, String country - 메소드 : Constructor, output Singer.java- 필드 : String name, Song[] songList(Song의 객체 n개를 메인으로부터 받아서 처리), int idx(배열 인덱스에 접근용도) - 메소드 : Constructor..
package org.joonzis.ex; public class Ex03_Student { String name, dept, score1, score2; double average; boolean isPass; public Ex03_Student() {} public Ex03_Student(String name, String dept, String score1, String score2) { this.name = name; this.dept = dept; this.score1 = score1; this.score2 = score2; this.average = getAverage(); this.isPass = getPass(); } double getAverage() { return (Double.par..
package org.joonzis.ex; public class Ex02_Triangle { int width, height; public Ex02_Triangle() {} public Ex02_Triangle(int width, int height) { this.width = width; this.height = height; } double calcArea() { return width * height / 2.0; } void output() { System.out.println("너비 : " + width); System.out.println("높이 : " + height); System.out.println("크기 : " + calcArea()); } } package org.joonzis.ex..
package org.joonzis.ex; public class Ex01_Person { // 필드 String name; int age; double height; char gender; public Ex01_Person() {} public Ex01_Person(String name, int age, double height, char gender) { this.name = name; this.age = age; this.height = height; this.gender = gender; } void output() { System.out.println("이름 : " + name); System.out.println("나이 : " + age); System.out.println("키 : " + h..
package org.joonzis.ex; public class Ex03_Team { // 필드 String name; static int count = 0;// 모든 팀원들이 공유하는 자원 public Ex03_Team(String name) { this.name = name; count++; } void output() { System.out.println("이름 : " + name); System.out.println("현재 팀원 : " + count + "명"); } } package org.joonzis.ex; public class Ex03_TeamMain { public static void main(String[] args) { Ex03_Team member1 = new Ex03_Team..