1.Algorithm:
Step 1: Initialize the variable to store the data
Step 2: Display the Welcome message
Step 3: Display the Menu
Step 4: Get the menu option from the user
Step 5: If the User Selects Setup Cost Per KM option perform step 6 and 7 else move to Step 10
Step 6: Get the costs per km for a package to be sent for 100KM or less distance from the User
Step 7: Get the costs per km for a package to be sent for over 100KM distance from the User
Step 8: Display the details entered by the user
Step 9: Go to Step 3
Step 10: If the User Selects Enter Parcel option perform step 11 to 17 else move to Step 18
Step 11: Get the receiver name of the package from the User
Step 12: Get the weight of the package from the User
Step 13: Get whether the insurance is required for the package from the User
Step 14: Get the number of KMs the package wants to travel from the User
Step 15: Display the details entered by the user
Step 16: Compute the delivery date of the package
Step 17: Go to Step 3
Step 17: If the User Selects Display Parcel Delivery Costs option perform step 18 to 23 else move to Step 24
Step 18: Compute the transportation cost by multiplying the distance and its corresponding cost
Step 19: Determine the insurance cost if the insurance is required for the package
Step 20: Compute the total cost i.e. transportation cost + insurance cost
Step 21: Display the cost details
Step 22: Display the delivery date of the package
Step 23: Go to Step 3
Step 24: If the user select the Exit System option perform step 25 else go to step 27
Step 25: Display the Exit message to the user
Step 26: Terminate the program execution
Step 27: If the user enters none of the option; Display the message of invalid choice and Go to Step 3
2.Program:
package transportapplication;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;
public class TransportApplication {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
// Display the header message
for(int i=0;i<40;i++) {
System.out.print(“-+”);
}
System.out.println();
for(int i=0;i<10;i++) {
System.out.print(” “);
}
System.out.println(“FEDERATION UNIVERSITY AUSTRALIA – MT HELEN”);
System.out.println(“”);
for(int i=0;i<10;i++) {
System.out.print(” “);
}
System.out.println(“Christmas Parcel Delivery Calculator”);
System.out.println();
System.out.println(” Developed by Arslan Ahmed, Student ID: 30338159 for ITECH1000 Summer 2017″);
System.out.println();
for(int i=0;i<40;i++) {
System.out.print(“-+”);
}
System.out.println();
boolean loop=true;
// variable to store the data
float costLessThan100=0, costOver100=0;
String receiversName=””;
float parcelWeight=0;
String insurenceRequired=””;
int distance=0;
float INSURENCE_PARAMETER=(float) 0.53;
//date to store the current time
Date deliveryDate=new Date();
// format in which date should be displayed
DateFormat dateFormat = new SimpleDateFormat(“EEE MMM dd HH:mm:ss z yyyy”);
while(loop)
{
//display the menu
displayMenu();
//get the choice from the user
int choice=sc.nextInt();
switch(choice)
{
case i:
// When Setup Cost Per KM is selected
System.out.print(“Enter how much it costs per km for a package to be sent 100KM or less: $ “);
costLessThan100=sc.nextFloat();// receive costs per km of the package sent 100KM or less
System.out.print(“Enter how much it costs per km for a package to be sent over 100KM: $ “);
costOver100=sc.nextFloat();// receive costs per km of the package sent over 100KM
System.out.println();
//display the cost of the package per km
System.out.println(“The cost for a parcel to be sent 100km or less is $”+costLessThan100+” per km.”);
System.out.println(“The cost for a parcel to be sent more than 100km is $”+costOver100+” per km”);
break;
case ii:
// When Enter Parcel is selected
System.out.print(“Enter receivers name: “);
receiversName=sc.next();//receive the receivers name of the package
System.out.print(“Enter weight of parcel: “);
parcelWeight=sc.nextFloat();//receive the weight of the package
System.out.print(“Do you want insurance (Y or N)? “);
insurenceRequired =sc.next();//receive the insurance status of the package
System.out.print(“How far do you want to send the parcel (km)? “);
distance=sc.nextInt();//receive the number of km the package must be sent
System.out.println();
//display the parcel package information
System.out.println(“You have entered the following details:”);
System.out.println(“Receivers Name: “+ receiversName);
System.out.println(“Parcel Weight: “+ parcelWeight );
System.out.println(“Insurance: “+ (insurenceRequired.equals(“Y”)?”true”:”false”) );
System.out.println(“KM to be sent: “+ distance);
//calculate the delivery date of the package from the distance
deliveryDate=getDeliveryDate(distance);
break;
case iii:
// when Display Parcel Delivery Costs is selected
System.out.println(“ntt+++++ Calculating Costs +++++”);
float transportationCost=0;
//calculate the transportationCost based on the distance the parcel requires to travel
if(distance<=100) {
transportationCost=distance*costLessThan100;
} else {
transportationCost=distance*costOver100;
}
float insurenceCost=0;
//calculate the insurence cost based on the insurence requirement of the package
if(insurenceRequired.equals(“Y”)) {
insurenceCost=parcelWeight*INSURENCE_PARAMETER;
}
// calculate the total cost of the package
float totalCost=transportationCost+insurenceCost;
// display the cost details
System.out.println(“ttTransportation Costs: “+Math.round(transportationCost*100.0)/100.0);
System.out.println(“ttInsurance Costs: “+ Math.round(insurenceCost*100.0)/100.0);
System.out.println(“ttTotal Costs: “+Math.round(totalCost*100.0)/100.0);
System.out.println(“nttThe parcel will arrive at: “+dateFormat.format(deliveryDate));
System.out.println(“tt+++++++++++++++++++++++++++++”);
break;
case iv:
// When Exit System is selected
System.out.println(“nThank you for using this calculator!”);
loop=false;//set loop to false to stop the loop
break;
default:
System.out.println(“Invalid Choice- Please enter the correct choice”);
break;
}
}
}
private static void displayMenu() {
System.out.println(“nMain Menu”);
System.out.println(“1. Setup Cost Per KM”);
System.out.println(“2. Enter Parcel”);
System.out.println(“3. Display Parcel Delivery Costs”);
System.out.println(“4. Exit System “);
}
private static Date getDeliveryDate(int distance) {
/*
Compute the delivery date by considering it takes 1 day to travel 10Km
*/
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.DATE, distance/10);
return calendar.getTime();
}
}
Output:
3.Testing Base Requirement:
Test Case |
Expected Result |
Actual Result |
The user selects the menu option: Setup Cost Per KM |
The user is prompted to enter the travel cost (per KM) for a package sent under 100KM and sent over 100KM |
Enter how much it costs per km for a package to be sent 100KM or less: $ 0.59 Enter how much it costs per km for a package to be sent over 100KM: $ 0.86 |
The user selects the menu option: Enter Parcel |
The user is prompted to enter the receivers name, the weight of the parcel, if they want insurance and how far the parcel is to be sent |
Enter receivers name: Greg Enter weight of parcel: 100 Do you want insurance (Y or N)? Y How far do you want to send the parcel (km)? 512 |
The user selects the menu option: Display Parcel Delivery Costs |
Displays calculation of the transportation, insurance and total costs |
Transportation Costs: 440.32 Insurance Costs: 53.0 Total Costs: 493.32 |
The user selects the menu option: Exit System |
Quit the program with a message to the user |
The program terminates with the message Thank you for using this calculator! |
The user selects the menu option: Not of the above choice |
Displays the message Invalid Choice- Please enter the correct choice |
Testing Standard Requirement:
Test Case |
Expected Result |
Actual Result |
Modularity |
Modularize the code |
The code is modularized with two function displayMenu() and getDeliveryDate() |
Comment |
The code is commented |
|
Adding Magic Numbers |
float INSURENCE_PARAMETER=(float) 0.53; |
Testing Advance Requirement:
Test Case |
Expected Result |
Actual Result |
The user selects the menu option: Display Parcel Delivery Costs |
Displays when the parcel will arrive |
Transportation Costs: 440.32 Insurance Costs: 53.0 Total Costs: 493.32 The parcel will arrive at: Sat Feb 24 19:30:26 EST 2018 |
Essay Writing Service Features
Our Experience
No matter how complex your assignment is, we can find the right professional for your specific task. Contact Essay is an essay writing company that hires only the smartest minds to help you with your projects. Our expertise allows us to provide students with high-quality academic writing, editing & proofreading services.Free Features
Free revision policy
$10Free bibliography & reference
$8Free title page
$8Free formatting
$8How Our Essay Writing Service Works
First, you will need to complete an order form. It's not difficult but, in case there is anything you find not to be clear, you may always call us so that we can guide you through it. On the order form, you will need to include some basic information concerning your order: subject, topic, number of pages, etc. We also encourage our clients to upload any relevant information or sources that will help.
Complete the order formOnce we have all the information and instructions that we need, we select the most suitable writer for your assignment. While everything seems to be clear, the writer, who has complete knowledge of the subject, may need clarification from you. It is at that point that you would receive a call or email from us.
Writer’s assignmentAs soon as the writer has finished, it will be delivered both to the website and to your email address so that you will not miss it. If your deadline is close at hand, we will place a call to you to make sure that you receive the paper on time.
Completing the order and download