0% found this document useful (0 votes)
31 views13 pages

Java Programming Lab Tasks Overview

The document consists of multiple Java programming tasks that involve user input and conditional statements. Each task addresses different scenarios such as fare calculation based on age, course eligibility based on programming knowledge, shopping discounts, scholarship eligibility based on GPA and income, health consultation bookings, movie ticket purchases, airline class selections, and library book transactions. The code snippets demonstrate the use of switch-case statements and if-else conditions to handle various user interactions.

Uploaded by

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

Java Programming Lab Tasks Overview

The document consists of multiple Java programming tasks that involve user input and conditional statements. Each task addresses different scenarios such as fare calculation based on age, course eligibility based on programming knowledge, shopping discounts, scholarship eligibility based on GPA and income, health consultation bookings, movie ticket purchases, airline class selections, and library book transactions. The code snippets demonstrate the use of switch-case statements and if-else conditions to handle various user interactions.

Uploaded by

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

PF Lab 4

Name: Muhammad Yousuf


Registration No. L1F24BSSE0384
Section: N1

Task 1:

import [Link];
public class Main {
public static void main(String[] args) {
Scanner myObj = new Scanner([Link]);
[Link]("If you're below 12 press '1' and for above 60 press '2' otherwise press '3'");
int age = [Link]();
int fare = 5000;

switch (age){
case (1):
double Fare = (double) fare * 50/100;
int price = (int) (fare - Fare);
[Link]("You got 50% discount");
[Link]("Your fare is: "+ price);
break;
case (2):
double faRe = (double) 30/100 * fare;
int Price = (int) (fare -faRe);
[Link]("You got 30% discount");
[Link]("Your fare is: "+ Price);
break;
case (3):
[Link]("You got no discount");
[Link]("Your fare is: "+fare);
break;

}
}
}

Output:
Task 2:
import [Link];

public class coursecheck {


public static void main(String[] args) {
Scanner obj = new Scanner([Link]);
[Link]("You know Basic Programming(y/n)");
String ans = [Link]();

if ([Link]("y")) {
[Link]("You can enroll in Advanced Programming!");
[Link]("Enter your status (passed/fail)");
String sts = [Link]();
[Link]("Enter your marks percentage: ");
double p = [Link]();

if ([Link]("passed")) {
if (p >= 80) {
[Link]("You are eligible for Advanced Programming!");
} else {
[Link]("You are eligible for Intermediate Course!");
}
}

}else {
[Link]("You are not eligible for any course!");
}
}
}

Output:
Task 3:
import [Link];

public class shopping {


public static void main(String [] args){
Scanner obj = new Scanner([Link]);
[Link]("You are a loyal member?(y/n)");
String l = [Link]();
[Link]("What's your purchasing value?");
int value = [Link]();

if ([Link]("y") && value >=500){


[Link]("You got a 20% discount");
double discount = (double) 20/100 * value;
int price = (int)(value - discount);
[Link]("Your new purchasing value is: "+price+"$");

}else if([Link]("n") ){
[Link]("You got no discount");
[Link]("Your purchasing value is: "+ value +"$");

}else if(value <500){


[Link]("You got a 10% discount");
double discount = (double) 10/100 * value;
int price = (int)(value - discount);
[Link]("Your new purchasing value is: "+price+"$");
}

}
}
Output:

Task 4:
import [Link];

public class daysfinder { public static void main(String [] args){


Scanner obj = new Scanner([Link]);
[Link]("Enter your GPA");
float gpa = [Link]();
Scanner Obj = new Scanner([Link]);
[Link]("Enter Status for your income (low/high)");
String income = [Link]();

if (gpa>=3.5 && [Link]("low")){


[Link]("You got full Scholarship");
} else if (gpa>=3.5 && [Link]("high")){
[Link]("You got Partial Scholarship");

}if (gpa<3.5){
[Link]("You got no Scholarship");
}

}
}

Output:
Task 5:
import [Link];
public class healthsystem {
public static void main(String[]args){

Scanner scanner = new Scanner([Link]);

[Link]("Enter the desired ward (General Physician / Dermatology / Orthopedics /


Pediatrics): ");
String wardType = [Link]().toLowerCase();

[Link]("Enter the booking condition (standard / emergency): ");


String bookingType = [Link]().toLowerCase();

[Link]("Do you wish to have an online consultation? (y/n): ");


String onlineConsultation = [Link]().toLowerCase();

switch (wardType) {
case "general physician":
if ([Link]("y")) {
[Link]("Available consultants: \nDr. Imran Khan: 9:00 AM to 11:00 AM \nDr.
Asim Ali: 4:00 PM to 6:00 PM");
} else {
if ([Link]("emergency")) {
[Link]("Available doctors: \nDr. Tariq Jamil: 10:00 PM to 12:00 AM \nDr.
Shahid Anwar: 6:00 PM to 8:00 PM");
} else if ([Link]("standard")) {
[Link]("Available doctors: \nDr. Huma Ahmed: 2:00 PM to 3:30 PM");
}
}
break;

case "dermatology":
if ([Link]("y")) {
[Link]("Available consultants: \nDr. Usman Farooq: 11:00 AM to 1:00 PM \
nDr. Faizan Raza: 7:30 PM to 9:00 PM");
} else {
if ([Link]("emergency")) {
[Link]("Available doctors: \nDr. Zain Ali: 6:00 PM to 8:00 PM \nDr.
Faheem Siddiqui: 5:00 PM to 6:30 PM");
} else if ([Link]("standard")) {
[Link]("Available doctors: \nDr. Mariam Malik: 12:30 PM to 2:00 PM");
}
}
break;

case "orthopedics":
if ([Link]("y")) {
[Link]("Available consultants: \nDr. Ahmed Raza: 8:00 AM to 10:00 AM \nDr.
Bilal Khan: 2:00 PM to 4:00 PM");
} else {
if ([Link]("emergency")) {
[Link]("Available doctors: \nDr. Junaid Iqbal: 7:30 AM to 9:00 AM \nDr.
Imran Khan: 4:30 PM to 6:00 PM");
} else if ([Link]("standard")) {
[Link]("Available doctors: \nDr. Rashid Aslam: 1:00 PM to 3:00 PM");
}
}
break;

case "pediatrics":
if ([Link]("y")) {
[Link]("Available consultants: \nDr. Samiullah Khan: 9:00 AM to 11:00 AM \
nDr. Ayesha Gul: 5:00 PM to 7:00 PM");
} else {
if ([Link]("emergency")) {
[Link]("Available doctors: \nDr. Haroon Ali: 6:00 PM to 8:00 PM \nDr.
Zainab Raza: 4:00 PM to 6:00 PM");
} else if ([Link]("standard")) {
[Link]("Available doctors: \nDr. Naseem Shah: 2:00 PM to 4:00 PM");
}
}
break;

default:
[Link]("Invalid ward selected. Please choose from General Physician,
Dermatology, Orthopedics, or Pediatrics.");
break;
}

}
}

Output:

Task 6:
import [Link];

public class bookingsystem {


public static void main(String [] args){
Scanner obj = new Scanner([Link]);
[Link]("Select the movie genre(action,horror,comedy,drama)");
String genre = [Link]();

int price = 100;

switch (genre){
case("action"):
[Link]("Select the Movie:\n 1) Back in Action \n 2) Mad Max Fury \n 3) Red One \n
4)Lift \n 5)Extraction \n 6)Grey Man ");
String movie = [Link]();
[Link]("Select the Seat type(regular/Vip)");
String type = [Link]();
int fare = 1000;
if ([Link]("Vip")){
fare = fare + 100;
}
[Link]("Movie: " + movie);
[Link]("Seat type: " + type);
[Link]("Ticket: "+fare);
break;

case ("comedy"):
[Link]("Select the Movie:\n 1) Bullet Train \n 2) The Big Shot \n 3) My Old Ass \n
4) Dictator 5) \n 6)Ted ");
String Movie = [Link]();
[Link]("Select the Seat type(regular/Vip)");
String tyPe = [Link]();

int Fare = 1000;


if ([Link]("Vip")){
Fare = Fare + 100;
}
[Link]("Movie: " + Movie);
[Link]("Seat type: " + tyPe);
[Link]("Ticket: "+Fare);
break;
case ("horror"):
[Link]("Select the Movie:\n 1)The Nun \n 2)Conjuring \n 3)The Ring \n 4)Anabelle
Creation\n 5)The Curse of La Llorona \n 6)Anabelle Comes home");
String MOvie = [Link]();
[Link]("Select the Seat type(regular/Vip)");
String tYpe = [Link]();

int FAre = 1000;


if ([Link]("Vip")){
FAre = FAre + 100;
}
[Link]("Movie: " + MOvie);
[Link]("Seat type: " + tYpe);
[Link]("Ticket: "+FAre);
break;
case("drama"):
[Link]("Select the Movie:\n 1)Oxygen \n 2)Uglies \n 3)Silver \n 4)Red Room\n
5)Fair Play \n 6)Everest");
String mOvie = [Link]();
[Link]("Select the Seat type(regular/Vip)");
String Type = [Link]();

int fAre = 1000;


if ([Link]("Vip")){
fAre = fAre + 100;
}
[Link]("Movie: " + mOvie);
[Link]("Seat type: " + Type);
[Link]("Ticket: "+fAre);
break;
}

}
}

Output:

Task 7:
import [Link];
public class airline {
public static void main(String[]args) {

Scanner scanner = new Scanner([Link]);


[Link]("Select your travel class:");
[Link]("1: Economy");
[Link]("2: Business");
[Link]("3: First Class");
int travelClass = [Link]();

switch (travelClass) {
case 1:
[Link]("You selected Economy Class.");
[Link]("Price: $200");
[Link]("Amenities: Standard seating, 1 free checked baggage.");
break;

case 2:
[Link]("You selected Business Class.");
[Link]("Price: $500");
[Link]("Amenities: Extra legroom, Priority boarding, 2 free checked baggage.");
break;

case 3:
[Link]("You selected First Class.");
[Link]("Price: $1000");
[Link]("Amenities: Luxury seating, Priority boarding, 3 free checked baggage,
Complimentary meals and drinks.");
break;

[Link]("Do you want to confirm your booking? (Yes/No)");


String confirmation = [Link]();

if ([Link]("Yes")) {
[Link]("Your booking has been confirmed!");
} else if ([Link]("No")) {
[Link]("Your booking has been cancelled.");
} else {
[Link]("Invalid response! Please enter 'Yes' or 'No'.");
}

}
}

Output:

Task 9:
import [Link];

public class library {


public static void main(String[] args) {
Scanner scanner = new Scanner([Link]);

String bookName = "Java Programming";


int bookAvailability = 3;
double lateFee = 0.0;
String transactionHistory = "";

[Link]("Select an operation:");
[Link]("1: Borrow a Book");
[Link]("2: Return a Book");
[Link]("3: Check Availability");
[Link]("4: Pay Late Fees");
[Link]("5: Exit");

int operation = [Link]();


switch (operation) {
case 1:
if (bookAvailability > 0) {
bookAvailability--;
transactionHistory += "Borrowed book: " + bookName + "\n";
[Link]("You have borrowed: " + bookName);
[Link]("Books remaining in library: " + bookAvailability);
} else {
[Link]("Sorry, no books are available right now.");
}
break;

case 2:
bookAvailability++;
transactionHistory += "Returned book: " + bookName + "\n";
[Link]("You have returned: " + bookName);
[Link]("Books available in library: " + bookAvailability);
break;

case 3:
[Link]("The book '" + bookName + "' has " + bookAvailability + " copies
available.");
break;

case 4:
if (lateFee > 0) {
[Link]("You have a late fee of $" + lateFee);
[Link]("Enter the amount you want to pay: ");
double payment = [Link]();
if (payment >= lateFee) {
lateFee = 0.0;
[Link]("Late fee cleared. Thank you for your payment!");
} else {
lateFee -= payment;
[Link]("Remaining late fee: $" + lateFee);
}
} else {
[Link]("You have no late fees.");
}
break;

case 5:
[Link]("Exiting the system. Goodbye!");
[Link]("Transaction History:");
[Link](transactionHistory);
break;

default:
[Link]("Invalid selection! Please choose a valid operation.");
break;
}

}
}

Output:

You might also like