You are on page 1of 14

Q43)Define a class called Library with following description:

Instance variables/Data Members:

int acc_num: stores the accession number of the book.

String title: Stores the title of the book.

String author: Stores name of the author.

Member Methods:

void input(): to input and store accession number, title and the author.

void compute(): to accept the number of days late, calculate and display the fine charge
at the rate Rs. 2 per day.

void display() : to display the details in the following format:

Accession Number Title Author.

Variable Description
int acc_num To store the accession number of the book.
String title To store the title of the book.
String author To store name of the author.
int z to accept the number of days late.
int d To calculate the amount of fine.

import java.io.*;

class Library

static int acc_num,d=0;

static String title,author;

static void input()throws IOException

InputStreamReader read=new InputStreamReader(System.in);


BufferedReader in=new BufferedReader(read);

System.out.println("Enter the accession number of the book");

acc_num=Integer.parseInt(in.readLine());

System.out.println("Enter the title of the book");

title=in.readLine();

System.out.println("Enter the name of the author of the book");

author=in.readLine();

static void compute()throws IOException

InputStreamReader read=new InputStreamReader(System.in);

BufferedReader in=new BufferedReader(read);

System.out.println("Enter the number of days late");

int z=Integer.parseInt(in.readLine());

d=0;

for(int i=1;i<=z;i++)

d=d+2;

static void display()throws IOException


{

System.out.println("**********************************");

System.out.println("Accesion Number Title Author ");

System.out.println(acc_num+" "+title+" "+author);

System.out.println("Fine to be paid =Rs"+d);

public static void main()throws IOException

InputStreamReader read=new InputStreamReader(System.in);

BufferedReader in=new BufferedReader(read);

Library ob=new Library();

ob.input();

ob.compute();

ob.display();

}
Q44)Define a class Employee having the following description:

Data members/Instance Variables:

int pan: to store personal account number.

String name: to store name.

double taxincome: to store annual taxable income.

double tax: to store tax that is calculated.

Member function:

void input(): stores the pan number, name, and taxable income.

void cal(): Calculate tax of an employee.

void display(): output details of an employee.

Write a program to compute the tax according to the given conditions and display the
output as per given format:

Total annual taxable income Tax rate

Up to Rs. 1,00,000 No tax

From Rs. 1,00,001 to 1,50,000 10% of the income exceeding Rs. 1,00,000

From Rs. 1,50,001 to 2,50,000 Rs.5000+20% of the income exceeding Rs. 1,50,000

Above Rs. 2,50,000 Rs.25000+30% of the income exceeding Rs. 2,50,000

Output:

Pan Number Name Tax-income Tax

Variable Description
String name To store name.
int pan To store personal account number.
double taxincome To store annual taxable income.
double tax To store tax that is calculated.
double d To calculate the amount exceeding the taxincome.
import java.io.*;

class Employee

static int pan;

static String name;

static double taxincome,tax,d=0.0;

static void input()throws IOException

InputStreamReader read=new InputStreamReader(System.in);

BufferedReader in=new BufferedReader(read);

System.out.println("Enter your personal account number");

pan=Integer.parseInt(in.readLine());

System.out.println("Enter your name");

name=in.readLine();

System.out.println("Enter your annual taxable income");

taxincome=Double.parseDouble(in.readLine());

static void cal()throws IOException

d=0.0;

if(taxincome<=100000)

tax=0;
}

if(taxincome>100000 && taxincome<=150000)

d=taxincome-100000;

tax=(10*d/100);

if(taxincome>150000 && taxincome<=250000)

d=taxincome-150000;

tax=5000+(20*d/100);

if(taxincome>250000)

d=taxincome-250000;

tax=25000+(30*d/100);

static void display()throws IOException

System.out.println("*******************************************************
*");

System.out.println("Pan Number Name Taxable income Tax");

System.out.println(pan+" "+name+" "+taxincome+" "+tax);


}

public static void main()throws IOException

InputStreamReader read=new InputStreamReader(System.in);

BufferedReader in=new BufferedReader(read);

input();

cal();

display();

}
Q45)Define a class called ParkingLot with the following descriptions:

Instance Variables/Data Members:

int vno: To store the vehicle number.

int hours: To store the number of hours the vehicle is parked in the parking lot.

double bill: To store the bill amount.

Member method:

void input(): to input and store the vno and hours.

void calculate(): to compute the parking charge at the rate Rs. 3 for the first hour and
Rs. 2.50 for each additional hour.

void display(): to display the details.

Write a main program to create an object of the class and call the above method.

Variable Description
int vno: To store the vehicle number.
int hours To store the number of hours the vehicle is parked in the parking lot.
double bill To store the bill amount.
double d To store the value of (hours-1)

import java.io.*;

class ParkingLot

static int vno,hours;

static double bill,d;

static void input()throws IOException

InputStreamReader read=new InputStreamReader(System.in);


BufferedReader in=new BufferedReader(read);

System.out.println("Enter the vehicle number");

vno=Integer.parseInt(in.readLine());

System.out.println("Enter the number of hours the vehicle has been parked in the
parking lot");

hours=Integer.parseInt(in.readLine());

static void calculate()throws IOException

if(hours==1)

bill=3;

if(hours>1)

d=hours-1;

bill= 3+(d*2.5);

static void display()throws IOException

System.out.println("Vehicle Number::"+vno);

System.out.println("The number of hours the vehicle had been parked in the


parking lot::"+hours);
System.out.println("The bill::Rs "+bill);

public static void main()throws IOException

InputStreamReader read=new InputStreamReader(System.in);

BufferedReader in=new BufferedReader(read);

ParkingLot ob=new ParkingLot();

ob.input();

ob.calculate();

ob.display();

}
Q46)Define a class named Movie with the following description:

Instance variables/data members:

int year -to store the year of release of a movie.

String title-to store the title of the movie.

float rating-to store the popularity of the movie.(minimum rating=0.0 and maximum
rating=5.0)

Member methods:

Movie(): Default constructor to initialize numeric data members to 0 and string data
members to “”.

void accept(): to input and store year, title and rating.

Void display(): to display the title of a movie and a message based on the rating as per
the table below.

Rating Message to be displayed.

0.0 to 2.0 Flop

2.1 to 3.4 Semi-hit

3.5 to 4.5 Hit

4.6 to 5.0 Super-hit

Write a main method to create an object of the class and call the above member
methods.

Variable Description
int year To store the year of release of a movie.
String title To store the title of the movie.
float rating To store the popularity of the movie.

import java.io.*;

class Movie
{

float rating;

String title;

int year;

Movie()

rating=0;

year=0;

title="";

void accept()throws IOException

InputStreamReader read=new InputStreamReader(System.in);

BufferedReader in=new BufferedReader(read);

System.out.println("Enter the year of release of the movie");

year=Integer.parseInt(in.readLine());

System.out.println("Enter the title of the movie");

title=in.readLine();

System.out.println("Enter the popularity rating of the movie");

rating=Float.parseFloat(in.readLine());

void display()

{
System.out.println("*************************************");

System.out.println("The title of the movie::"+title);

System.out.println("Rating:-");

if(rating>=0.0 && rating<=2.0)

System.out.println(rating+" Flop");

if(rating>=2.1 && rating<=3.4)

System.out.println(rating+" Semi-hit");

if(rating>=3.5 && rating<=4.5)

System.out.println(rating+" Hit");

if(rating>=4.6 && rating<=5.0)

System.out.println(rating+" Super-hit");

public static void main()throws IOException

InputStreamReader read=new InputStreamReader(System.in);


BufferedReader in=new BufferedReader(read);

Movie ob=new Movie();

ob.accept();

ob.display();