Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!