Slab-Based Java Programs Overview
Slab-Based Java Programs Overview
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 .