[Go to site: main page, start]

0% found this document useful (0 votes)
158 views8 pages

Slab-Based Java Programs Overview

The document contains multiple Java programs that calculate various charges and bills based on user input, including truck fares, electricity bills, water usage, internet data usage, income tax, movie ticket pricing, parking fees, mobile call charges, speeding fines, and hotel room booking charges. Each program uses a while loop to iterate through the input values and compute the total cost based on specified conditions. The results are printed to the console for the user to see.

Uploaded by

kandoirishab8
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)
158 views8 pages

Slab-Based Java Programs Overview

The document contains multiple Java programs that calculate various charges and bills based on user input, including truck fares, electricity bills, water usage, internet data usage, income tax, movie ticket pricing, parking fees, mobile call charges, speeding fines, and hotel room booking charges. Each program uses a while loop to iterate through the input values and compute the total cost based on specified conditions. The results are printed to the console for the user to see.

Uploaded by

kandoirishab8
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

Slab-Based Java Programs Using While

Loop
Truck Fare Calculation

import [Link];

public class TruckFareCalculator {


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

int km;
[Link]("Enter total distance in kilometers: ");
km = [Link]();

int totalFare = 0;
int distanceCovered = 0;

while (distanceCovered < km) {


if (distanceCovered < 1) {
totalFare += 1000;
distanceCovered++;
} else if (distanceCovered >= 1 && distanceCovered < 3) {
totalFare += 2000;
distanceCovered++;
} else {
totalFare += 3000;
distanceCovered++;
}
}

[Link]("Total fare for " + km + " km is: ₹" + totalFare);


}
}

Electricity Bill Calculation

import [Link];
public class ElectricityBill {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int units;
[Link]("Enter total units consumed: ");
units = [Link]();

int bill = 0;
int i = 1;

while (i <= units) {


if (i <= 100) {
bill += 5;
} else if (i <= 200) {
bill += 7;
} else {
bill += 10;
}
i++;
}

[Link]("Total electricity bill: ₹" + bill);


}
}

Water Usage Billing

import [Link];

public class WaterBill {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int liters;
[Link]("Enter total water consumed (liters): ");
liters = [Link]();

int charge = 0;
int i = 1;

while (i <= liters) {


if (i <= 50) {
charge += 1;
} else if (i <= 100) {
charge += 2;
} else {
charge += 5;
}
i++;
}

[Link]("Total water bill: ₹" + charge);


}
}

Internet Data Usage Billing

import [Link];

public class InternetBill {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int gb;
[Link]("Enter total data used (in GB): ");
gb = [Link]();

int total = 0;
int i = 1;

while (i <= gb) {


if (i <= 2) {
total += 50;
} else if (i <= 5) {
total += 75;
} else {
total += 100;
}
i++;
}

[Link]("Total internet bill: ₹" + total);


}
}

Income Tax Calculator

import [Link];

public class IncomeTax {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int income;
[Link]("Enter annual income: ₹");
income = [Link]();

int tax = 0;
int i = 1;

while (i <= income) {


if (i <= 250000) {
// No tax
} else if (i <= 500000) {
tax += 5;
} else if (i <= 1000000) {
tax += 10;
} else {
tax += 20;
}
i += 1000;
}

[Link]("Estimated tax (approx): ₹" + tax * 10);


}
}

Movie Ticket Pricing

import [Link];

public class MovieTicket {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int seat;
[Link]("Enter seat number: ");
seat = [Link]();

int cost = 0;
int i = 1;

while (i <= seat) {


if (i <= 50) {
cost = 100;
} else if (i <= 100) {
cost = 150;
} else {
cost = 200;
}
i++;
}

[Link]("Ticket price: ₹" + cost);


}
}

Parking Fee Based on Hours

import [Link];

public class ParkingFee {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int hours;
[Link]("Enter hours parked: ");
hours = [Link]();

int fee = 0;
int i = 1;

while (i <= hours) {


if (i <= 2) {
fee += 20;
} else if (i <= 5) {
fee += 30;
} else {
fee += 50;
}
i++;
}

[Link]("Total parking fee: ₹" + fee);


}
}

Mobile Call Charges

import [Link];

public class CallCharges {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int mins;
[Link]("Enter call duration (in minutes): ");
mins = [Link]();

int cost = 0;
int i = 1;

while (i <= mins) {


if (i <= 3) {
cost += 1;
} else if (i <= 8) {
cost += 2;
} else {
cost += 3;
}
i++;
}

[Link]("Total call cost: ₹" + cost);


}
}
Speeding Fine Calculator

import [Link];

public class SpeedFine {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int speedLimit, actualSpeed;
[Link]("Enter speed limit: ");
speedLimit = [Link]();
[Link]("Enter actual speed: ");
actualSpeed = [Link]();

int overSpeed = actualSpeed - speedLimit;


int fine = 0;
int i = 1;

while (i <= overSpeed) {


if (i <= 10) {
fine += 100;
} else if (i <= 20) {
fine += 200;
} else {
fine += 500;
}
i += 10;
}

if (overSpeed > 0) {
[Link]("Speeding fine: ₹" + fine);
} else {
[Link]("No fine.");
}
}
}

Hotel Room Booking Charges

import [Link];

public class HotelBooking {


public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
int days;
[Link]("Enter number of days booked: ");
days = [Link]();

int total = 0;
int i = 1;

while (i <= days) {


if (i <= 2) {
total += 1000;
} else if (i <= 5) {
total += 1500;
} else {
total += 2000;
}
i++;
}

[Link]("Total hotel bill: ₹" + total);


}
}

Common questions

Powered by AI

The Internet Data Usage Billing program calculates charges by iterating through the data consumed in GBs and applying different rates as defined by slabs within a while loop. For the first 2 GB, a rate of 50 per GB is applied. For usage between 3 and 5 GB, the rate increases to 75 per GB, and for any data usage beyond 5 GB, the rate further rises to 100 per GB. This step-by-step approach helps to accommodate varying data usage patterns, penalizing higher consumption with increased rates for a structured billing plan .

The Parking Fee Calculation program employs a step-wise fee determination method, incrementing the fee based on parked hours using a while loop. For the first 2 hours, a fee of 20 per hour is charged. Between 3 and 5 hours, the charge increases to 30 per hour, and for parking beyond five hours, the hourly rate jumps to 50. This scheme ensures that longer parking durations incur higher fees, encouraging efficient use of parking space and aligning with typical parking management policies .

The Electricity Bill program uses a while loop to iterate over each unit consumed, applying different rates depending on the total units. For the first 100 units, a charge of 5 per unit is added. For units between 101 and 200, a charge of 7 per unit is applied, and for any consumption above 200 units, a charge of 10 per unit is added. This tiered billing system calculates the total bill by incrementally adding the appropriate charges for each unit consumed .

The Hotel Room Booking Charges program calculates the total cost based on the number of days by applying different nightly rates depending on how many days the guest stays, using a while loop to facilitate this tiered structure. For a stay of up to 2 days, a rate of 1000 per night is charged. For stays between 3 to 5 days, the rate increases to 1500 per night. Beyond 5 days, the cost rises to 2000 per night. This pricing model encourages longer bookings with proportionally increased charges to maximize occupancy revenue while considering room availability .

Slab-based billing in the Water Usage Billing program refers to charging different rates based on the volume of water consumed, divided into specific slabs. The program uses a while loop to iterate through each liter of water consumed. For the first 50 liters, the charge is 1 per liter. For consumption between 51 and 100 liters, the rate increases to 2 per liter, and for any consumption above 100 liters, the rate goes up to 5 per liter. This method ensures that the bill reflects increased consumption with proportionately higher charges, incentivizing reduced usage .

The Speeding Fine Calculator calculates fines by determining how much the actual speed exceeds the speed limit, then applying graduated fines per 10-unit increments of overspeed. A while loop iterates based on the speed differential. For an overspeed between 1 and 10, a fine of 100 is applied. If the over speed is between 11 and 20, the fine increases to 200. Beyond 20, to effectively handle high overspeeding, the fine surges to 500 per 10 units. This graduated approach promotes adherence to speed limits by imposing heavier penalties for greater deviations .

The Mobile Call Charges program applies charges based on slabs defined by the call duration in minutes using a while loop for system iteration. For calls lasting up to 3 minutes, the charge is 1 per minute. For durations between 4 and 8 minutes, the rate escalates to 2 per minute. For calls exceeding 8 minutes, the charge peaks at 3 per minute. This structure provides a simple yet effective way to rate calls efficiently, introducing higher rates for longer calls to enhance revenue from extended service usage .

In the Movie Ticket Pricing program, the cost per seat is determined by the seat number within predefined ranges, using a while loop to compare seat numbers. Seats numbered 1 to 50 incur a price of 100. Seats from 51 to 100 increase to 150. Any seat number greater than 100 is priced at 200. This pricing model reflects a tiered strategy where each subsequent range incurs higher charges, potentially based on factors like proximity to the screen or demand .

The Income Tax Calculator uses a while loop to iterate through each 1000 units of annual income, applying different tax rates based on predefined slabs. No tax is applied for income up to 250,000. For income between 250,001 and 500,000, a tax of 5 per 1000 is added. Income between 500,001 and 1,000,000 incurs a tax of 10 per 1000, and any income beyond 1,000,000 is taxed at 20 per 1000. The final tax value is multiplied by 10 to approximate the total tax payable. This slab-based approach allows for a progressive tax system where higher incomes are taxed at higher rates .

The Truck Fare Calculation program determines the total fare by iterating over the distance traveled in kilometers and applying different fare rates using a while loop. If the distance covered is less than 1 km, the fare is increased by 1000 for each kilometer. If the distance covered is between 1 and 3 km, the fare is increased by 2000 per kilometer. For distances over 3 km, the fare increases by 3000 per kilometer. This incremental approach ensures that the total fare accumulates correctly based on the distance slabs defined .

You might also like