class Rectangle { private double width=1 ; private double height=1; private static String color="white"; public Rectangle(){ } public Rectangle(double w,double h,String c) { width=w; height=h; color=c;} public void setWidth(double width) { this.width=width; } public void setHeight(double height) { this.height=height;} public void setColor(String color) { this.color=color;} public double getWidth() { return width;} public double getHeight() { return height;} public String getColor() { return color;} public double findArea() { return width*height; } } 6666666666666 class TestRectangle { public static void main(String[] args) { Rectangle rect1 = new Rectangle(); Rectangle rect2 = new Rectangle(10,5.8,"red"); rect1.setWidth(12); rect1.setHeight(5.5); rect1.setColor("yellow"); System.out.println("ract1 Width ="+rect1.getWidth()+ " Height ="+rect1.getHeight()+ " Color="+rect1.getColor()); System.out.println("ract2 Width ="+rect2.getWidth(); " Height ="+rect2.getHeight()+ " Color="+rect2.getColor()); System.out.println("Area of rect1 ="+ rect1.findArea()); System.out.println("Area of rect2 ="+ rect2.findArea()); } } ................. class Account { protected double balance; public Account(double amount){ this.balance=amount;} public void deposit(double amount){ this.balance+=amount;} public boolean withdraw(double amount) {if (amount<=balance) {balance-=amount; return true; } else return false;} public void showBalance() {System.out.println("Balance is"+balance);} public double getBalance() {return balance;} } .................. class Teller { public static void main(String[] args) { Account acc=new Account(5000); acc.deposit(2000); acc.showBalance();//balance 7000 acc.withdraw(4000); acc.showBalance();//balance 3000 acc.withdraw(8000); acc.showBalance();//balance 3000 acc.withdraw(2000); acc.showBalance();////balance 1000 acc=new CheckingAccount(10000,5000);//Check acc.withdraw(12000); acc.showBalance();//balance -2000 } } ................ class CheckingAccount extends Account { private double credit; public CheckingAccount (double amount,double credit) { super(amount); this.credit=credit;} public boolean withdraw(double amount) { if (amount<=(balance+credit)) { balance=balance-amount; return true; } else return false; } }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง