public class MyDate {
private boolean valid = true;
private int day;
private int month;
private int year;
public int getDay() {
return day;
}
public void setDay(int day) {
if(day > 31 || day <1)
valid = false;
else
{
this.day = day;
}
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
if(month > 12 || month <1)
valid = false;
else
{
this.month = month;
}
}
public int getYear() {
return year;
}
public void setYear(int year) {
if(year > 3000 || year <2000)
valid = false;
else
{
this.year = year;
}
}
public MyDate(int day,int month, int year)
{
setDay(day);
setMonth(month);
setYear(year);
}
public boolean isValid()
{
return valid;
}
}
public class Main {
public static void main(String[] args) {
MyDate date = new MyDate(31,11,2001);
if(date.isValid())
System.out.println("유효");
else
System.out.println("불가");
date.setDay(20);
date.setMonth(13);
date.setYear(200);
if(date.isValid())
System.out.println("유효");
else
System.out.println("불가");
}
}
public class Cafe {
int price;
int money;
String name;
int count;
public Cafe(String name, int price)
{
money = 0;
count = 0;
this.name = name;
this.price = price;
}
public void getmoney() {
money += this.price;
count++;
}
public void showCafe()
{
System.out.println("카페 이름 :"+name);
System.out.println("이용 고객 :"+count);
System.out.println("매출 :"+money);
}
}
public class Customer {
String name;
int money;
public Customer(String name, int money){
this.name = name;
this.money = money;
}
public void take(Cafe cafe)
{
this.money -= cafe.price;
cafe.getmoney();
}
public void showMetheMoney()
{
System.out.println(name+"의 잔액은 "+money +" 입니다.");
}
}
public class Main2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Cafe cafeb = new Cafe("별다방",4500);
Cafe cafaa = new Cafe("달다방",5000);
Customer per = new Customer("이무",20000);
per.take(cafaa);
per.take(cafeb);
per.take(cafeb);
per.showMetheMoney();
cafaa.showCafe();
cafeb.showCafe();
}
}
'Java' 카테고리의 다른 글
static method (0) | 2019.10.26 |
---|---|
Static & Singleton (0) | 2019.10.26 |
this 응용 (0) | 2019.10.25 |
정보 은닉. (0) | 2019.10.25 |
생성자 객체 & 인스턴스 오버로딩. (0) | 2019.10.25 |