Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.util.

Scanner;
public class testcode{
public static void main(String[] args) {
library l1 = new library();
l1.accept();
l1.compute();
l1.show();
}
}
class library{
String name;
String author;
double price;
int d;
double r;
double amt;
library(){
this.d = 0;
this.r = 0;
}

void accept(){
Scanner sc = new Scanner(System.in);
System.out.println("enter the name of the book");
this.name = sc.nextLine();
System.out.println("enter the name of the author");
this.author = sc.nextLine();
System.out.println("enter the price of the boook");
this.price = sc.nextFloat();
System.out.println("enter the number of days taken to return the book");
this.d = sc.nextInt();
}
void compute(){
double base = 0;
if(this.d <= 5){
base = base + this.d*(0.02*this.price);
}else if(this.d > 5){
base = base + 5*(0.02*this.price);
int excess = this.d - 5;
if(excess >=1 && excess <=5){
this.r = r + excess*2;
}else if ( excess <= 10){
this.r = r + 5*2 + (excess-5)*3;
}else{
this.r = r + 5*2 + (10-5)*3 + (excess-10)*5;
}
}
this.amt = base + this.r;
}
void show(){
System.out.println("the name of the book " + this.name);
System.out.println("the name of the author is " + this.author);
System.out.println("the price of the book : " + this.price);
System.out.println("the number of days the book has been issued for " +
this.d);
System.out.println("the fine charged for the extra days : " + this.r );
System.out.println("the total amount to be paid is : " + this.amt);
}
}

You might also like