import java.util.Vector;
//244.7
/*
import java.util.*;
class Day {
private String work;
public void set(String work) { this.work = work; }
public String get() { return work;}
public void show() {
if( work == null ) System.out.println("없습니다.");
else System.out.println(work + "입니다.");
}
}
class MonthSchedule {
Day arr[];
Scanner scan = new Scanner(System.in);
public MonthSchedule(int n) {
arr = new Day[n];
}
public void run() {
int a,b;
while(true) {
System.out.print("할일(입력:1, 보기:2, 끝내기:3) >>");
a = scan.nextInt();
if(a == 3) {
finish();
}
else {
System.out.print("날짜(1~30)?");
b = scan.nextInt();
if(a == 1)
input(b);
else
view(b);
}
}
}
public void input(int day) {
String work;
System.out.print("할일(빈칸없이입력)?");
work = scan.next();
arr[day] = new Day();
arr[day].set(work);
System.out.println();
}
public void view(int day) {
System.out.print(day + "일의 할 일은 ");
arr[day].show();
System.out.println();
}
public void finish() {
System.out.print("프로그램을 종료합니다.");
System.exit(0);
}
}
public class Main {
public static void main(String[] args) {
System.out.println("이번달 스케쥴 관리 프로그램.");
MonthSchedule april = new MonthSchedule(30);
april.run();
}
}
import java.util.*;
class PhoneBook{
String tell,name;
public void set(String tell,String name) {
this.tell = tell;
this.name = name;
}
}
class Setting{
PhoneBook arr[];
Scanner scan = new Scanner(System.in);
int length;
public Setting(int n) {
arr = new PhoneBook[n];
length = n;
}
public void input() {
for(int i = 0; i < length; i++) {
System.out.print("이름과 전화번호(이름과 번호는 빈 칸없이 입력)>>");
String name = scan.next(), tell = scan.next();
arr[i] = new PhoneBook();
arr[i].set(tell, name);
}
System.out.println("저장되었습니다...");
scan();
}
public void scan() {
String name;
while(true) {
System.out.print("검색할 이름>>");
name = scan.next();
if(name.equals("그만")) {
stop();
}
else {
scanning(name);
}
}
}
public void scanning(String name) {
for(int i = 0; i < length; i++) {
if(arr[i].name.equals(name)) {
System.out.println(name + "의 번호는 " + arr[i].tell + " 입니다.");
return;
}
}
System.out.println(name + " 이 없습니다.");
}
public void stop() {
System.exit(0);
}
}
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n;
System.out.print("인원수>>");
n = scan.nextInt();
Setting phone = new Setting(n);
phone.input();
}
접근지정자
public protected default private
class Day {
public static int num=0;
private String work;
public void set(String work) { this.work = work; }
public String get() { num++; return work;}
public void show() {
if( work == null ) System.out.println("없습니다.");
else System.out.println(work + "입니다.");
}
public static void setnum() { //static 메소드에서 nonstatic 필드 접근 불가능
//work="work"; //
num++;
}
}
public class Main {
public static void main(String[] args) {
Day d1 = new Day();
Day d2 = new Day();
d1.num=10;
System.out.println(d2.num);
Day.num=10;
System.out.println(Day.num);
}
}
*/
/*
import java.util.*;
class Player {
String PlayerName;
static String word;
public void set(String name) {
PlayerName = name;
}
public void scan() {
static String sum;
Scanner scan = new Scanner(System.in);
sum = scan.next();
}
}
class WordGameApp {
Player arr[];
Scanner scan = new Scanner(System.in);
public void setting(){
System.out.println("끝말잇기 게임을 시작합니다...");
System.out.print("게임에 참가하는 인원은 몇명입니까>>");
int n = scan.nextInt();
arr = new Player[n];
for(int i = 0; i < n; i++) {
System.out.print("참가자의 이름을 입력하세요>>");
String name;
name = scan.next();
arr[i] = new Player();
arr[i].set(name);
Player.word = "아버지";
start();
}
public void start() {
System.out.println("시작하는 단어는 아버지입니다");
int turn = 0;
String word;
while(true) {
System.out.print(arr[turn].PlayerName + ">>");
word = scan.next();
char first = word.charAt(0);
if(first == Player.word.charAt(Player.word.length() - 1)) {
Player.word = word;
}
else {
System.out.print(arr[turn].PlayerName +"이 졌습니다.");
System.exit(0);
}
if(turn == 2) {
turn = 0;
}
else {
turn ++;
}
}
}
}
public class Main {
public static void main(String[] args) {
WordGameApp game = new WordGameApp();
game.setting();
}
}
*/
/*
import java.util.*;
class ArrayUtil{
public static int [] concat(int[] a, int[] b) {
int arr[] = new int[a.length + b.length];
System.arraycopy(a, 0, arr, 0, a.length);
System.arraycopy(b, 0, arr, a.length, b.length);
return arr;
}
public static void print(int[] a) {
System.out.print("[ ");
for(int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
System.out.print("]");
return ;
}
}
public class Main {
public static void main(String [] args) {
int [] array1 = { 1, 5, 7, 9 };
int [] array2 = { 3, 6, -1, 100, 77 };
int [] array3 = ArrayUtil.concat(array1, array2);
ArrayUtil.print(array3);
}
}
super - sub
부모 - 자식
상속
extends
*/
/*
class Person{
int age;
private String name;
void view() {
System.out.println("나이는 "+age+"이고, 이름은 "+name+"입니다.");
}
}
class Student extends Person{
public String school;
private char grade;
void view() { //오버라이딩 덮어쓰기
super.view();
System.out.println("학교는"+school+"이고, 성적은"+grade+"입니다.");
}
}
class Main{
public static void main(String[] args) {
Student s = new Student();
s.view();
}
}
*/
// 예제 5-1
/*
class Point {
private int x,y;
public void set(int x,int y) { // 한점을 구성하는 x, y 자표
this.x = x; this.y = y;
}
public void showPoint() { // 점의 좌표 출력
System.out.println("(" + x + "," + y + ")");
}
}
class ColorPoint extends Point {
private String color;
public void setColor(String color) { // Point를 상속받은 ColorPoint 선언
this.color = color;// 점의 색
}
public void showColorPoint() { // 컬러 점의 좌표 출력
System.out.print(color);
showPoint(); // Point 클래스의 showPoint() 호출
}
}
public class ColorPointEx {
public static void main(String[] args) {
Point p = new Point(); // Point 객체 생성
p.set(1, 2); // Point 클래스의 set() 호출
p.showPoint();
ColorPoint cp = new ColorPoint(); // ColorPoint 객체 생성
cp.set(3, 4);// Point 클래스의 set() 호출
cp.setColor("red"); // ColorPoint 클래스의 setColor() 호출
cp.showColorPoint(); // 컬러와 좌표 출력
}
}
*/
//예제 5-2
/*
class Person {
private int weight; // private 접근 지정. Student 클래스에서 접근 불가
int age; //디폴트 접근 지정. Student 클래스에서 접근 가능
protected int height; //protected 접근 지정. Student 클래스에서 접근 가능
public String name; //public 접근 지정. Student 클래스에서 접근 가능
public void setWeight(int weight) {
this.weight = weight;
}
public int getWeight() {
return weight;
}
}
class Student extends Person {
public void set() {
age = 30; // 슈퍼 클래스의 디폴트 멤버 접근 가능
name = "홍길동"; // 슈퍼 클래스의 public 멤버 접근 가능
height = 175; // 슈퍼 클래스의 protected 멤버 접근 가능
//weight = 99; // 오류.슈퍼 클래스의 privated 멤버 접근 불가
setWeight(99); // private 멤버 weight은 setWeight()으로 간접 접근
}
}
public class InheritanceEx {
public static void main(String[] args) {
Student s = new Student();
s.set();
}
}*/
/*
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
char n = NULL;
int k = 0;
while true() {
}
}
}
생성자 상속 20220907
*/
/*
class Animal{
int height;
public Animal() {
System.out.println("animal constructor");
}
public Animal(int height) {
System.out.println("animal height constructor");
this.height=height;
}
}
class Person extends Animal{
private int age;
public String name;
public Person() {
System.out.println("hi");
}
public Person(int age) {
this.age=age;
}
public Person(String name) {
this.name=name;
}
public Person(int age, String name) {
this.age=age;
this.name=name;
}
public void view() {
System.out.println("나이 : "+age);
System.out.println("이름 : "+name);
}
}
class Student extends Person {
char grade;
public Student() {
System.out.println("hihi");
}
public Student(char grade) {
super(10,"name");
this.grade=grade;
}
}
public class Main{
public static void main(String[] args) {
Student s = new Student('a');
s.view();
}
}
8/
/*
매개변수생성자A30
생성자B
*/
/*
System.out.println("생성자B");
super(10);
|
super(10);
System.out.println("생성자B");
(생성자 최상단 위치시키거나 특정 X)
*/
/*
class Point {
private int x, y; // 한 점을 구성하는 x, y 좌표
public Point() {
this.x = this.y = 0;
}
public Point(int x, int y) {
this.x = x; this.y = y;
}
public void showPoint() { // 점의 자표 출력
System.out.println("(" + x + "," + y + ")");
}
}
class ColorPoint extends Point { // Point를 상속받은 ColorPoint 선언
private String color; // 점의 색
public ColorPoint(int x,int y, String color) {
super(x, y); // Point의 생성자 Point(x, y) 호출
this.color = color;
}
public void showColorPoint() { // 컬러 점의 좌표 출력
System.out.print(color);
showPoint(); // Point 클래스의 showPoint() 호출
}
}
public class Main {
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5, 6, "blue");
cp.showColorPoint();
}
}
*/
/*
class TV {
private int size;
public TV(int size) { this.size = size; }
protected int getSize() { return size; }
}
class ColorTV extends TV {
int color;
public ColorTV(int inch,int color) {
super(inch);
this.color = color;
}
public void printProperty() {
System.out.print(super.getSize() + "인치 " + color + "컬러");
}
}
public class Main {
public static void main(String[] args) {
ColorTV myTV = new ColorTV(32, 1024);
myTV.printProperty();
}
}
추상클래스 abstract :
*/
/*
abstract class TV {
private int size;
public TV(int size) { this.size = size; }
protected int getSize() { return size; }
}
class ColorTV extends TV {
private int color;
public ColorTV(int inch,int color) {
super(inch);
this.color = color;
}
public void printProperty() {
System.out.print(super.getSize() + "인치 " + color + "컬러");
}
}
class IPTV extends ColorTV{
private String IP;
public IPTV(String IP, int inch, int color) {
super(inch, color);
this.IP = IP;
}
public void printProperty() {
System.out.print("나의 IPTV는 " + IP + " 주소의 ");
super.printProperty();
}
}
public class Main {
public static void main(String[] args) {
IPTV iptv = new IPTV("192.1.1.2", 32, 2048);
TV tv = new IPTV("192.1.1.2", 32, 2048);
iptv.printProperty();
}
}
*/
/*
interface PhoneInterface { // 인터페이스 선언
final int TIMEOUT = 10000; // 상수 필드 선언
void sendCall(); // 추상 메소드
void receiveCall(); // 추상 메소드
default void printLogo() { // default 메소드
System.out.println("** Phone **");
}
}
class SamsungPhone implements PhoneInterface { // 인터페이스 구현
// PhoneInterface의 모든 추상 메소드 구현
@Override
public void sendCall() {
System.out.println("띠리리리링");
}
@Override
public void receiveCall() {
System.out.println("전화가 왔습니다.");
}
// 메소드 추가 작성
public void flash() { System.out.println("전화기에 불이 켜졌습니다."); }
}
public class Main
{
public static void main(String[] args) {
SamsungPhone phone = new SamsungPhone();
phone.printLogo();
phone.sendCall();
phone.receiveCall();
phone.flash();
}
}
*/
/*
public abstract class GameObject { // 추상 클래스
protected int distacne;// 한 번 이동 거리
protected int x, y;// 현재 위치(화면 맵 상의 위치)
public GameObject(int startX, int startY, int distance) { // 초기 위치와 이동 거리 설정
this.x = startX;
this.y = startY;
this.distacne = distance;
}
public int getX() { return x; }
public int getY() { return y; }
public boolean collide(GameObject p) { // 이객체가 객체 p와 충돌했으면 true 리턴
if(this.x == p.getX() && this.y == p.getY())
return true;
else
return false;
}
protected abstract void move(); // 이동한 후의 새로운 위치로 x, y 변경
protected abstract char getshape();// 객체의 모양을 나타내는 문자 리턴
}
class Game {
}
*/
/*
class Point {
private int x, y;
public Point(int x, int y) { this.x = x; this.y = y; }
public int getX() { return x; }
public int getY() { return y; }
protected void move(int x, int y) { this.x = x; this.y = y; }
}
class ColorPoint extends Point {
private String color;
public ColorPoint(int x, int y, String color) {
super(x, y);
this.color = color;
}
public void setXY(int x, int y) {
super.move(x, y);
}
public void setColor(String Color) {
this.color = Color;
}
public String toStirng() {
return color + "색의 (" + super.getX() + "," + super.getY() ")의 점";
}
}
public class Main {
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5, 5, "YELLOW");
cp.setXY(10, 20);
cp.setColor("RED");
String str = cp.toStirng();
System.out.println(str + "입니다.");
}
}
*/
/*
import java.util.*;
interface Stack {
int length();
int capacity();
String pop();
boolean push(String val);
}
class StringStack implements Stack {
int len,top = 0;
String stack[];
String word;
public StringStack(int l) {
this.len = l;
stack = new String[l];
}
public int length() {
return this.len;
}
public int capacity() {
return this.len-this.top;
}
public String pop() {
if(top < len)
{
stack[top++] = this.word;
return "yes";
}
else {
return "no";
}
}
public boolean push(String val) {
if(val.equals("그만")) {
System.out.print("스택에 저장된 모든 문자열 팝 :");
while(top > 0) {
System.out.print(" " + stack[--top]);
}
return false;
}
else {
return true;
}
}
}
public class Main {
public static void main(String[] args) {
int size;
String k = "start";
Scanner scan = new Scanner(System.in);
System.out.print("총 스택 저장 공간의 크기 입력 >> ");
size = scan.nextInt();
StringStack stk = new StringStack(size);
while(stk.push(k)) {
System.out.print("문자열 입력 >> ");
k = scan.next();
stk.word = k;
if(!k.equals("그만") && stk.pop().equals("no")) {
System.out.println("스택이 꽉 차서 푸시 불가!");
}
}
}
}
/*
interface Shape {
final double PI = 3.14;
void draw();
double getArea();
default public void redraw() {
System.out.print("--- 다시 그립니다. ");
draw();
}
}
class Circle implements Shape {
public int r;
public Circle(int n) {
this.r = n;
}
@Override
public void draw() {
System.out.println("반지름이 " + r + "인 원입니다.");
}
@Override
public double getArea() {
return r*r*PI;
}
}
public class Main {
public static void main(String[] args) {
Shape donut = new Circle(10);
donut.redraw();
System.out.println("면적은 " + donut.getArea());
}
}
import java.util.*;
abstract class GameObject {
protected int distance;
protected int x, y;
public GameObject(int startX, int startY, int distance) {
this.x = startX;
this.y = startY;
this.distance = distance;
}
public int getX() { return x; }
public int getY() { return y; }
public boolean collide(GameObject p) {
if(this.x == p.getX() && this.y == p.getY())
return true;
else
return false;
}
protected abstract void move();
protected abstract char getShape();
}
class Bear extends GameObject {
char icon;
Scanner scan = new Scanner(System.in);
public Bear(int startX, int startY, int distance, char c) {
super(startX, startY, distance);
this.icon = c;
}
@Override
public void move() {
System.out.print("왼쪽(a), 아래(s), 위(d), 오른쪽(f) >> ");
String dir = scan.next();
if(dir.equals("a") && super.x > 0) {
super.x -= 1;
}
else if(dir.equals("s") && super.y < 9) {
super.y += 1;
}
else if(dir.equals("d") && super.y > 0) {
super.y -= 1;
}
else if(dir.equals("f") && super.x < 19) {
super.x += 1;
}
}
@Override
public char getShape() {
return this.icon;
}
}
class Fish extends GameObject {
char icon;
Scanner scan = new Scanner(System.in);
public Fish(int startX, int startY, int distance, char c) {
super(startX, startY, distance);
this.icon = c;
}
@Override
protected void move() {
int turn = 0, movetime = 0;
turn++;
if(turn > 5) {
turn = 0;
movetime = 0;
}
if(movetime >= 2) {
Random xy = new Random();
int k = xy.nextInt(4)
if(k == 0 && super.x > 0) {
super.x -= 1;
}
else if(k == 1 && super.y < 9) {
super.y += 1;
}
else if(k == 2 && super.y > 0) {
super.y -= 1;
}
else if(k == 3 && super.x < 19) {
super.x += 1;
}
}
}
@Override
protected char getShape() {
return icon;
}
}
public class Main {
public static void main(String[] args) {
Random xy = new Random();
char map[][] = new char[10][20];
char n;
Scanner scan = new Scanner(System.in);
System.out.println("** Bear의 Fish 먹기 게임을 시작합니다. **");
System.out.print("Bear의 아이콘을 입력해 주세요 >> ");
n = scan.next().charAt(0);
Bear 곰 = new Bear(xy.nextInt(20),xy.nextInt(10),xy.nextInt(xy.nextInt(10)),n);
System.out.print("Fish의 아이콘을 입력해 주세요 >> ");
n = scan.next().charAt(0);
Fish 물고기 = new Fish(xy.nextInt(20),xy.nextInt(10),xy.nextInt(xy.nextInt(10)),n);
for(int i = 0; i < 10; i++) {
for(int j = 0; j < 20; j++) {
if(i == 곰.getY() && j == 곰.getX()) {
map[i][j] = 곰.getShape();
}
if(i == 물고기.getY() && j == 물고기.getX()) {
map[i][j] = 물고기.getShape();
}
else {
map[i][j] = '-';
}
}
}
System.out.println();
while(곰.collide(물고기) == false && 물고기.collide(곰) == false) {
for(int i = 0; i < 10; i++) {
for(int j = 0; j < 20; j++) {
System.out.print(map[i][j]);
}System.out.println();
}
n = scan.next().charAt(0);
map[곰.getY()][곰.getY()] = '-';
곰.move();
map[곰.getY()][곰.getY()] = 곰.getShape();
map[물고기.getY()][물고기.getY()] = '-';
물고기.move();
map[물고기.getY()][물고기.getY()] = 물고기.getShape();
}
}
}
*/
/*
class Main{
public static void main(String[] args) {
//Vector<Person> v = new Vector<Person>();
Vector<Integer> v = new Vector<Integer>();
v.add(3);
v.add(1);
v.add(5);
v.add(0);
System.out.println("size : "+ v.size());
System.out.print(">>");
for(int i=0;i<v.size();i++) System.out.print(v.get(i)+" ");
System.out.println();
v.remove(0);
System.out.println("size : "+ v.size());
System.out.print(">>");
for(int i=0;i<v.size();i++) System.out.print(v.get(i)+" ");
System.out.println();
v.add(0,3);
System.out.print(">>");
for(int i=0;i<v.size();i++) System.out.print(v.get(i)+" ");
System.out.println();
//v.clear();
v.remove(Integer.valueOf(5));
System.out.print(">>");
for(int i=0;i<v.size();i++) System.out.print(v.get(i)+" ");
System.out.println();
Integer[] arr = (Integer[])(v.toArray());
/*
System.out.println("size : "+ v.size());
System.out.println(v.capacity());
System.out.println(v.contains(5));
}
}
*/
/*
import java.util.*;
public class Main {
public static void main(String[] args) {
Vector<Integer> rain = new Vector<Integer>();
Scanner scan = new Scanner(System.in);
while(true) {
System.out.print("강수량 입력 (0 입력시 종료) >> ");
int n = scan.nextInt();
if(n==0) break;
rain.add(n);
}
}
}
*/



