0% found this document useful (0 votes)
18 views

EXERCISE 6 in Java

The document describes two Java classes - Accounts and SavingsAccount. Accounts is an abstract class that defines data members like balance and account number, and abstract methods like withdraw and deposit. SavingsAccount extends Accounts and adds a rateOfInterest data member and calculateAmount method. The main method creates a SavingsAccount object, calls methods to display initial balance, withdraw, deposit, and calculate interest.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

EXERCISE 6 in Java

The document describes two Java classes - Accounts and SavingsAccount. Accounts is an abstract class that defines data members like balance and account number, and abstract methods like withdraw and deposit. SavingsAccount extends Accounts and adds a rateOfInterest data member and calculateAmount method. The main method creates a SavingsAccount object, calls methods to display initial balance, withdraw, deposit, and calculate interest.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

EXERCISE :6

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;

abstract void withdraw (int amt);


abstract void deposit (int amt);
void display ()
{
System.out.println (Balance);
}
}

class SavingsAccount extends Accounts


{
double rateofInterest;
SavingsAccount (int a, int b, String c, String d, double e)
{
//super (a, b, c, d);
Balance = a;
Account_number = b;
Name = c;
Address = d;

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();
}
}

public class Main


{
public static void main (String[]args)
{
Scanner sc = new Scanner (System.in);
System.out.println("enter Balance");
int a = sc.nextInt ();
System.out.println("enter Account number");

int b = sc.nextInt ();


System.out.println("enter Name ");
String c = sc.next ();
System.out.println("enter Address");
String d = sc.nextLine ();
sc.nextLine();
System.out.println("enter Rateof interest");
double e = sc.nextDouble ();
SavingsAccount s = new SavingsAccount (a, b, c, d, e);
System.out.println("Innitial Ammount");
s.display ();
System.out.println("Ammount after Withdrawal:");
s.withdraw(500);
System.out.println("Ammount after deposit :");
s.deposit(300);
System.out.println("Available Balance: ");
s.Calculate();

}
}

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"};
}

class Library extends Lib {


void display() {
System.out.println("Available books:");
for (String i : s) {
System.out.println(i);
}
}
}

class Issue extends Library {


String a;

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];
}

s = Arrays.copyOf(s, s.length - 1);


}
System.out.println (" the book available after issued:");
display();
}
}
class Return extends Library {
String b;

Return(String z) {
super();
b = z;
s = Arrays.copyOf(s, s.length +1);

s[s.length-1] = b;

System.out.println (" the book available after


return");

display();
}
}

public class Main {


public static void main(String[] args) {
Scanner sc= new Scanner (System .in);
System.out.println ("enter the book to be issued :");
Issue issue1 = new Issue(sc.next());
System.out.println (" enter the book to Return:");
Return r1=new Return(sc.next());
}
}

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy