In: Computer Science
Evaluate Grade for Shipping Company - Code in Java
There are many Shipping companies emerging in the market now.
'SaySo' online survey panel has come up with the strategy to choose
the best Shipping Company for your shipping needs. The survey panel
has taken into consideration two factors of the companies namely
the number of countries a shipping Company offers its services
(country coverage) and number of shipments done per month. The
survey panel has graded the companies based on the two factors as
given below:
Grade | Countries | Shipment per month |
A | Above 150 | Above 1500 |
B | Above 125 | Above 1200 |
C | Above 100 | Above 1000 |
D | Above 75 | Above700 |
E | <=75 and >=0 | <=700 and >=0 |
Invalid Input | < 0 | < 0 |
Write the program to find the grade under which a specific Company
falls, given the number of countries it offers services and the
number of shipments made.
Problem Specfication :
The file name should be Main.java.
Input Format :
The first input consists of an integer that corresponds to the
number of countries the company offer its services.
The second input consists of an integer that corresponds to the
number of shipments per month.
Output Format :
The output should display the Grade of company. Print 'Invalid
Input' otherwise.
Refer sample input and output for formatting specifications.
[All text in bold corresponds to input and rest corresponds
to output.]
Sample Input and Output 1:
Enter the total number of countries :
150
Enter the total number of shipment per month :
1550
The company grade is : B
Sample Input and Output 2:
Enter the total number of countries :
-12
Enter the total number of shipment per month :
450
Invalid Input
Don'ts:
1. Do not create packages for
classes. Strictly adhere to the program structure given in the
template code.
2. Do not use Internet Explorer,
highly recommended to use chrome browser to launch ebox
platform.
3. Do not create multiple classes
inside a single file. Create separate file for each class.
Please refer to the screenshot of the code to understand the indentation of the code and output
Code
// Import the Scanner class
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
// create a number of countries variable
int countries;
//create a number of shipment variable
int shipment;
// Create a Scanner object
Scanner myObj = new Scanner(System.in);
// print the number of countries
System.out.println("Enter the total number of
countries :");
// take input from user for the number of countries
and assign to countries variable
countries = myObj.nextInt();
// print the number of shipment to ask the user
System.out.println("Enter the total number of shipment
per month :");
// take input from user for the number of shipments
and assign to shipment variable
shipment = myObj.nextInt();
// checks if no. of countries entered are greater than
150 and shipment are greater than 1500
if (countries > 150 && shipment >
1500)
{
// prints grade A
System.out.println("The company grade is : A");
}
// checks if no. of countries entered are greater than
125 and shipment are greater than 1200
else if (countries > 125 && shipment >
1200)
{
// prints grade B
System.out.println("The company grade is : B");
}
// checks if no. of countries entered are greater than
100 and shipment are greater than 1000
else if (countries > 100 && shipment >
1000)
{
// prints grade C
System.out.println("The company grade is : C");
}
// checks if no. of countries entered are greater than
75 and shipment are greater than 700
else if (countries > 75 && shipment >
700)
{
// prints grade D
System.out.println("The company grade is : D");
}
// checks if no. of countries entered are greater than
or equal to 0 and less than or equal to 75
//checks if shipment are greater than or equal to 0
and less than or equal to 700
else if ((countries <= 75 && countries
>=0) && (shipment <= 700 && shipment
>=0))
{
// prints grade E
System.out.println("The company grade is : E");
}
// if none of the above conditions satisfies,it prints
Invalid Input
else
{
// prints Invalid Input
System.out.println("Invalid Input");
}
}
}
Output
Enter the total number of countries :
160
Enter the total number of shipment per month :
1509
The company grade is : A
Code Screenshot
Output Screenshot
output for invalid input