CL X CH 11 Program
CL X CH 11 Program
PG- 195,196,197
Data
Purpose
Members
Member
Purpose
Methods
void accept() To take input for name, coach, mobile number and amount
Member
Purpose
Methods
Type of
Amount
Coaches
First_AC ₹700
Second_AC ₹500
Third_AC ₹250
Sleeper None
Write a main method to create an object of the class and call the above member
methods.
Programming Code
import java.util.Scanner;
public class RailwayTicket
String name,coach;
long mobno;
int amt,totalamt;
name = in.nextLine();
coach = in.nextLine();
mobno = in.nextLong();
amt = in.nextInt();
if(coach.equalsIgnoreCase("First_AC"))
else if(coach.equalsIgnoreCase("Third_AC"))
else if(coach.equalsIgnoreCase("Sleeper"))
totalamt = amt;
obj.accept();
obj.update();
obj.display();
}
Output
Name: Rakesh
Coach: FIRST_AC
class : ElectricBill
Member methods:
void accept( ) — to accept the name of the customer and number of units
consumed
void calculate( ) — to calculate the bill as per the following tariff:
Number of
Rate per unit
units
A surcharge of 2.5% charged if the number of units consumed is above 300 units.
Write a main method to create an object of the class and call the above member
methods.
Programming code
import java.util.Scanner;
String n;
int units;
double bill,amt,surcharge;
public void accept()
n = in.nextLine();
units = in.nextInt();
bill = units * 2;
else
obj.accept();
obj.calculate();
obj.print();
Output
Member
Purpose
Methods
void input( ) To input and store the name and price of the book
void display( ) To display the name and price of the book after discount
Price Discount
Write a main method to create an object of the class and call the above member
methods.
Programming code
import java.util.Scanner;
String bname;
double price;
public BookFair()
bname = "";
price = 0.0;
}
public void input()
bname = in.nextLine();
price = in.nextDouble();
double disc;
else
price -= disc;
}
public void display()
obj.input();
obj.calculate();
obj.display();
Output
Average
Remark
Marks
85 — 100 Excellent
75 — 84 Distinction
60 — 74 First Class
40 — 59 Pass
Programming code
import java.util.Scanner;
{
int roll,s1,s2,s3;
String name,remark;
double avg;
void input()
name = in.nextLine();
roll = in.nextInt();
s1= in.nextInt();
s2= in.nextInt();
s3= in.nextInt();
avg= (s1+s2+s3)/3.0;
void calculation()
if (avg< 40)
remark = "Poor";
else if (avg < 60)
remark = "Pass";
remark = "Distinction";
else
remark = "Excellent";
void output()
obj.input();
obj.calculation();
obj.output();
Output
raju
23
89
85
88
Marks of subject1 : 89
Marks of subject2 : 85
Marks of subject3 : 88
Data
Purpose
Members
Member
Purpose
Methods
To compute the parking charge at the rate ₹3 for the first hour
void
or the part thereof and ₹1.50 for each additional hour or part
calculate( )
thereof.
Write a main method to create an object of the class and call the above methods.
Programming code
import java.util.Scanner;
int vno,hours;
double bill;
vno = in.nextInt();
System.out.print("Enter hours: ");
hours = in.nextInt();
if (hours <= 1)
bill = 3;
else
obj.input();
obj.calculate();
obj.display();
Output
Enter hours: 7
Hours: 7
Bill: 12.0
Member
Purpose
Methods
void display() To display the title of the movie and a message based on the
Member
Purpose
Methods
Ratings Table
0.0 to
Flop
2.0
2.1 to
Semi-Hit
3.4
3.5 to
Hit
4.4
4.5 to
Super-Hit
5.0
Write a main method to create an object of the class and call the above member
methods.
Programming code
import java.util.Scanner;
int year;
String title;
float rating;
public movieMagic()
year = 0;
title = "";
rating = 0.0f;
title = in.nextLine();
year = in.nextInt();
System.out.print("Enter Rating of Movie: ");
rating = in.nextFloat();
message = "Flop";
message = "Semi-Hit";
message = "Hit";
message = "Super-Hit";
System.out.println(title);
System.out.println(message);
obj.display();
Output
TRZONE
Invalid Rating
9. Given below is a hypothetical table showing rates of income tax for male
citizens below the age of 65 years:
Is greater than Rs. 5,00,000 and less than or equal to [(TI - 5,00,000) x 20%] +
Rs. 8,00,000 34,000
Write a program to input the age, gender (male or female) and Taxable Income of
a person.
If the age is more than 65 years or the gender is female, display “wrong
category”. If the age is less than or equal to 65 years and the gender is male,
compute and display the income tax payable as per the table given above.
Programming code
import java.util.Scanner;
double ti = in.nextDouble();
System.out.print("Wrong Category");
else {
tax = 0;
else
}
}
Output
Enter Age: 65
1. void compare(int, int) — to compare two integers values and print the
greater of the two integers.
Programming code
import java.util.Scanner;
{
if (a > b)
System.out.println(a);
else
System.out.println(b);
int x = (int)a;
int y = (int)b;
if (x > y) {
System.out.println(a);
else {
System.out.println(b);
}
int l1 = a.length();
int l2 = b.length();
System.out.println(a);
else {
System.out.println(b);
int n1 = in.nextInt();
int n2 = in.nextInt();
obj.compare(n1, n2);
char c1 = in.next().charAt(0);
char c2 = in.next().charAt(0);
in.nextLine();
obj.compare(c1, c2);
String s1 = in.nextLine();
String s2 = in.nextLine();
obj.compare(s1, s2);
}
}