EXERCISE 6 in Java
EXERCISE 6 in Java
QUESTION:-
1) Create an Abstract class Accounts with the following
details
Data members:
a) Balance
b) Account number
c) Account holders name
d) Address
Methods:
a) withdrawal() – abstract
b) deposit() – abstract
c) display() – to show the balance of the account number
Create a subclass of this class SavingsAccount and add the
following details
Data members:
a) rateofInterest
Methods:
a) calculateAmount()
code
import java.util.*;
abstract class Accounts
{
int Balance;
int Account_number;
String Name;
String Address;
rateofInterest = e;
}
void Calculate ()
{
System.out.println (Balance+(rateofInterest * Balance));
}
void withdraw (int amt)
{
if (amt > 0)
{
Balance = Balance - amt;
}
super.display();
}
void deposit (int amt)
{
if (amt > 0)
{
Balance = Balance + amt;
}
super.display();
}
}
}
}
Output
enter Balance
10000
enter Account number
12345
enter Name
abc
enter Address
psg tech
enter Rateof interest
5.5
Innial Ammount
10000
Ammount after Withdrawal:
9500
Ammount after deposit :
9800
Available Balance:
63700.0
QUESTION
2) Create an Abstract class named Library Management that
has functions for getting the
book name and display the names of the books. There are
two derived classes, Issue and
Return. These classes have decrement and increment
functions. The user can take or
return books. Update the system accordingly. Include
provision for searching for a book.
Code:-
import java.util.Arrays;
import java.util.*;
abstract class Lib {
protected String[] s = {"a", "b", "c", "d", "e", "f", "g"};
}
Issue(String z) {
super();
a = z;
int d = -1;
for (int i = 0; i < s.length; i++) {
if (s[i].equals(a)) {
d = i;
break;
}
}
if(d==-1){
System.out.println("the book is not present");
return;
}
if (d != -1) {
for (int i = d; i < s.length - 1; i++) {
s[i] = s[i + 1];
}
Return(String z) {
super();
b = z;
s = Arrays.copyOf(s, s.length +1);
s[s.length-1] = b;
display();
}
}
Output:-
enter the book to be issued :
a
the book available after issued:
Available books:
b
c
d
e
f
g
enter the book to Return:
a
the book available after return
Available books:
a
b
c
d
e
f
g
a