public class App4 {
public static void main(String[] args) {
// 실행할 코드
iPhone iphone = new iPhone();
iphone.call("010-5556-8614");
iphone.lock();
iphone.call("119");
iphone.unlock();
iphone.call("112");
}
}
abstract class SmartPhone{
// 전화 걸기
abstract void call(String number);
// 잠금 기능
abstract void lock();
// 잠금 해체
abstract void unlock();
}
// Ctrl + .
class iPhone extends SmartPhone{
Scanner sc = new Scanner(System.in);
private boolean locked = false;
private int pin;
@Override
void call(String number) {
if(locked == false){
System.out.println("calling on iPhone : " + number);
}
else{
System.out.println("Message : Unlock first!");
}
}
@Override
void lock() {
if(locked == false){
System.out.println("Input Password : ");
pin = sc.nextInt();
locked = true;
}
else{
System.out.println("Phone is already locked!");
}
}
@Override
void unlock() {
if(locked == true){
System.out.println("PIN: ");
int input = sc.nextInt();
if(input == pin){
System.out.println("Correct PIN!");
locked = false;
}
else{
System.out.println("Wrong PIN! Try Again!");
}
}
else{
System.out.println("Phone is already unlocked!");
}
}
}
public class App5 {
public static void main(String[] args) {
AirAttacker atk = new AirAttacker();
atk.attack("Player");
atk.fly(10, 5, 6);
}
}
interface Flyable{
void fly(int x, int y, int z);
}
interface Moveable{
void move(int x, int y);
}
interface Attackable{
void attack(String target);
}
abstract class Unit{
int hp;
int mp;
int exp;
Unit(int hp, int mp, int exp){
this.hp = hp;
this.mp = mp;
this.exp = exp;
}
abstract void attacked(int damage);
abstract void defeated();
}
interface FlyAttacker extends Flyable, Attackable{
abstract void airToground();
}
class AirAttacker implements Flyable, Attackable{
@Override
public void attack(String target) {
System.out.println("Attack on : " + target);
}
@Override
public void fly(int x, int y, int z) {
System.out.println("Move to : " + x + y + z);
}
}
class Dragon extends Unit implements FlyAttacker{
Dragon(int hp, int mp, int exp) {
super(hp, mp, exp);
//TODO Auto-generated constructor stub
}
@Override
public void attack(String target) {
// TODO Auto-generated method stub
}
@Override
public void fly(int x, int y, int z) {
// TODO Auto-generated method stub
}
@Override
void attacked(int damage) {
// TODO Auto-generated method stub
}
@Override
void defeated() {
// TODO Auto-generated method stub
}
@Override
public void airToground() {
// TODO Auto-generated method stub
}
}