Question: JAVA Program The objectives of this assignment are: Demonstrate you can create and execute successfully a program organized into multiple methods. NOTE No new function

JAVA Program

The objectives of this assignment are:

Demonstrate you can create and execute successfully a program organized into multiple methods. NOTE No new function is being added in this assignment, just organizing it to make it more readable and more abstract.

Learn how methods are a way of organizing your code into sections. Your main method is less cluttered if it calls methods created elsewhere in your program. Example: instead of all the code to display a Shipment in main, you need only a one-line call to a method. Its a form of abstraction which makes your program easier to read. Its kind of like outlining a long complex document into layers of complexity.

Demonstrate you can post your source program and execution results in the assignment Dropbox in the Assessment area of eCourseware.

The activities of this assignment are:

Program Assignment 4: Create a program named ShipmentMethodsYourName.

Create a copy of ShipmentDisplayLoopYourName named ShipmentMethodsYourName.

Modify the new program to add this functionality:

Create a method named displayShipment and call it to display each shipment.

Create a method name displayTotals and call it to display the shipment count and total cost.

Optionally created a method named computeCost and call it to compute the cost.

Program built off the previous assignment

import java.util.Scanner;

import java.util.Date;

public class ShipmentDisplayLoopLastNMFirstName

{

public static void main(String[] args)

{

// Create Scanner & Define Variables

Scanner input = new Scanner (System.in);

String shipID;

double shipWeight;

double shipVolume;

int shipTotal = 0;

double shipCostTotal = 0;

String shipOrigin;

String shipDestination;

// Prompts & Read User Input

//start if while loop

while ( true )

{

System.out.print(" Input Shipment ID:");

shipID = input.next();

if (shipID.equals("end") | shipID.equals("END"))

break; // end the loop if END or end entered

System.out.print("Enter the Shipment Weight:");

shipWeight = input.nextDouble();

System.out.print("Enter the Shipment Volume:");

shipVolume = input.nextDouble();

System.out.print("Enter the Shipment Origin:");

shipOrigin = input.next();

System.out.print("Enter the Shipment Destination:");

shipDestination = input.next();

//check for invalid shipments

if (shipWeight > 70) ////if statement for weight

{ System.out.println(" Shipment ID: "

+ shipID

+ " <<<=== Shipment Ignored, Shipment Exceeded Weight! "

);

continue;

} // end if true condition

else

{

if (shipVolume > 120) ////if statement for volume

{ System.out.println(" Shipment ID: "

+ shipID

+ " <<<=== Shipment Ignored, Shipment Exceeded Volume! "

);

continue;

} // end else condition

} //////end if

// Calculations for weight and volume

double shipCost = ((shipWeight * 10) + (shipVolume * 1.5));

System.out.println(" Shipment Cost is $" + shipCost);

shipTotal++; // add 1 to count

shipCostTotal += shipCost; // add cost to total

} //end while loop

//leave class and date and total calculations at the bottom of code

Date date = new Date();

System.out.println(" Shipment Count:"

+ shipTotal

+ " Total Cost Of All Valid Shipments: $"

+ shipCostTotal

+ " " // new line

+ "MIS-2845 Applied Program Development I "

+ " " // new line

+ "ShipmentLoopDisplayLastNMFirstNM"

+ " " // new line

+ date

);

} // end main method

} //end ShipmentDisplayLoopLastNMFirstName class

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!