Compare commits
2 Commits
55abafec70
...
504ce3feaf
| Author | SHA1 | Date |
|---|---|---|
|
|
504ce3feaf | |
|
|
0711f71b4d |
|
|
@ -1,2 +1,5 @@
|
||||||
/ppl/
|
/mana/
|
||||||
|
/User/
|
||||||
|
/a/
|
||||||
/ver/
|
/ver/
|
||||||
|
/java/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
package User;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class management {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
user[] users= new user[10];
|
||||||
|
int index=0;
|
||||||
|
Scanner s=new Scanner(System.in);
|
||||||
|
|
||||||
|
while(true){
|
||||||
|
System.out.println("1.사용자추가 2.사용자정보3.사용자삭제4.종료");
|
||||||
|
System.out.println("몇번?:");
|
||||||
|
int a=s.nextInt();
|
||||||
|
System.out.println("입력한 정수 : " + a);
|
||||||
|
int choice =s.nextInt();
|
||||||
|
if(choice == 1) {
|
||||||
|
user u= new user();
|
||||||
|
u.name= s.next();
|
||||||
|
u.age=s.nextInt();
|
||||||
|
|
||||||
|
users[index]=u;
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
if(choice==4) {
|
||||||
|
s.close();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
// 무한반복
|
||||||
|
// 메뉴 1. 사용자 정보
|
||||||
|
// 2. 사용자 추가
|
||||||
|
// 3. 사용자 삭제
|
||||||
|
// 4. 사용자 정보
|
||||||
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package User;
|
||||||
|
|
||||||
|
public class user {
|
||||||
|
|
||||||
|
String name;
|
||||||
|
int age;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package a;
|
||||||
|
|
||||||
|
import ver.Rectangle;
|
||||||
|
|
||||||
|
public class Circle extends Triangle{
|
||||||
|
protected int radius;
|
||||||
|
|
||||||
|
public void draw(){
|
||||||
|
System.out.println("반지름 " + radius);
|
||||||
|
Rectangle r = new Rectangle();
|
||||||
|
int cHeight = r.height; // 정상
|
||||||
|
Triangle t = new Triangle(); // 정상
|
||||||
|
// cHeight = t.height; // 오류
|
||||||
|
// cHeight = height; // 오류
|
||||||
|
int cWidth = t.width; // 정상
|
||||||
|
cWidth = width; // 정상
|
||||||
|
int width = t.width; // 정상
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
package a;
|
||||||
|
|
||||||
|
import ver.Rectangle;
|
||||||
|
|
||||||
|
class Triangle {
|
||||||
|
protected int width;
|
||||||
|
private int height;
|
||||||
|
|
||||||
|
public void draw(){
|
||||||
|
System.out.println("가로 " + width + ", 세로 " + height);
|
||||||
|
Rectangle r = new Rectangle();
|
||||||
|
int height = r.height; // 정상
|
||||||
|
System.out.println("높이 " + height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
package java;
|
||||||
|
|
||||||
|
|
||||||
|
public class Circle extends Shape implements Drawing {
|
||||||
|
|
||||||
|
protected int r;
|
||||||
|
|
||||||
|
public Circle() {
|
||||||
|
r = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Circle(int r) {
|
||||||
|
this.r = r;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double area() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return Math.PI * r * r;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int draw() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
System.out.println(title + " : 원을 그립니다.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
package java;
|
||||||
|
|
||||||
|
//public interface Drawing {
|
||||||
|
interface Drawing {
|
||||||
|
public String title = "그리는 인터페이스 입니다.";
|
||||||
|
public int draw();
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package java;
|
||||||
|
|
||||||
|
//public class Line {
|
||||||
|
public class Line extends Shape {
|
||||||
|
|
||||||
|
protected int startX;
|
||||||
|
|
||||||
|
public Line() {
|
||||||
|
startX = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Line(int startX) {
|
||||||
|
this.startX = startX;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double area() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return startX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int draw() {
|
||||||
|
// System.out.println(title + " : 원을 그립니다."); // 오류, 인터페이스를 선언하지 않았다.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
package java;
|
||||||
|
|
||||||
|
public class Rectangle extends Shape implements Drawing {
|
||||||
|
|
||||||
|
protected int x, y;
|
||||||
|
|
||||||
|
public Rectangle() {
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rectangle(int x, int y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double area() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return x * y;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int draw() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
System.out.println(title + " : 사각형을 그립니다.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
|
||||||
|
public class Scatchbook {
|
||||||
|
private String name;
|
||||||
|
private Drawing[] drawList; // 배열은 크기를 동적으로 조절하기가 힘들다. Chap23, 24 제네릭과 컬렉션을 통해 동적으로 크기를 조정하는 것을 배우게 된다.
|
||||||
|
|
||||||
|
public Scatchbook(String name, int size) {
|
||||||
|
this.name = name;
|
||||||
|
this.drawList = new Drawing[size];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDrawing(Drawing d){
|
||||||
|
for(int index = 0; index < drawList.length; index++){
|
||||||
|
if(drawList[index] == null) {
|
||||||
|
drawList[index] = d;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public void draw(){
|
||||||
|
for(Drawing d : drawList) System.out.println(d.draw());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String args[]) {
|
||||||
|
Scatchbook scatchbook = new Scatchbook("SWH아카데미 스케치북", 2);
|
||||||
|
Circle circle = new Circle(5000);
|
||||||
|
Line line = new Line(5);
|
||||||
|
Rectangle rectangle = new Rectangle();
|
||||||
|
|
||||||
|
scatchbook.addDrawing(circle);
|
||||||
|
scatchbook.addDrawing(rectangle);
|
||||||
|
// scatchbook.addDrawing(line); // 컴파일 오류
|
||||||
|
scatchbook.draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package java;
|
||||||
|
|
||||||
|
public abstract class Shape {
|
||||||
|
protected int x, y;
|
||||||
|
|
||||||
|
public abstract double area();
|
||||||
|
public void move(int x1, int y1) {
|
||||||
|
x += x1;
|
||||||
|
y += y1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
package mana;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
String name;
|
||||||
|
int age;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
package mana;
|
||||||
|
|
||||||
|
public class UserManagement {
|
||||||
|
|
||||||
|
private User[] list;
|
||||||
|
|
||||||
|
public void init(){
|
||||||
|
list = new User[10];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(User u){
|
||||||
|
list[0] = u;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void insert(int index, User u){
|
||||||
|
list[index] = u;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(String name, int age, String id){
|
||||||
|
User u = new User();
|
||||||
|
((Object) u).setAge(age);
|
||||||
|
list[0] = u;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User modify(int index, User u){
|
||||||
|
list[index] = u;
|
||||||
|
return list[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void view(){
|
||||||
|
User u = list[0];
|
||||||
|
System.out.println("이름: " + u.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
// 무한반복
|
||||||
|
// 메뉴 1. 사용자 정보
|
||||||
|
// 1.1. 사용자 추가
|
||||||
|
// 1.2. 사용자 삭제
|
||||||
|
// 1.3. 사용자 정보
|
||||||
|
|
||||||
|
UserManagement mnt = new UserManagement();
|
||||||
|
mnt.init();
|
||||||
|
mnt.add("코야", 8, "123");
|
||||||
|
|
||||||
|
User k = new User ();
|
||||||
|
mnt.modify(0, k);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,27 @@
|
||||||
|
package mana;
|
||||||
|
|
||||||
|
|
||||||
|
public class mana {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private int age;
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
public mana(String name, String id){
|
||||||
|
this.id = id;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
public void setAge(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
package mana;
|
||||||
|
|
||||||
|
public class managemunt {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -1,7 +0,0 @@
|
||||||
package ver;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in New Issue