|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Need help on how to display the message for my practise in java
hi I kind of need some help you see I want to display the message that says on the javac in command prompt that says
//Enter parcel weight: //200 //A 200 gram parcel costs $2.50 to deliver. the problem is the formula that bothers me a lot Weight Range Delivery Cost Up to 200 grams 2.50 201 to 500 grams 4.00 501 to 100 grams 6.50 1001 to 5 kg 6.50 plus 50 cents for each additional 500 grams or part there of Over 5 kg 14.00 Parcels over 15kg are not accepted the formula that I can come up with is 1001-501/500*0.50 + 6. 50 is 7.00 but when it says over 5kg (5000 grams) for 5001 grams and up to 15 kg the number is that not good since if I use 5001-501/500*0.50+6.50 is 11.00 that's where I want the number over 5kg up to 15kg is 14.00 here's the code that I have written. /* File: DeliveryCompany.java Author: Andrew Date: September 18 2007 Purpose: To show that the Parcel deliver shows the actually values */ import java.util.Scanner; import java.text.DecimalFormat; public class DeliveryCompany { private static DecimalFormat currency = new DecimalFormat("$ #, ## 0.00"); public static void main(String[] args) { //Declartions int weightParcel; = 0; double deliveryCost; = 0; double newWeightParcel; = 0; Scanner input = new Scanner(System.in); //prompt the user for entering the parcel weight System.out.println("Please enter parcel weight"); weightParcel = input.nextInt(); //convert delivery cost into money sign deliveryCost(Currency.format(deliveryCost); // make decision on weight parcel if(weightParcel < = 0) { if(weightParcel <= 201) { if(weightParcel <=501) { if(weightParcel <= 1001) { if(weightParcel <= 5001) { if (weightParcel <= 150001) { deliveryCost = 0; } else { deliveryCost = 14.00; } } else { newWeightParcel = weightParcel-1001/500*0.50 +6.50; } } else { deliveryCost = 6.50; } } else { deliveryCost = 4.00; deliveryCost = 2.50; } else { system.out.print("Sorry that number is invalid.") } } } // display results System.out.print("A " + weightParcel + "will cost" + deliveryCost + "to deliver"); } } |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > Need help on how to display the message for my practise in java |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|