SlideShare a Scribd company logo
ASSIGNMENT 7
MUHAMMAD MUZZAMMIL BIN JUSOF
1417299
SECTION 5
DR. ALI ALWAN
Q1: What is the output of running class C?
class A {
public A () {
System.out.println(“A’s no-arg constructor is invoked”);
}
}
class B extends A {
}
public class C {
public static void main (String [] args ) {
B b = new B ();
}
}
Answer :
A’s no-arg constructor is invoked
Q2: True/ false
1. When invoking a constructor from a subclass, its superclass’s no-arg constructor is
always invoked.
2. You can override a private method defined in a superclass.
3. You can override a static method defined in a superclass.
4. You can always successfully cast an instance of a subclass to a superclass
5. You can always successfully cast an instance of a superclass to a subclass.
6. A protected method can be accessedby any class in the same package.
7. A protected method can be accessedby its subclasses in any package.
8. A final class can be extended.
9. A final method can be overridden
Answer :
1) False
2) False
3) True
4) True
5) False
6) False
7) True
8) False
9) False
Q3: Explain the difference between method overloading and method overriding.
Answer :
Method overloading is used to increase the readability of the program. Method overriding is
used to provide the specific implementation of the method that is already provided by its super
class. Method overloading is performed within class. Method overriding occurs in two
classes that have IS-A (inheritance) relationship. In case of method overloading, parameter
must be different. In case of method overriding, parameter must be same. Method overloading
is the example of compile time polymorphism. Method overriding is the example of run time
polymorphism. In java, method overloading can't be performed by changing return type of the
method only. Return type can be same or different in method overloading. But you must have
to change the parameter. Return type must be same or covariant in method overriding.
Q4: Show the output of the following code:
public class Test {
public static void main (String [] args) {
new Person().printPerson();
new Student().printPerson();
}
}
class Student extends Person {
@Override
public String getInfo() {
return “Student”;
}
}
class Person {
public String getInfo() {
return “Person”;
}
public void printPerson() {
System.out.println(getInfo());
}
}
Answer :
Person
Student
Q5: What is wrong in the following program?
public class Test {
public static void main (String [ ] args) {
I b = new I(5);
}
}
class H extends I {
public H (int t) {
System.out.println("H's constructor is invoked ");
}
}
class I {
public I (){
}
public I(int k) {
System.out.println("I's construtor is invoked");
}
}
Answer :
public class Test
{
public static void main (String [ ] args) {
I b = new I(5);
}
}
class H extends I {
public H (int t) {
System.out.println("H's constructor is invoked ");
}
}
class I { public I (){
}
public I(int k) {
System.out.println("I's construtor is invoked");
}
}
Q6:
1. Write a Java program for the following scenario:
Suppose we want to monitor the academic performance of students in the Kulliyyah of
ICT. Students consist of undergraduate and graduate students. For eachstudent, we need
to record the student’s name, ten test scores, and the course grade. The program should
store the test scores in an array of type double. The course grade, either “PASS” or “NO
PASS”, is determined by the following formula:
Type of student Grading scheme
Undergraduate PASS if average testscore >=50
Graduate PASS if average testscore >=70
You should provide the following:
a. Identify relevant classes and design a UML class diagram to represent the relationship
between classes using an inheritance hierarchy. You must include relevant attributes and
methods for all the classes.The classes should consist of at least i) overloading constructor
methods, ii) get and set method for each attributes (getName, setName, getTestScore,
setTestScore etc.)
b. Write the complete program based on your design.
Answer :
TestScore
name: String
score: double
+TestScore(name: String, score: double)
+getName(): String
+setName(name: String): void
+getScore(): double
+setScore(score: double): void
public class TestScore
{
String name;
double score;
public TestScore(String name, double score)
{
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}
import java.util.*;
public class TestTestScore
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Please enter student name : ");
String name = input.next();
System.out.println("Please enter student level : 1) undergraduate 2) graduate
");
int level = input.nextInt();
System.out.println("Please enter ten score : ");
int score[] = new int[10];
for(int i = 1; i <= score.length; i++)
{
score[i] = input.nextInt();
if(level == 1)
{
if(score[i] >= 50 && score[i] <= 100)
System.out.println("Pass");
else if(score[i] >=0 && score[i] < 50)
System.out.println("Not pass");
}
else if(level == 2)
{
if(score[i] >= 70 && score[i] <= 100)
System.out.println("Pass");
else if(score[i] >=0 && score[i] < 70)
System.out.println("Not pass");
}
else
{
System.out.println("Wrong input!!");
}
}
}
}
Q7: (The Person, Student, Employee, Faculty, and Staff classes). Design a class named
Person and its two subclasses named Student and Employee. Make Faculty and Staff
subclasses of Employee. A person has a name, address, phone number, and email address.
A student has a class status (freshman, sophomore, junior, or senior). Define the status as
a constant. An employee has an office, salary, and date hired. A faculty member has office
hours and a rank. A staff member has a title. Override the toString method in each class
to display the class name and the person’s name.
Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and
invokes their toString() methods.
Answer :
public class Person
{
private String name;
private String address;
private int phone_number;
private String email;
public Person()
{
}
public Person(String name, String address, int phone_number, String email)
{
this.name = name;
this.address = address;
this.phone_number = phone_number;
this.email = email;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getPhone_number() {
return phone_number;
}
public void setPhone_number(int phone_number) {
this.phone_number = phone_number;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String toString(){
return getClass().getName() + "n" + name;
}
}
public class Student extends Person
{
private final String status;
public Student(String status)
{
this.status = status;
}
public String getStatus() {
return status;
}
}
import java.util.*;
public class Employee extends Person
{
private String office;
private double salary;
private String date;
public Employee()
{
}
public Employee(String office, double salary, String date)
{
this.office = office;
this.salary = salary;
this.date = date;
}
public String getOffice() {
return office;
}
public void setOffice(String office) {
this.office = office;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
public class Faculty extends Employee
{
private int hours;
private int rank;
public Faculty()
{
}
public Faculty(int hours, int rank)
{
this.hours = hours;
this.rank = rank;
}
public int getHours() {
return hours;
}
public void setHours(int hours) {
this.hours = hours;
}
public int getRank() {
return rank;
}
public void setRank(int rank) {
this.rank = rank;
}
}
public class Staff extends Employee
{
private String title;
public Staff()
{
}
public Staff(String title)
{
this.title = title;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
public class TestQ7
{
public static void main(String[] args)
{
Person person = new Person();
Person person1 = new Person("Razak", "Terengganu", 011234567,
"Razak@gmail.com" );
Person student = new Student("junior");
Person employee = new Employee("KL", 12345.95, "02-02-2000" );
Person faculty = new Faculty(9,3);
Person staff = new Staff("Manager");
System.out.println(person.toString() + "n");
System.out.println(student.toString() + "n");
System.out.println(employee.toString() + "n");
System.out.println(faculty.toString() + "n");
System.out.println(staff.toString() + "n");
}
}
Q8: (Subclasses of Account). In lab session4 (Objects and Classes)exercise 2,the Account
class was defined to model a bank account. An account has the properties name, account
number, balance, and methods deposit, withdraw, and get balance. Create two subclasses
for checking and saving accounts. A checking account has an overdraft limit, but a saving
account cannot be overdrawn.
Write a test program that creates objects of Account, SavingsAccount, and
CheckingAccount and invokes their toString() methods.
Answer :
public class Account
{
private String name;
private int accountNo;
private double balance;
public double withdraw;
public double deposit;
public Account()
{
}
public Account(String name, int accountNo, double balance)
{
this.name = name;
this.accountNo = accountNo;
this.balance = balance;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAccountNo() {
return accountNo;
}
public void setAccountNo(int accountNo) {
this.accountNo = accountNo;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double deposit(double amount)
{
return balance += amount;
}
public double withdraw(double amount)
{
return balance -= amount;
}
public String toString()
{
return "Banking Account Informationn" + "nCustomer Name " + name
+"nAccount Number " + accountNo + "nWithdraw Amount is " + withdraw
+ "nDeposite Amount " + deposit + "nBalance " + balance;
}
}
public class SavingsAccount extends Account
{
SavingsAccount(){ super();}
}
public class CheckingAccount extends Account
{
CheckingAccount(){ super();}
}
public class TestAccount
{
public static void main (String[] args)
{
Account acct1 = new Account ("Mahmud", 123456, 95000.00);
Account acct2 = new Account ("Rosli", 224561, 9500.00);
acct1.withdraw (-100.00);
acct2.deposit (500);
System.out.println (acct1);
System.out.println (acct2);
}
}

More Related Content

PDF
Placement management system
PPTX
Javascript validating form
PPTX
Types of methods in python
PPTX
Working with arrays in php
PPTX
Template pattern
PPT
Object and class
PDF
Java Inheritance
PPTX
encapsulation, inheritance, overriding, overloading
Placement management system
Javascript validating form
Types of methods in python
Working with arrays in php
Template pattern
Object and class
Java Inheritance
encapsulation, inheritance, overriding, overloading

What's hot (20)

PPTX
Java Inheritance
PPTX
Visual Basic Controls ppt
PPTX
Database connectivity in python
PPTX
Class, object and inheritance in python
PPTX
Core Java Tutorials by Mahika Tutorials
PPT
Using single row functions to customize output
PDF
StringTokenizer in java
DOCX
Pharmacy management system project report
PPTX
Java OOPS Concept
PPTX
Inheritance In Java
PDF
Javapolymorphism
PPTX
Super keyword in java
PPTX
Inheritance in c++
PPTX
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...
PDF
Constructor and Destructor
PPTX
Member Function in C++
PDF
Java-Answer Chapter 01-04 (For Print)
PPT
Working with color and font
PPTX
Programming in C Basics
PPTX
Polymorphism in java
Java Inheritance
Visual Basic Controls ppt
Database connectivity in python
Class, object and inheritance in python
Core Java Tutorials by Mahika Tutorials
Using single row functions to customize output
StringTokenizer in java
Pharmacy management system project report
Java OOPS Concept
Inheritance In Java
Javapolymorphism
Super keyword in java
Inheritance in c++
Supervised and Unsupervised Learning In Machine Learning | Machine Learning T...
Constructor and Destructor
Member Function in C++
Java-Answer Chapter 01-04 (For Print)
Working with color and font
Programming in C Basics
Polymorphism in java
Ad

Similar to Assignment 7 (20)

PPTX
Java Polymorphism Part 2
PDF
Object Oriented Solved Practice Programs C++ Exams
PPT
Chapter 13 - Inheritance and Polymorphism
PPT
Java căn bản - Chapter13
DOC
Cs141 mid termexam v1
PPTX
L03 Software Design
DOCX
Uta005
PDF
Preexisting code, please useMain.javapublic class Main { p.pdf
PPTX
L02 Software Design
PDF
Java & OOP Core Concept
PPT
Inheritance & Polymorphism - 2
PDF
First compile all the classes.But to run the program we have to run .pdf
PPTX
Inheritance.pptx
DOCX
Second chapter-java
PPTX
Chapter 8.3
PDF
Cs141 mid termexam2_fall2017_v1.1_solution
DOCX
Examf cs-cs141-2-17 solution
PPTX
Object oriented concepts
PPT
lectulecturleclecturlecturlecturlecturturre15.ppt
PPTX
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
Java Polymorphism Part 2
Object Oriented Solved Practice Programs C++ Exams
Chapter 13 - Inheritance and Polymorphism
Java căn bản - Chapter13
Cs141 mid termexam v1
L03 Software Design
Uta005
Preexisting code, please useMain.javapublic class Main { p.pdf
L02 Software Design
Java & OOP Core Concept
Inheritance & Polymorphism - 2
First compile all the classes.But to run the program we have to run .pdf
Inheritance.pptx
Second chapter-java
Chapter 8.3
Cs141 mid termexam2_fall2017_v1.1_solution
Examf cs-cs141-2-17 solution
Object oriented concepts
lectulecturleclecturlecturlecturlecturturre15.ppt
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
Ad

More from IIUM (20)

PDF
How to use_000webhost
PDF
Chapter 2
PDF
Chapter 1
PDF
Kreydle internship-multimedia
PDF
03phpbldgblock
PDF
Chap2 practice key
PDF
Group p1
PDF
Tutorial import n auto pilot blogspot friendly seo
PDF
Visual sceneperception encycloperception-sage-oliva2009
PDF
03 the htm_lforms
PDF
Exercise on algo analysis answer
PDF
Redo midterm
PDF
Heaps
PDF
Report format
PDF
Edpuzzle guidelines
PDF
Final Exam Paper
PDF
Final Exam Paper
PDF
Group assignment 1 s21516
PDF
Avl tree-rotations
PDF
Week12 graph
How to use_000webhost
Chapter 2
Chapter 1
Kreydle internship-multimedia
03phpbldgblock
Chap2 practice key
Group p1
Tutorial import n auto pilot blogspot friendly seo
Visual sceneperception encycloperception-sage-oliva2009
03 the htm_lforms
Exercise on algo analysis answer
Redo midterm
Heaps
Report format
Edpuzzle guidelines
Final Exam Paper
Final Exam Paper
Group assignment 1 s21516
Avl tree-rotations
Week12 graph

Recently uploaded (20)

PPTX
UNIT-2(B) Organisavtional Appraisal.pptx
PPTX
Robot_ppt_YRG[1] [Read-Only]bestppt.pptx
PDF
Volvo EC290C NL EC290CNL Excavator Service Repair Manual Instant Download.pdf
PDF
book-slidefsdljflsk fdslkfjslf sflgs.pdf
DOCX
lp of food hygiene.docxvvvvvvvvvvvvvvvvvvvvvvv
PDF
How Much does a Volvo EC290C NL EC290CNL Weight.pdf
PDF
RPL-ASDC PPT PROGRAM NSDC GOVT SKILLS INDIA
PPTX
Small Fleets, Big Change: Market Acceleration by Niki Okuk
PPTX
Intro to ISO 9001 2015.pptx for awareness
PPTX
description of motor equipments and its process.pptx
PDF
Volvo EC20C Excavator Step-by-step Maintenance Instructions pdf
PDF
Journal Meraj.pdfuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
PPTX
Culture by Design.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PPTX
729193dbwbsve251-Calabarzon-Ppt-Copy.pptx
PDF
LB95 New Holland Service Repair Manual.pdf
PPTX
deforestation.ppt[1]bestpptondeforestation.pptx
PDF
GMPL auto injector molding toollllllllllllllll
PPTX
Business Economics uni 1.pptxRTRETRETRTRETRETRETRETERT
PDF
Volvo ec17c specs Service Manual Download
PPTX
368455847-Relibility RJS-Relibility-PPT-1.pptx
UNIT-2(B) Organisavtional Appraisal.pptx
Robot_ppt_YRG[1] [Read-Only]bestppt.pptx
Volvo EC290C NL EC290CNL Excavator Service Repair Manual Instant Download.pdf
book-slidefsdljflsk fdslkfjslf sflgs.pdf
lp of food hygiene.docxvvvvvvvvvvvvvvvvvvvvvvv
How Much does a Volvo EC290C NL EC290CNL Weight.pdf
RPL-ASDC PPT PROGRAM NSDC GOVT SKILLS INDIA
Small Fleets, Big Change: Market Acceleration by Niki Okuk
Intro to ISO 9001 2015.pptx for awareness
description of motor equipments and its process.pptx
Volvo EC20C Excavator Step-by-step Maintenance Instructions pdf
Journal Meraj.pdfuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
Culture by Design.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
729193dbwbsve251-Calabarzon-Ppt-Copy.pptx
LB95 New Holland Service Repair Manual.pdf
deforestation.ppt[1]bestpptondeforestation.pptx
GMPL auto injector molding toollllllllllllllll
Business Economics uni 1.pptxRTRETRETRTRETRETRETRETERT
Volvo ec17c specs Service Manual Download
368455847-Relibility RJS-Relibility-PPT-1.pptx

Assignment 7

  • 1. ASSIGNMENT 7 MUHAMMAD MUZZAMMIL BIN JUSOF 1417299 SECTION 5 DR. ALI ALWAN Q1: What is the output of running class C? class A { public A () { System.out.println(“A’s no-arg constructor is invoked”); } } class B extends A { } public class C { public static void main (String [] args ) { B b = new B (); } } Answer : A’s no-arg constructor is invoked Q2: True/ false 1. When invoking a constructor from a subclass, its superclass’s no-arg constructor is always invoked. 2. You can override a private method defined in a superclass. 3. You can override a static method defined in a superclass. 4. You can always successfully cast an instance of a subclass to a superclass 5. You can always successfully cast an instance of a superclass to a subclass. 6. A protected method can be accessedby any class in the same package. 7. A protected method can be accessedby its subclasses in any package. 8. A final class can be extended. 9. A final method can be overridden Answer : 1) False 2) False 3) True 4) True 5) False 6) False 7) True 8) False 9) False
  • 2. Q3: Explain the difference between method overloading and method overriding. Answer : Method overloading is used to increase the readability of the program. Method overriding is used to provide the specific implementation of the method that is already provided by its super class. Method overloading is performed within class. Method overriding occurs in two classes that have IS-A (inheritance) relationship. In case of method overloading, parameter must be different. In case of method overriding, parameter must be same. Method overloading is the example of compile time polymorphism. Method overriding is the example of run time polymorphism. In java, method overloading can't be performed by changing return type of the method only. Return type can be same or different in method overloading. But you must have to change the parameter. Return type must be same or covariant in method overriding. Q4: Show the output of the following code: public class Test { public static void main (String [] args) { new Person().printPerson(); new Student().printPerson(); } } class Student extends Person { @Override public String getInfo() { return “Student”; } } class Person { public String getInfo() { return “Person”; } public void printPerson() { System.out.println(getInfo()); } } Answer : Person Student Q5: What is wrong in the following program? public class Test { public static void main (String [ ] args) { I b = new I(5); } } class H extends I { public H (int t) {
  • 3. System.out.println("H's constructor is invoked "); } } class I { public I (){ } public I(int k) { System.out.println("I's construtor is invoked"); } } Answer : public class Test { public static void main (String [ ] args) { I b = new I(5); } } class H extends I { public H (int t) { System.out.println("H's constructor is invoked "); } } class I { public I (){ } public I(int k) { System.out.println("I's construtor is invoked"); } } Q6: 1. Write a Java program for the following scenario: Suppose we want to monitor the academic performance of students in the Kulliyyah of ICT. Students consist of undergraduate and graduate students. For eachstudent, we need to record the student’s name, ten test scores, and the course grade. The program should store the test scores in an array of type double. The course grade, either “PASS” or “NO PASS”, is determined by the following formula: Type of student Grading scheme Undergraduate PASS if average testscore >=50 Graduate PASS if average testscore >=70 You should provide the following: a. Identify relevant classes and design a UML class diagram to represent the relationship between classes using an inheritance hierarchy. You must include relevant attributes and methods for all the classes.The classes should consist of at least i) overloading constructor
  • 4. methods, ii) get and set method for each attributes (getName, setName, getTestScore, setTestScore etc.) b. Write the complete program based on your design. Answer : TestScore name: String score: double +TestScore(name: String, score: double) +getName(): String +setName(name: String): void +getScore(): double +setScore(score: double): void public class TestScore { String name; double score; public TestScore(String name, double score) { this.name = name; this.score = score; } public String getName() { return name; } public void setName(String name) { this.name = name; } public double getScore() { return score; } public void setScore(double score) { this.score = score; } }
  • 5. import java.util.*; public class TestTestScore { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Please enter student name : "); String name = input.next(); System.out.println("Please enter student level : 1) undergraduate 2) graduate "); int level = input.nextInt(); System.out.println("Please enter ten score : "); int score[] = new int[10]; for(int i = 1; i <= score.length; i++) { score[i] = input.nextInt(); if(level == 1) { if(score[i] >= 50 && score[i] <= 100) System.out.println("Pass"); else if(score[i] >=0 && score[i] < 50) System.out.println("Not pass"); } else if(level == 2) { if(score[i] >= 70 && score[i] <= 100) System.out.println("Pass"); else if(score[i] >=0 && score[i] < 70) System.out.println("Not pass"); } else { System.out.println("Wrong input!!"); } } } }
  • 6. Q7: (The Person, Student, Employee, Faculty, and Staff classes). Design a class named Person and its two subclasses named Student and Employee. Make Faculty and Staff subclasses of Employee. A person has a name, address, phone number, and email address. A student has a class status (freshman, sophomore, junior, or senior). Define the status as a constant. An employee has an office, salary, and date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString method in each class to display the class name and the person’s name. Write a test program that creates a Person, Student, Employee, Faculty, and Staff, and invokes their toString() methods. Answer : public class Person { private String name; private String address; private int phone_number; private String email; public Person() { } public Person(String name, String address, int phone_number, String email) { this.name = name; this.address = address; this.phone_number = phone_number; this.email = email; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public int getPhone_number() { return phone_number;
  • 7. } public void setPhone_number(int phone_number) { this.phone_number = phone_number; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String toString(){ return getClass().getName() + "n" + name; } } public class Student extends Person { private final String status; public Student(String status) { this.status = status; } public String getStatus() { return status; } } import java.util.*; public class Employee extends Person { private String office; private double salary; private String date; public Employee() { } public Employee(String office, double salary, String date) { this.office = office; this.salary = salary; this.date = date; }
  • 8. public String getOffice() { return office; } public void setOffice(String office) { this.office = office; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary = salary; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } } public class Faculty extends Employee { private int hours; private int rank; public Faculty() { } public Faculty(int hours, int rank) { this.hours = hours; this.rank = rank; } public int getHours() { return hours; } public void setHours(int hours) { this.hours = hours; } public int getRank() { return rank; } public void setRank(int rank) { this.rank = rank; } }
  • 9. public class Staff extends Employee { private String title; public Staff() { } public Staff(String title) { this.title = title; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } public class TestQ7 { public static void main(String[] args) { Person person = new Person(); Person person1 = new Person("Razak", "Terengganu", 011234567, "Razak@gmail.com" ); Person student = new Student("junior"); Person employee = new Employee("KL", 12345.95, "02-02-2000" ); Person faculty = new Faculty(9,3); Person staff = new Staff("Manager"); System.out.println(person.toString() + "n"); System.out.println(student.toString() + "n"); System.out.println(employee.toString() + "n"); System.out.println(faculty.toString() + "n"); System.out.println(staff.toString() + "n"); } }
  • 10. Q8: (Subclasses of Account). In lab session4 (Objects and Classes)exercise 2,the Account class was defined to model a bank account. An account has the properties name, account number, balance, and methods deposit, withdraw, and get balance. Create two subclasses for checking and saving accounts. A checking account has an overdraft limit, but a saving account cannot be overdrawn. Write a test program that creates objects of Account, SavingsAccount, and CheckingAccount and invokes their toString() methods. Answer : public class Account { private String name; private int accountNo; private double balance; public double withdraw; public double deposit; public Account() { } public Account(String name, int accountNo, double balance) { this.name = name; this.accountNo = accountNo; this.balance = balance; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAccountNo() { return accountNo; } public void setAccountNo(int accountNo) { this.accountNo = accountNo; } public double getBalance() { return balance; }
  • 11. public void setBalance(double balance) { this.balance = balance; } public double deposit(double amount) { return balance += amount; } public double withdraw(double amount) { return balance -= amount; } public String toString() { return "Banking Account Informationn" + "nCustomer Name " + name +"nAccount Number " + accountNo + "nWithdraw Amount is " + withdraw + "nDeposite Amount " + deposit + "nBalance " + balance; } } public class SavingsAccount extends Account { SavingsAccount(){ super();} } public class CheckingAccount extends Account { CheckingAccount(){ super();} } public class TestAccount { public static void main (String[] args) { Account acct1 = new Account ("Mahmud", 123456, 95000.00); Account acct2 = new Account ("Rosli", 224561, 9500.00); acct1.withdraw (-100.00); acct2.deposit (500); System.out.println (acct1); System.out.println (acct2); } }