Java Assignment 3
Java Assignment 3
Q1. Develop a class called Library with the following description by applying
the concept of class and object:
Instance Variable/Data Members
int acc_num - to store the accession number of the book.
String title - to store the title of the book
String author - to store the name of the author
Member methods
void input() - to input and store the detail of the book
void compute() - to accept the number of days late, calculate and display the
fine charged at the rate of Rs. 2 per day.
void display() - to display the all the details of book
Write a program for the above mentioned class and call the method
accordingly.
class Assignment3Question1 {
public static void main(String[] args) {
Library book = new Library();
book.input(001, "harry puttar", "joking rolling");
book.compute(10);
book.display();
}
}
class Library {
int acc_num;
String title;
String author;
void input(int acc_num, String title, String author)
{
this.acc_num = acc_num;
this.title = title;
this.author = author;
}
void compute(int days_late) {
System.out.println("Your late fine is ₹" + 2*days_late);
}
void display()
{
System.out.println("accession number:\t" + this.acc_num);
System.out.println("title:\t\t\t" + this.title);
System.out.println("author:\t\t\t" + this.author);
}
}
2. Build a class named FixedInvestment that contains:
A double data field named depositAmount that specifies the investment
amount (default 1000).
A double data field named annualInterestRate that specifies the fixed
interest rate (default 5.0%)
An int data field named numberOfYears that specifies the investment
duration (default 1).
A no-arg constructor that create a default instance.
A constructor that creates an instance with the specified
depositAmount, annualInterestRate and numberOfYears.
The accessor methods for depositAmount, numberOfYears and
annualInterestRate.
A method named getTotalReturn() that return the investment return
after the specified number of years.
The total return can be computed using the following formula:
totalReturn = investmentAmount x (1 +
monthlyInterestRate)numberOfYears*12