Question

In: Computer Science

I need this in java A6 – Shipping Calculator Assignment Introduction In this part, you will...

I need this in java

A6 – Shipping Calculator

Assignment

Introduction

In this part, you will solve a problem described in English. Although you may discuss ideas with your classmates, etc., everyone must write and submit their own version of the program. Do NOT use anyone else’s code, as this will result in a zero for you and the other person!

Shipping Calculator

Speedy Shipping Company will ship your package based on the weight and how far you are sending the package, which can be anywhere in the world. They will only ship small packages up to 10 pounds. You need to have a program, which will help you determine how much they will charge.

The charges are based on each 500 miles shipped. The mileage should be in whole numbers. They are not prorated, i.e., 600 miles is the same charge as 900 miles; in other words, 600 and 900 miles is counted as 2 segments of 500 miles each.

Here is the table they gave you:

Package Weight Rate per 500 miles shipped

Charge

2 pounds or less

$1.50

More than 2 but not more than 6

$3.70

More than 6 but not more than 10

$5.25

Your code needs to validate the input completely, e.g., the weight and mile amounts must be positive. If an input is invalid, e.g., the weight is zero or less, you should display an appropriate, professional error message, e.g., Error: Weight must be greater than zero!, which should be offset and surrounded by white space, so it stands out, and repeat getting that input until valid input is received. Keep in mind, the user will find it annoying if they must enter both the miles and weight at the same time, and only one of them caused an error, or they must reenter already valid data. Also, make sure you follow the Code Conventions and good programming practices, e.g., appropriately initialize variables to zeros, avoid stacked if or if-else constructs unless necessary, don’t use break or continue to get out of a loop, goto, etc.; in other words, you should NOT use stacked if/if-else constructs, break, or continue for this assignment.

At this point for the code, you should only solve the problem using what you learned from modules 1 – 6, i.e., NO arrays, functions other than main(), etc. Only if all the input is valid, should the program calculate and display one shipping charge, and pause, but not quit, before proceeding to a new customer. Your test cases should test the various possibilities, and the limits of the program, which means, you will need to use an appropriate loop, which will ask if you would like to process the next customer or not by asking them to enter an appropriate value. Once there are no more customers to process, the program should display Good-bye! and end. Remember to solve each aspect of the program separately, and then, put the parts together.

Hints: You may need to reset any values after you display the answer and before you get the input for the next customer. Big Helpful Hint: For the number of segments calculation, you may want to start with integer division, e.g., 1200 miles / 500 miles per segment = 2 segments, and then, expand on that.

You should be able to solve this problem with only one loop.

Sample Run

Enter the number of miles as a whole number: 0

        Error: Miles must be greater than zero!

Enter the number of miles as a whole number: 1

Enter the weight of the package in pounds: 0

        Error: Weight must be greater than zero!

Enter the weight of the package in pounds: 1

The cost to ship your package is: $1.50.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 2

The cost to ship your package is: $1.50.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 2.5

The cost to ship your package is: $3.70.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 6

The cost to ship your package is: $3.70.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 500

Enter the weight of the package in pounds: 11

        Error: We don't ship packages over 10 pounds!

Enter the weight of the package in pounds: 10

The cost to ship your package is: $5.25.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 501

Enter the weight of the package in pounds: 3.75

The cost to ship your package is: $7.40.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 1000

Enter the weight of the package in pounds: 6.1

The cost to ship your package is: $10.50.

Enter 1 to continue or 0 to quit: 1

Enter the number of miles as a whole number: 12450

Enter the weight of the package in pounds: 1

The cost to ship your package is: $37.50.

Enter 1 to continue or 0 to quit: 0

Good-bye!

Press any key to continue . . .

Create an IPO Diagram Here

Input

Process

Output

Test Case 1

Input Data

Expected Results

Weight:                1.5 pounds

Miles:                    200 miles (This is one 500-mile segment.)

Your shipping charge is $1.50.

Test Case 2

Input Data

Expected Results

Weight:                5.6 pounds

Miles:                    1200 miles (This is three 500-mile segments.)

Your shipping charge is $11.10.

Create Test Cases 3 – 5 Here

Your test cases must be unique, i.e., do NOT use the examples in this document, except concerning those, which produce an error. Make sure they are good, e.g., test for errors, before and after ends of ranges, etc. Feel free to include more test cases to thoroughly test your program.

Paste the Code Here

Paste any related Execution Windows (Screenshots) for All Customers, i.e., All Test Cases, Here

Post new questions in the Q & A discussion, if you are stuck or there is something in this, about which you are confused.

Solutions

Expert Solution

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

// ShippingCalculator.java

import java.util.Scanner;

public class ShippingCalculator {

   public static void main(String[] args) {
       int miles=0,choice=0,segments=0;
       double weight=0.0,charges=0.0;
       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner sc = new Scanner(System.in);
  
       do {
          
           do {
           //Getting the input entered by the user
   System.out.print("Enter the number of miles as a whole number:");
   miles=sc.nextInt();
   if(miles<=0)
   {
       System.out.println(" Error: Miles must be greater than zero! ");
   }
           } while (miles<=0);

          
           segments=(miles%500)==0 ? (miles/500) : (miles/500)+1;
          
          
           do {
           //Getting the input entered by the user
   System.out.print("Enter the weight of the package in pounds:");
   weight=sc.nextDouble();
   if(weight<=0)
   {
       System.out.println(" Error: Weight must be greater than zero! ");
   }
  
   if(weight>10)
   {
       System.out.println(" Error: We don't ship packages over 10 pounds! ");
   }
           } while (weight<=0 || weight>10);
          
           int res=(int)Math.ceil(weight);
          
          
          
           switch(res)
           {
           case 1:
           case 2:{  
               charges=segments*1.5;
               break;
           }
           case 3:
              
           case 4:
           case 5:
           case 6:
           {  
               charges=segments*3.70;
               break;
           }
           case 7:
           case 8:
           case 9:
           case 10:
           {  
               charges=segments*5.25;
               break;
           }
          
          
           }
          
           System.out.println("The cost to ship your package is: $"+charges);
          
           System.out.print("Enter 1 to continue or 0 to quit:");
           choice=sc.nextInt();
       } while (choice==1);
      
   }

}
_________________________

Output:

Enter the number of miles as a whole number:12450
Enter the weight of the package in pounds:1
The cost to ship your package is: $37.5
Enter 1 to continue or 0 to quit:0


_______________Could you plz rate me well.Thank You


Related Solutions

I need the JAVA code for a 4 function calculator app on andriod studio - The...
I need the JAVA code for a 4 function calculator app on andriod studio - The requirements are the following : - The only buttons needed are 0-9, *, /, +, -, a clear, and enter button - Implement the onclicklistener on the main activity - The calcuator should use order of operations (PEMDAS) - It should be able to continue from a previous answer (Ex: If you type 2+6 the calculator will display 8. If you then multiple by...
Lab 02 Final Grade Calculator **** I need it in JAVA **** **** write comments with...
Lab 02 Final Grade Calculator **** I need it in JAVA **** **** write comments with the code **** Objective: Write a program that calculates a final grade! The program should read in a file and then calculates the final grade based on those scores. Files read into this system are expected to follow this format: <Section0>\n <Grade0 for Section0>\n <Grade1 for Section0>\n … <GradeX for Section0>\n <Section1>\n <Grade0 for Section1>\n … <GradeY for Section1> <Section2> … <SectionZ> Sections denote...
0. Introduction. In this assignment you will implement a stack as a Java class, using a...
0. Introduction. In this assignment you will implement a stack as a Java class, using a linked list of nodes. Unlike the stack discussed in the lectures, however, your stack will be designed to efficiently handle repeated pushes of the same element. This shows that there are often many different ways to design the same data structure, and that a data structure should be designed for an anticipated pattern of use. 1. Theory. The most obvious way to represent a...
I need a full java code. And I need it in GUI With the mathematics you...
I need a full java code. And I need it in GUI With the mathematics you have studied so far in your education you have worked with polynomials. Polynomials are used to describe curves of various types; people use them in the real world to graph curves. For example, roller coaster designers may use polynomials to describe the curves in their rides. Polynomials appear in many areas of mathematics and science. Write a program which finds an approximate solution to...
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu...
JAVA PROGRAMMING Hi! I need to create a calculator using do/while loop that calls a menu switch where the user choice the calculation type. In the switch each case calls a method to each type of calculation (addition/subtraction/division/multiply/ change set of numbers in the array) those methods sends back the result to be displayed in another method. This application needs to hold the user input's numbers as an array. Thanks for your time. It is a great help!
JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to...
JAVA CODE BEGINNERS, I already have the DEMO CLASS(NEED YOU TO USE), I need you to use all methods, also switch statements. Write a Temperature class. The class will have three conversion methods: toCelsius(), toKelvin() and toFahrenheit(). These methods will return a Temperature in those three scales equal to the this temperature. Note that the value of this is not changed in these conversions. In addition to these three conversion methods the class will have methods add(Temperature), subtract(Temperature), multiply(Temperature), and...
I REALLY JUST NEED TO KNOW THE TOTAL SHIPPING COST AND THE SHIPPING PATTERN! House Beer...
I REALLY JUST NEED TO KNOW THE TOTAL SHIPPING COST AND THE SHIPPING PATTERN! House Beer has three breweries in Portland, New York and Scranton. The cases of beer are sent to warehouses in Boston and Atlantic City and then shipped to the distribution centers in Pittsburgh, Cincinnati, and Atlanta. The shipping cost per case from each brewery to each warehouse and the supply and demand are given below. (15 points) Warehouse Brewery Boston Atlantic City Portland 0.38 1.16 New...
This is a statistics calculator and simulator (Links to an external site.). For this assignment, I...
This is a statistics calculator and simulator (Links to an external site.). For this assignment, I would like you to start with a real life scenario in which you might need to know some statistical measures. Provide a real life scenario (you must have 10 numbers with a frequency of 1 and calculate the statistics) Take a screenshot of the completed stats. Now, change your frequencies to anything you want and see how the data changes. Take a screen shot...
I have to write a c program for shipping calculator. anything that ships over 1000 miles,...
I have to write a c program for shipping calculator. anything that ships over 1000 miles, there is an extra 10.00 charge. I have tried everything. no matter what I put, it will not add the 10.00. please help here is my code #include <stdio.h> #include <stdlib.h> int main() { double weight, miles, rate, total; printf("Enter the weight of the package:"); scanf("%lf", &weight); if (weight > 50.0) { puts("we only ship packages of 50 pounds or less."); return 0; }...
***You can use a calculator but I just need the work written out so I can...
***You can use a calculator but I just need the work written out so I can see what you did and how you did it*** I need the answer for number 4 which is based on number 3. Please answer number 4 based on number 3. Number 4 can be found at the bottom. Thank you! 3. A business takes out a loan for $250,000 at 4.8% interest compounded monthly. If the business can afford to make monthly payments of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT