Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 : check the code and psudo code is correct or not and give me desk check for this Input Processing Output parcel _

Question 1: check the code and psudo code is correct or not and give me desk check for this
Input Processing Output
parcel_weight Prompt for parcel_weight
Get parcel_weight
Check if weight is 0(exit condition)
Adjust weight (ceil if >5, max 25 kg)
Calculate delivery_charge
Display delivery_charge delivery_charge
A pseudo code algorithm
1. BEGIN
2. FUNCTION main()
3. CREATE scanner for input
4. WHILE true DO
5. PROMPT "Enter parcel weight in kg (0 to exit): "
6. TRY
7. READ weight
8. IF weight <0 THEN PRINT "Invalid weight. Please enter a positive number." CONTINUE
9. CATCH InputMismatchException
10. PRINT "Please enter a valid number." CLEAR input
11. IF weight ==0 THEN PRINT "Exiting program..." EXIT loop
12. IF weight >5 THEN weight = ceiling(weight)
13. IF weight >25 THEN weight =25 PRINT "Weight adjusted."
14. deliveryCharge = calculateDeliveryCharge(weight)
15. PRINT "Delivery charge: $"+ deliveryCharge
16. ENDWHILE
17. CLOSE scanner
18. END FUNCTION
19. FUNCTION calculateDeliveryCharge(weight)
20. IF weight <3 THEN RETURN 8.00 ELSE IF weight <=5 THEN RETURN 12.00 ELSE RETURN 12.00+(weight -5)*1.50
21. END FUNCTION
22. END
import java.util.InputMismatchException;
import java.util.Scanner;
public class DeliveryService {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
while (true){
System.out.print("Enter parcel weight in kg (0 to exit): ");
double weight;
try {
weight = scanner.nextDouble();
if (weight <0){
System.out.println("Invalid weight. Please enter a positive number.");
continue;
}
} catch (InputMismatchException e){
System.out.println("Please enter a valid number.");
scanner.nextLine(); // Clear the invalid input
continue;
}
if (weight ==0){
System.out.println("Exiting program...");
break;
}
if (weight >5){
weight = Math.ceil(weight);
}
if (weight >25){
weight =25;
System.out.println("Weight adjusted to maximum allowed (25 kg).");
}
double deliveryCharge = calculateDeliveryCharge(weight);
System.out.println("Delivery charge: $"+ deliveryCharge);
}
scanner.close();
}
public static double calculateDeliveryCharge(double weight){
if (weight <3){
return 8.00;
} else if (weight <=5){
return 12.00;
} else {
return 12.00+(weight -5)*1.50;
}
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

What should Sheila have done to avoid interviews like this one?

Answered: 1 week ago