Question
need some help with this java program By using Programming Assignment 2 solution which is below, where your program must have been written using methods,
need some help with this java program
By using Programming Assignment 2 solution which is below, where your program must have been written using methods, constructors and objects, you are to rewrite it to accomplish the following tasks for this assignment 3.
Part I
Text I/O [Additional input]: You should enter a shipping companys Name, Address, quantity of parcels shipped in each weight bracket. The output should be stored in a file (). Your output on the file should be descriptive.
The Output should contain the following:
Companys: Name and Address
Weight Bracket: Quantity Shipped
Cost of shipping to: Canada, USA, Europe or South America
Total Cost: For all Quantity of goods shipped
Part II
Exception handling:
Only accepted input should be entered, all other error and/or exceptions should be handle and the user allowed to re-enter the correct input only up to 3 times. If the user enters incorrect entry twice, the program warns him as
All output should be free of errors and well formatted.
If correct input is entered, the user could be asked to terminate the program or allowed to enter different input. All entries made by the user should be saved into the text file.
Part III
Comments: Provide comments to your code using Javadoc, class header comments, and section and method comments describing the task the section/method is performing.
Deliverables:
Note:
Project name: ProgrammingAssignment_3
Class name: ProgrammingAssignment_3
Text file name: ProgrammingAssignment_3.txt
Here is the assginment 2 solution with the output:
package Inconu;
import java.util.Scanner;
public class ProgrammingAssignment_2 {
public static void main(String [] args){
//Scanner to take all users input
Scanner input = new Scanner(System.in);
//Declare variables
int shippingLocation;
String another;
double totalShipping = 0; //variable for cost of all locations
int counter = 0;
do{
//Displays the available shipping locations and prompts user for location
System.out.println("Shipping Locations: " + "1, If Local(US) " + "2, If Canada " +
"3, If South America " + "4, If Europe ");
System.out.print("Select a shipping location: ");
shippingLocation = input.nextInt();
//error check to ensure user enters a location between 1-4
while (shippingLocation <=0 || shippingLocation >=5){
System.out.print("Enter a location between 1 and 4: ");
shippingLocation = input.nextInt();
}
//creates an array for the number of packages the users can ship.
//User can only input weights between 4 ranges
int[] packageArray = new int[4];
//Prompts the user for the quantity of packages within the given ranges,
//the input is entered to package array index 0 through 3.
System.out.println("Enter the number of packages shipped or 0 if no packages.");
for(int i=0; i < packageArray.length; i++)
{
if (i == 0)
{
System.out.print("Packages of weight range 0 < w <= 1: ");
}
if (i == 1)
{
System.out.print("Packages of weight range 1 < w <= 3: ");
}
if (i == 2)
{
System.out.print("Packages of weight range 3 < w <= 10: ");
}
if (i == 3)
{
System.out.print("Packages of weight range 10 < w <= 20: ");
}
packageArray[i] =input.nextInt();
}
//Outputs to console the cost of shipping and method calls for all shipping locations
//shipping Locally(US)
if(shippingLocation == 1){
double cost = localShipment(packageArray);
totalShipping = totalShipping + cost;
System.out.println(" Cost of shipping to Local(US): $" +cost);
}
//Shipping to Canada
else if(shippingLocation == 2){
double cost = canadaShipment(packageArray);
totalShipping = totalShipping + cost;
System.out.println(" Cost of shipping to Canada: $" + cost);
}
//Shipping to South America
else if(shippingLocation == 3){
double cost = southAmericaShipment(packageArray);
totalShipping = totalShipping + cost;
System.out.println(" Cost of shipping: $" + cost);
}
//Shipping to Europe
else{
double cost = europeShipment(packageArray);
totalShipping = totalShipping + cost;
System.out.println(" Cost of shipping: $" + cost);
}
//prompt user whether they want to ship packages to a different location
input = new Scanner(System.in);
System.out.print("Do you wish to ship to a different location? (y/n)");
another =input.nextLine();
counter++;
//"do-while" location entered is less than 4 and if the user enters y for yes.
//This loop terminated when user enters n for no.
}while(counter < 4 && another.equalsIgnoreCase("yes") || another.equalsIgnoreCase("y"));
//Displays the cost of shipping to all locations entered by user.
System.out.println(" Total shipping cost to selected locations: $" + totalShipping);
}
//Local shipment method called from main.
//This return method calculates the cost of shipping by taking user input from package array
//and multiplying by the price of then weight. This return method returns the cost of shipping.
public static double localShipment(int[] packageArray){
double total = 0;
for (int i =0; i < packageArray.length; i++) {
double current =0;
if (i == 0)
{
current = 3.5 * packageArray[i];
}else if (i == 1)
{
current = 5.5 * packageArray[i];
}
else if (i == 2)
{
current = 8.5 * packageArray[i];
}
else if (i == 3)
{
current = 10.5 * packageArray[i];
}
total = total + current;
}
return total;
}
//Canada shipment method called from main.
//This return method calculates the cost of shipping by taking user input from package array
//and multiplying by the price of then weight. This return method returns the cost of shipping.
public static double canadaShipment(int[] packageArray){
double total = 0;
for (int i =0; i < packageArray.length; i++) {
double current =0;
if (i == 0)
{
current = 4.5 * packageArray[i];
}else if (i == 1)
{
current = 6.5 * packageArray[i];
}
else if (i == 2)
{
current = 10.5 * packageArray[i];
}
else if (i == 3)
{
current = 12.5 * packageArray[i];
}
total = total + current;
}
return total;
}
//SouthAnerica shipment method called from main.
//This return method calculates the cost of shipping by taking user input from package array
//and multiplying by the price of then weight. This return method returns the cost of shipping.
public static double southAmericaShipment(int[] packageArray){
double total = 0;
for (int i =0; i < packageArray.length; i++) {
double current =0;
if (i == 0)
{
current = 5.5 * packageArray[i];
}else if (i == 1)
{
current = 7.5 * packageArray[i];
}
else if (i == 2)
{
current = 9.5 * packageArray[i];
}
else if (i == 3)
{
current = 11.5 * packageArray[i];
}
total = total + current;
}
return total;
}
//Local shipment method called from main.
//This return method calculates the cost of shipping by taking user input from package array
//and multiplying by the price of then weight. This return method returns the cost of shipping.
public static double europeShipment(int[] packageArray){
double total = 0;
for (int i =0; i < packageArray.length; i++) {
double current =0;
//
if (i == 0)
{
current = 7.5 * packageArray[i];
}else if (i == 1)
{
current = 9.5 * packageArray[i];
}
else if (i == 2)
{
current = 11.0 * packageArray[i];
}
else if (i == 3)
{
current = 15.0 * packageArray[i];
}
total = total + current;
}
return total;
}
}
output:
Shipping Locations:
1, If Local(US)
2, If Canada
3, If South America
4, If Europe
Select a shipping location: 2
Enter the number of packages shipped or 0 if no packages.
Packages of weight range 0 < w <= 1: 4
Packages of weight range 1 < w <= 3: 7
Packages of weight range 3 < w <= 10: 2
Packages of weight range 10 < w <= 20: 4
Cost of shipping to Canada: $134.5
Do you wish to ship to a different location? (y/n)n
Total shipping cost to selected locations: $134.5
PLEASE SHOW ME YOUR OUTPUT AND ALL THE PROGRAM FOR ASSignment 3. THANKS
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started