Q:

quiz question on Scanner and calculations and if conditional statement

0

You work in the transportation company that transports goods in containers on trains.

Consider the following problem:

Each train is composed of 15 wagons, each wagon can transport 3 containers and each container can hold 20 tons of goods.

Write a program that reads from the user the total weight of the goods to transport and computes the following information:

1- How many containers do we need to transport the merchandise?

2- How many wagons are necessary?

3- How many trains do we need?

4- How many wagons will be needed in the last train?

5- What is the filling ratio (percentage of used capacity) of the last container.

6- The program should print the following:

a. If the total number of Wagons is smaller than 3, print a kind message "The Quantity is too small. Sorry we can’t transport it"

b. Else if the total number of Wagons is greater or equal to 3, print the computed results in a clean and organized manner. (Number of Wagons, trains, and the filling ratio of the last container).

You should use the “if” conditions in HW2 to determine the exact number of containers, wagons and trains instead of adding 1 all the time.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;

public class testtt {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		System.out.println("enter the total weight of goods you need to transport:");
		double totalWeight=in.nextDouble();
		double containers_count=Math.ceil(totalWeight/20);
		System.out.println("we need "+Math.round(containers_count)+" containers");
		
		double needed_wagons=Math.ceil(containers_count/3);
		System.out.println("we need "+Math.round(needed_wagons)+" wagons");
		if(needed_wagons<3)
		{
		System.out.println("The Quantity is too small. Sorry we can’t transport it");
		}
		else {
		double needed_trains=Math.ceil(needed_wagons/15);
		System.out.println("we need "+Math.round(needed_trains)+" trains");
		
		double x=needed_wagons/15;
		double y=needed_trains-x;
		int num_of_wagons_in_last_train=15-(int)Math.floor(15*y);
		System.out.println("we need "+num_of_wagons_in_last_train+" wagons in the last train");
		
	
		double d= (double)totalWeight/20;
		d=containers_count-d;
		int filling_ratio_of_last_container=100-(int)(d*100);
		System.out.println("filling ratio (percentage of used capacity) of the last container: "+filling_ratio_of_last_container+"%");
		}
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now