Description: To show how interface, abstract classes works
//Account
public class Account{
private float balance = 0;
public void deposit(float amount) throws IllegalAmountException{
if (amount < 0)
throw new IllegalAmountException();
else
balance +=amount;
}
public float getBalance(){ return balance;}
}
//Campany
public class Company extends LegalEntity{
private String taxNumber;
}
//Hasaddress
interface HasAddress{
public void addAddress(String address);
public String getAddress();
}
//IllegalAmountException
public class IllegalAmountException extends Exception{
private final String strMessage = "Amount is less than the minimum";
public String getMessage(){
return this.strMessage;
}
}
//Legalentity
import java.util.*;
public abstract class LegalEntity implements HasAddress{
private String address;
private String area;
private String registrationDate;
private ArrayList accounts;
public LegalEntity()
{
accounts = new ArrayList();
}
public void addAddress(String address){this.address = address;}
public String getAddress(){return address;}
public void addAccount(Account account)
{
accounts.add(account);
}
public ArrayList returnAccounts()
{
return accounts;
}
}
//person
public class Person extends LegalEntity{
}
//test.java
import java.util.*;
class Test
{
public static void main(String[] args)
{
Test aTest = new Test();
aTest.test();
}
private void test()
{
Person person = new Person();
person.addAddress("123 Surrey Avenue");
System.out.println(person.getAddress());
Account acc = new Account();
try{
acc.deposit(-33);
}
catch(IllegalAmountException e){
System.out.println(e.getMessage());
}
person.addAccount(acc);
Account acc2 = new Account();
try{
acc2.deposit(200);
}
catch(IllegalAmountException e){
System.out.println(e.getMessage());
}
person.addAccount(acc2);
ArrayList it = person.returnAccounts();
Iterator t = it.iterator();
Account anAccount;
float balance;
while(t.hasNext()){
anAccount = (Account) t.next();
balance = anAccount.getBalance();
System.out.println("Balance = " + balance);
}
}
}
Best Projects
Bug Trackingsystem,Books online shopping,college management system,HR management system,Internet banking,Online chat room ,Online exam,Telephone billing system,Banking application,ATM database,airways reservation system,virtual network computing ,calculator,SMTP(simple mail transfer protocol)
Archives
-
▼
2008
(101)
-
▼
June
(32)
- EAR Utility to Compare two EAR files
- J2EE recover(Email Recoverd password)
- Servlet Application
- A CLASS SHOWS HOW
- Back&Fore ground color changer
- Magnifier (VERY NICE)JAR
- Die Roller
- DCSoft DOS Casino
- Card Base Classes
- A Civilisation Game
- Javascript Command Interpreter
- Parellel Port Viewer
- Swing Code to Maintain CD Database
- A Pong Game
- A Basic Game
- Bomber Man
- Logo using Runnable Interface
- Led Digital Clock
- Server Insertion to DB
- File to Array Convertor (JAR file)
- Java Servlet & JDBC Code for Web Development
- Animated Movable Ball
- Beat it Game
- Guessing Game
- Applet game Template.
- SMTP
- Pizza Hut
- Texteditor
- Virtual Network Computing
- GUI For RDBMS
- Calculator
- Smart Mail(Big project)
-
▼
June
(32)
No comments:
Post a Comment