0% found this document useful (0 votes)
8 views3 pages

Java If-Else Programs for ICSE

The document contains three Java programs that utilize if-else statements for different applications: a Railway Ticket booking system, a ShowRoom billing system, and a Student report generation program. Each program includes methods for input, calculation, and display of relevant information. The programs demonstrate basic Java syntax and control flow using user input to determine outputs.

Uploaded by

rasku87
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Java If-Else Programs for ICSE

The document contains three Java programs that utilize if-else statements for different applications: a Railway Ticket booking system, a ShowRoom billing system, and a Student report generation program. Each program includes methods for input, calculation, and display of relevant information. The programs demonstrate basic Java syntax and control flow using user input to determine outputs.

Uploaded by

rasku87
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Programs Using If-Else (Q7, Q8, Q9)

Q7 - Railway Ticket (ICSE 2018)


import [Link];

class RailwayTicket {
String name;
String coach;
long mobno;
int amt;
int totalamt;

void accept() {
Scanner sc = new Scanner([Link]);

[Link]("Enter name: ");


name = [Link]();

[Link]("Enter coach (First_AC / Second_AC / Third_AC / sleeper): ");


coach = [Link]();

[Link]("Enter mobile number: ");


mobno = [Link]();

[Link]("Enter basic amount: ");


amt = [Link]();
}

void update() {
if ([Link]("First_AC"))
totalamt = amt + 700;
else if ([Link]("Second_AC"))
totalamt = amt + 500;
else if ([Link]("Third_AC"))
totalamt = amt + 250;
else
totalamt = amt;
}

void display() {
[Link]("\n----- TICKET DETAILS -----");
[Link]("Name: " + name);
[Link]("Coach: " + coach);
[Link]("Mobile No: " + mobno);
[Link]("Total Amount: " + totalamt);
}

public static void main(String[] args) {


RailwayTicket obj = new RailwayTicket();
[Link]();
[Link]();
[Link]();
}
}

Q8 - ShowRoom (ICSE 2019)


import [Link];

class ShowRoom {
String name;
long mobno;
double cost;
double dis;
double amount;

ShowRoom() {
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}

void input() {
Scanner sc = new Scanner([Link]);

[Link]("Enter Customer Name: ");


name = [Link]();

[Link]("Enter Mobile Number: ");


mobno = [Link]();

[Link]("Enter Cost of Items: ");


cost = [Link]();
}

void calculate() {
if (cost <= 10000)
dis = 0.05 * cost;
else if (cost <= 20000)
dis = 0.10 * cost;
else if (cost <= 35000)
dis = 0.15 * cost;
else
dis = 0.20 * cost;

amount = cost - dis;


}

void display() {
[Link]("\n----- BILL DETAILS -----");
[Link]("Name: " + name);
[Link]("Mobile No: " + mobno);
[Link]("Amount to Pay: " + amount);
}

public static void main(String[] args) {


ShowRoom s = new ShowRoom();
[Link]();
[Link]();
[Link]();
}
}

Q9 - Student Program
import [Link];

class Student {
String name;
int m1, m2, m3;
int total;
double avg;

void input() {
Scanner sc = new Scanner([Link]);

[Link]("Enter Student Name: ");


name = [Link]();

[Link]("Enter marks of 3 subjects: ");


m1 = [Link]();
m2 = [Link]();
m3 = [Link]();
}

void calculate() {
total = m1 + m2 + m3;
avg = total / 3.0;
}

void display() {
[Link]("\n----- STUDENT REPORT -----");
[Link]("Name: " + name);
[Link]("Total Marks: " + total);
[Link]("Average: " + avg);
}

public static void main(String[] args) {


Student s = new Student();
[Link]();
[Link]();
[Link]();
}
}

You might also like