JAVA Account Class Assignment
JAVA Account Class Assignment
Section:B
Lab Date:5/3/22
Lab No:03
Lab Work:
Task 1:
Write an Account Class with following features-
Attributes-
Int accountNumber
String accountName
Double accountBalance
Methods-
Void deposit(double money);
//this method will deposit money in the account balance
Double getBalance();
//this method will return current account balance
Void printInfo();
//this method will print all the values of the attributes.
package labworks;
}
double getBalance() {
return accountBalance;
}
void printInfo() {
System.out.println("Account no is"+ accountNumber);
System.out.println("Account name is"+ accountName);
System.out.println("Account balance is"+ accountBalance);
}
}
Task 2:
Write overloaded constructors of the class Accounting as following-
Constructors-
Account();
Account(int id);
Account(String name);
Account(int id,String name);
Account(int id, String name, double initialBalance);
Account(){
accountNumber=-5;
accountName="Anonymous";
accountBalance=-100;
}
Account(int id){
accountNumber=id;
}
Account(String name){
accountName=name;
}
Account(int id,String name){
accountNumber=id;
accountName=name;
}
Account(int id,String name,double initialBalance){
accountNumber=id;
accountName=name;
accountBalance=initialBalance;
}
}
Task 3:
From the main method create five different objects using the above five constructors and
call the printInfo() method once for each of the objects.
package labworks;
Task 4:
Write overloaded methods in the Account class as following-
printInfo(int id);
//it will print: Account number_has balance_
printInfo(String Name)
//it will print: Account name_has balance_
printInfo(int id,String Name)
//it will print: Account number_and Account name_has balance_
package labworks;
}*/
void printInfo(int id){
/*accountNumber=id;*/
/*int accountBalance=108;*/
System.out.println("Account Number "+id+" has balance "+accountBalance);
}
void printInfo(String name){
System.out.println("Account Name "+name+" has balance "+accountBalance);
}
void printInfo(int id,String name){
System.out.println("Account Number "+id+" and "+"Account Name "+name+"
has balance "+accountBalance);
}
/*Account(){
accountNumber=-5;
accountName="Anonymous";
accountBalance=-100;
}
Account(int id){
accountNumber=id;
}
Account(String name){
accountName=name;
}
Account(int id,String name){
accountNumber=id;
accountName=name;
}
Account(int id,String name,double initialBalance){
accountNumber=id;
accountName=name;
accountBalance=initialBalance;
}*/
RunnerForAccount.java:
package labworks;
}
/*Account ac1=new Account();
ac1.printInfo();
Account ac2=new Account(1);
ac2.printInfo();
Account ac3=new Account("Nusrot");
ac3.printInfo();
Account ac4=new Account(11,"Jahan");
ac4.printInfo();
Account ac5=new Account(12,"John",700);
ac5.printInfo();
}*/
}
Output:
Task 5:
Write overloaded method in the Account class as following:
Void deposit (double money,double duePayment);
//it will deposit money after extracting the duePayment from it.
package labworks;
}
double getBalance() {
return accountBalance;
}
void printInfo() {
System.out.println("Account no is"+ accountNumber);
System.out.println("Account name is"+ accountName);
System.out.println("Account balance is"+ accountBalance);
}
void printInfo(int id){
accountNumber=id;
int accountBalance=108;
System.out.println("Account Number "+id+" has balance "+accountBalance);
}
Main Method:
package labworks;
Output: