Java問題1(国別コース)
4966 ワード
1. TV
package TV;
public class TV {
private int size;
public TV(int size) { this.size = size; }
protected int getSize() { return size; }
}
package TV;
public class ColorTV extends TV{
private int color;
public ColorTV(int size, int color) {
super(size);
this.color = color;
}
protected int getColor() {
return color;
}
public void printProperty() {
System.out.println(getSize()+"인치 "+color+"컬러");
}
}
import TV.ColorTV;
public class ex01 {
public static void main(String[] args) {
ColorTV myTV = new ColorTV(32, 1024);
myTV.printProperty();
}
}
package TV;
public class IPTV extends ColorTV{
String ipAddr;
public IPTV(String ipAddr, int size, int color) {
super(size, color);
this.ipAddr =ipAddr;
}
@Override
public void printProperty() {
System.out.println("나의 IPTV는 "+ipAddr+"주소의 "+getSize()+"인치 "+getColor()+"컬러");
}
}
import TV.IPTV;
public class ex02 {
public static void main(String[] args) {
IPTV iptv = new IPTV("192.1.1.2", 32, 2048);
iptv.printProperty();
}
}
2. Converter
package Converter;
import java.util.Scanner;
abstract public class Converter {
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.println(getSrcString()+"을"+getDestString()+"로 바꿉니다");
System.out.print(getSrcString()+"을 입력하세요 >> ");
double val = scanner.nextDouble();
double res = convert(val);
System.out.println("변환 결과 : "+res+getDestString()+"입니다");
scanner.close();
}
}
package Converter;
public class Won2Dollar extends Converter{
private int dollar;
public Won2Dollar(int dollar) {
this.dollar = dollar;
}
@Override
protected double convert(double src) {
return src/dollar;
}
@Override
protected String getSrcString() {
return "원";
}
@Override
protected String getDestString() {
return "달러";
}
}
import Converter.Won2Dollar;
public class ex03 {
public static void main(String[] args) {
Won2Dollar toDollar = new Won2Dollar(1200);
toDollar.run();
}
}
package Converter;
public class Km2Mile extends Converter{
private double mile;
public Km2Mile(double mile) {
this.mile = mile;
}
@Override
protected double convert(double src) {
return src/mile;
}
@Override
protected String getSrcString() {
return "Km";
}
@Override
protected String getDestString() {
return "mile";
}
}
import Converter.Km2Mile;
public class ex04 {
public static void main(String[] args) {
Km2Mile toMile = new Km2Mile(1.6);
toMile.run();
}
}
3. Point
package Point;
public 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;}
}
package Point;
public class ColorPoint extends Point{
private String color;
public ColorPoint() {
super(0,0);
this.color = "BLACK";
}
public ColorPoint(int x, int y) {
super(x,y);
this.color = "BLACK";
}
public ColorPoint(int x, int y, String color) {
super(x, y);
this.color = color;
}
public void setXY(int x, int y) {
move(x, y);
}
public void setColor(String color) {
this.color = color;
}
@Override
public String toString() {
return color+"색의 ("+getX()+","+getY()+")의 점";
}
}
import Point.ColorPoint;
public class ex05 {
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5, 5, "YELLOW");
cp.setXY(10, 20);
cp.setColor("RED");
String str = cp.toString();
System.out.println(str+"입니다");
}
}
4. Stack
Reference
この問題について(Java問題1(国別コース)), 我々は、より多くの情報をここで見つけました
https://velog.io/@ansalstmd/자바문제1국비과정-ozirqo98
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
package TV;
public class TV {
private int size;
public TV(int size) { this.size = size; }
protected int getSize() { return size; }
}
package TV;
public class ColorTV extends TV{
private int color;
public ColorTV(int size, int color) {
super(size);
this.color = color;
}
protected int getColor() {
return color;
}
public void printProperty() {
System.out.println(getSize()+"인치 "+color+"컬러");
}
}
import TV.ColorTV;
public class ex01 {
public static void main(String[] args) {
ColorTV myTV = new ColorTV(32, 1024);
myTV.printProperty();
}
}
package TV;
public class IPTV extends ColorTV{
String ipAddr;
public IPTV(String ipAddr, int size, int color) {
super(size, color);
this.ipAddr =ipAddr;
}
@Override
public void printProperty() {
System.out.println("나의 IPTV는 "+ipAddr+"주소의 "+getSize()+"인치 "+getColor()+"컬러");
}
}
import TV.IPTV;
public class ex02 {
public static void main(String[] args) {
IPTV iptv = new IPTV("192.1.1.2", 32, 2048);
iptv.printProperty();
}
}
package Converter;
import java.util.Scanner;
abstract public class Converter {
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.println(getSrcString()+"을"+getDestString()+"로 바꿉니다");
System.out.print(getSrcString()+"을 입력하세요 >> ");
double val = scanner.nextDouble();
double res = convert(val);
System.out.println("변환 결과 : "+res+getDestString()+"입니다");
scanner.close();
}
}
package Converter;
public class Won2Dollar extends Converter{
private int dollar;
public Won2Dollar(int dollar) {
this.dollar = dollar;
}
@Override
protected double convert(double src) {
return src/dollar;
}
@Override
protected String getSrcString() {
return "원";
}
@Override
protected String getDestString() {
return "달러";
}
}
import Converter.Won2Dollar;
public class ex03 {
public static void main(String[] args) {
Won2Dollar toDollar = new Won2Dollar(1200);
toDollar.run();
}
}
package Converter;
public class Km2Mile extends Converter{
private double mile;
public Km2Mile(double mile) {
this.mile = mile;
}
@Override
protected double convert(double src) {
return src/mile;
}
@Override
protected String getSrcString() {
return "Km";
}
@Override
protected String getDestString() {
return "mile";
}
}
import Converter.Km2Mile;
public class ex04 {
public static void main(String[] args) {
Km2Mile toMile = new Km2Mile(1.6);
toMile.run();
}
}
3. Point
package Point;
public 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;}
}
package Point;
public class ColorPoint extends Point{
private String color;
public ColorPoint() {
super(0,0);
this.color = "BLACK";
}
public ColorPoint(int x, int y) {
super(x,y);
this.color = "BLACK";
}
public ColorPoint(int x, int y, String color) {
super(x, y);
this.color = color;
}
public void setXY(int x, int y) {
move(x, y);
}
public void setColor(String color) {
this.color = color;
}
@Override
public String toString() {
return color+"색의 ("+getX()+","+getY()+")의 점";
}
}
import Point.ColorPoint;
public class ex05 {
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5, 5, "YELLOW");
cp.setXY(10, 20);
cp.setColor("RED");
String str = cp.toString();
System.out.println(str+"입니다");
}
}
4. Stack
Reference
この問題について(Java問題1(国別コース)), 我々は、より多くの情報をここで見つけました
https://velog.io/@ansalstmd/자바문제1국비과정-ozirqo98
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
package Point;
public 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;}
}
package Point;
public class ColorPoint extends Point{
private String color;
public ColorPoint() {
super(0,0);
this.color = "BLACK";
}
public ColorPoint(int x, int y) {
super(x,y);
this.color = "BLACK";
}
public ColorPoint(int x, int y, String color) {
super(x, y);
this.color = color;
}
public void setXY(int x, int y) {
move(x, y);
}
public void setColor(String color) {
this.color = color;
}
@Override
public String toString() {
return color+"색의 ("+getX()+","+getY()+")의 점";
}
}
import Point.ColorPoint;
public class ex05 {
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5, 5, "YELLOW");
cp.setXY(10, 20);
cp.setColor("RED");
String str = cp.toString();
System.out.println(str+"입니다");
}
}
Reference
この問題について(Java問題1(国別コース)), 我々は、より多くの情報をここで見つけました https://velog.io/@ansalstmd/자바문제1국비과정-ozirqo98テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol