Please use to first assignment in order to proceed with second assignment. Assig
ID: 3755122 • Letter: P
Question
Please use to first assignment in order to proceed with second assignment.
Assignment 2
The objectives of this assignment are:
Demonstrate you can create and execute successfully a simple input and output program with simple math.
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 2: Create a program named ShipmentDisplayYourName.
Using a Scanner object read and display using System.out.println the following data items/fields for a Shipment. Display a request line before reading the data item with scanner such as this: System.out.print(“ Enter the Shipment ID: “);
Shipment ID: String shipId: Example:
Import Java.util.Scanner;
Scanner input = new Scanner (System.in);
String shipId;
System.out.print(“ Enter the Shipment ID: “);
shipId = input.next();
Shipment weight: int shipWeight Example:
String shipWeight;
System.out.print(“ Enter the Shipment Weight: “);
shipWeight = input.nextint();
Shipment volume: int shipVolume
Shipment origin station: String shipOrigin
Shipment destination station: String shipDestination
Calculate and display the a double named shipCost which is shipWeight times 10 plus shipVolume times 1.5. A double is defined and used like an int but allows decimal points.
Example: double shipCost;
Display the class name and date on a separate line.
Run your program.
Post your source program as a .java file in the Program 2 dropbox in the Assessments area of eCourseware.
Post the results of your program as a screen shot in the Program 2 Dropbox in the Assessments area of eCourseware. Or copy and paste both into a Word document and post that in the Program 2 Dropbox in the Assessments area of eCourseware.
--------------------------------------------------------------------------------------------------------------------------------------
Assignment 3
The objectives of this assignment are:
Demonstrate you can create and execute successfully a program with a loop to process multiple Shipments and use the if conditional statement and compute and display totals at the end.
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 3: Create a program named ShipmentDisplayLoopYourName.
Create a copy of ShipmentDisplayYourName named ShipmentDisplayLoopYourName.
Modify the new program to add this functionality:
Use a while loop to process multiple Shipments.
Break out of the loop if Shipment ID entered is END or end.
Ignore Shipments with weight greater than 70 weight or volume greater than 120.
Count the number of processed Shipments.
Total up the Shipment Cost.
Display the count and total after the loop has ended.
Explanation / Answer
Please replace YourName in both the class names with your actual name.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
Assignment1
===========
import java.util.Scanner;
public class ShipmentDisplayYourName {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
String shipId;
int shipWeight;
int shipVolume;
System.out.print("Enter the Shipment ID: ");
shipId = input.next();
System.out.print("Enter the Shipment Weight: ");
shipWeight = input.nextInt();
System.out.print("Enter the Shipment Volume: ");
shipVolume = input.nextInt();
double shipCost = shipWeight * 10 + shipVolume * 1.5;
System.out.println("The cost of shipping is " + shipCost);
}
}
Assignment2
--------------
import java.util.Scanner;
public class ShipmentDisplayLoopYourName {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
String shipId;
int shipWeight;
int shipVolume;
int totalCount = 0, processedCount = 0;
int totalCost = 0;
while(true){
System.out.print("Enter the Shipment ID: ");
shipId = input.next();
if(shipId.equals("END") || shipId.equals("end"))
break;
System.out.print("Enter the Shipment Weight: ");
shipWeight = input.nextInt();
System.out.print("Enter the Shipment Volume: ");
shipVolume = input.nextInt();
if(shipWeight > 70 || shipVolume > 120)
System.out.println("Ignoring this shipment");
else
{
processedCount++;
double shipCost = shipWeight * 10 + shipVolume * 1.5;
totalCost += shipCost;
}
totalCount++;
}
System.out.println("Total input shipments: " + totalCount);
System.out.println("Processed shipments: " + processedCount);
System.out.println("The total cost of shipping is " + totalCost);
}
}
output
-----
Enter the Shipment ID: A111
Enter the Shipment Weight: 30
Enter the Shipment Volume: 20
Enter the Shipment ID: B123
Enter the Shipment Weight: 100
Enter the Shipment Volume: 90
Ignoring this shipment
Enter the Shipment ID: C222
Enter the Shipment Weight: 50
Enter the Shipment Volume: 40
Enter the Shipment ID: D444
Enter the Shipment Weight: 70
Enter the Shipment Volume: 130
Ignoring this shipment
Enter the Shipment ID: end
Total input shipments: 4
Processed shipments: 2
The total cost of shipping is 890