Define a class called Library with the following description Data members / Instance variables are :- int acc_num = account number String tittle = tittle of the book String author = Writer of the book Method members : Library ( ) = default constructor to assign default values in data Members. void input ( ) = input book name, author name and account no. int compute ( ) = input number of days late and calculate the fine amount and return rate is 2.0 per day void display ( ) = print acc_num, tittle, author and fine amount write a main method to create an object of class Library and call all member methods
Answers
Answer:
import java.util.Scanner;
import java.util.*;
public class Main
{
public static void main (String[]args)
{
int a[] = new int[50];
Scanner in = new Scanner (System.in);
System.out.println ("Enter book details");
System.out.println ("Enter title");
String title=in.next();
System.out.println ("Enter Author");
String author=in.next();
System.out.println ("Enter Accountnumber as Number");
Integer acc_num=in.nextInt();
Library library=new Library();
library.input (title, author, acc_num);
System.out.println ("Enter number of days late: ");
Integer days = in.nextInt ();
library.compute(days);
library.display();
}
}
public class Library
{
Integer acc_num;
String title;
String author;
float fine;
Library ()
{
acc_num = 0;
title = "";
author = "";
}
public void input (String bookname, String author, Integer acc_num)
{
this.acc_num = acc_num;
this.title = bookname;
this.author = author;
}
public void compute (Integer days)
{
fine = days * 2;
}
public void display ()
{
System.out.println ("Book Details");
System.out.println ("Account No: "+acc_num);
System.out.println ("Title: "+title);
System.out.println ("Author: "+author);
System.out.println ("Fine Rate: "+fine);
}
}
Explanation:
I have changes int to void in compute method. otherwise it will not work. and question need to be changed.
Answer:
Above two answer are absolutely right