Question

In: Computer Science

Specifications: Write a Java program called LifeRaft.java that will do all of the following: Display a...

Specifications:

Write a Java program called LifeRaft.java that will do all of the following:

  1. Display a title
  2. Ask the user to enter the following values:
    1. The type of plane(Boeing 747 or Airbus A300)
    2. The number of passengers on board the Plane
    3. The number of crew aboard the plane
    4. The maximum number of people that can be carried by one liferaft assuming all the liferafts on the plane are the same size
    5. The actual number of liferafts that are available on board the plane

  1. Calculate and display the following results:
    1. The minimum number of liferafts required to carry all the people
    2. The number of people that would be rescued if the available liferafts were filled (but not beyond the number of people on board the plane) as well as the percentage that this represents of all the people on board
    3. The number of people that would drown as well as the percentage that this represents of all the people on board
    4. If nobody drowns, then also display the number of additional people that could be carried by the liferafts if they were all filled to capacity regardless of whether this number is greater than the number of people on board.

Example 1:

  • If there are 240 passengers and 8 crew, and each liferaft can carry 40 people, then we need 7 liferafts. With 7 liferafts, up to 7 x 40 = 280 people can be carried. Note that 6 liferafts can only carry 240 people, which is not enough!
  • If there are 6 liferafts available then only 6 x 40 = 240 people will be rescued (100 x 240 / 248 = 96.77%). This means 248 – 240 = 8 people will drown (100 x 8 / 240 = 3.33%).

Example 2:

  • If there are 240 passengers and 8 crew, and each liferaft can carry 40 people, then we need 7 liferafts. With 7 liferafts up to 7 x 40 = 280 people can be rescued.
  • If there are 7 liferafts available then 7 x 40 = 280 people could be rescued, but there are only 248 people so only 248 will be saved (100%) and nobody drowns (0%).
  • With 7 liferafts the excess capacity would be 280 – 248 = 32 additional people.

Solutions

Expert Solution

LifeRaft.java:

import java.util.*;
public class LifeRaft
{
   public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       String planeType;
       do{
           System.out.print("Enter type of plane:");
           planeType=sc.nextLine();
           if(planeType.equals("Airbus A300") || planeType.equals("Boeing 747")){ break;}
       }while(true);
       System.out.print("No. of passengers:");
       int passengers=sc.nextInt();
       System.out.print("No. of crew:");
       int crew=sc.nextInt();
       System.out.print("Maximum no. of passengers taken by single liferaft:");
       int capacity=sc.nextInt();
       System.out.print("No. of liferaft:");
       int liferaft=sc.nextInt();
       int people=passengers+crew;
       int temp=liferaft;
       int requiredLiferaft;
       if(temp*capacity<people){
           requiredLiferaft=temp;
       }
       else{
           while(temp*capacity>people)
           {
           temp-=1;
           }
           requiredLiferaft=temp+1;
       }
       System.out.println("Minimum number of liferafts required:"+requiredLiferaft);
       int rescued=requiredLiferaft*capacity>people?people:requiredLiferaft*capacity; //People rescued
       int remaining=requiredLiferaft*capacity-rescued;
       int drown=people-rescued;
       System.out.println("No. of people that can be rescued:"+rescued);
       System.out.printf("percentage of people rescued: %.2f\n",(float)rescued/(float)people*100);
       System.out.println("No. of people that can be drown:"+drown);
       System.out.printf("percentage of people drown: %.2f\n",(float)drown/(float)people*100);
       if(requiredLiferaft != liferaft){
           System.out.println("No. of people that can be rescued with remaining liferaft:"+((liferaft-requiredLiferaft)*capacity+remaining));
}
       else{
           System.out.println("No. of people that can be rescued with remaining liferaft:0");
       }
   }
}

output:

It will not accept the type of plane if it is neither "Airbus A300" nor "Boeing 747"


Related Solutions

Program Specifications: You will be writing a Java program called ASCIIRabbit.java that will print the following...
Program Specifications: You will be writing a Java program called ASCIIRabbit.java that will print the following ASCII objects. There should be two blank lines between each shape and your output must match identically. Rabbit In A Hat -------------------- (^\ /^) \ V / (o o) ( (@) ) --------- | | | | | | _______ Rabbit Under A Hat -------------------- _______ | | | | | | --------- /\"/\ () * () ("")_("") Rabbit Wears A Hat ------------------ _______...
Write a program in Java and run it in BlueJ according to the following specifications: The...
Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade on each line) and determines their type (excellent or ok). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "all" - prints all student records (first name, last name, grade, type). "excellent" - prints students with grade > 89. "ok"...
Java Programing Write a program called reverseProg.   This program will do the following Asks the user...
Java Programing Write a program called reverseProg.   This program will do the following Asks the user to input a string, it reads the string and does the followings Prints the string in reverse order. Displays the characters that are in position 7th, 8th and 9th of this string Displays the length of the string Displays the string in all UPPER CASE Sample output example: Enter a string: Wilmington University String Entered is: Wilmington University Wilmington University spelled backward is: ytsirevinU...
Program Specifications The built-in Java Math methods make some calculations much easier. Write a program called...
Program Specifications The built-in Java Math methods make some calculations much easier. Write a program called "DoTheMath" that accepts as input three floating-point numbers x, y, and z (define them as double) and outputs several calculations: x to the power of y x to the power of (y to the power of z) The absolute value of x The square root of (x*y to the power of z). Sample Run: Enter the values for x, y, z: -3.7 -3 5...
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199 Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
write java program that prompt the user to enter two numbers .the program display all numbers...
write java program that prompt the user to enter two numbers .the program display all numbers between that are divisible by 7 and 8 ( the program should swap the numbers in case the secone number id lower than first one please enter two integer number : 900 199   Swapping the numbers 224 280 336 392 448 504 560 616 672 728 784 840 896 i need it eclipse
A. Write a program called OnesZerosA.java to do all of the following. Please note, for this...
A. Write a program called OnesZerosA.java to do all of the following. Please note, for this problem you are not allowed to use ArrayList. Read a file containing ones and zeros (such as the example below, also available at http://www2.hawaii.edu/~esb/2020fall.ics111/oneszeros.txt) into a two-dimensional int array. Your program must create the array with the same number of rows as the number of lines in the file, and the same number of columns as the number of ones and zeros in each...
Write a java program that will first display the following menu: Choose one of the following...
Write a java program that will first display the following menu: Choose one of the following 1- To add 2 double integers 2- To add 2 integer numbers 3- To add 3 double numbers 4- To add 3 integer numbers After reading user’s choice, use a switch case statement to call the corresponding method Void add 1 (double n1, double n2) Void add2() Double add3 (double n1, double n2, double n3) Double add4 ()
Write a complete program in java that will do the following:
Write a complete program in java that will do the following:Sports:             Baseball, Basketball, Football, Hockey, Volleyball, WaterpoloPlayers:           9, 5, 11, 6, 6, 7Store the data in appropriate arraysProvide an output of sports and player numbers. See below:Baseball          9 players.Basketball       5 players.Football           11 players.Hockey            6 players.Volleyball        6 players.Waterpolo       7 players.Use Scanner to provide the number of friends you have for a team sport.Provide an output of suggested sports for your group of friends. If your...
JAVA: Display all even numbers between 1 and 20 --Optional write a program that reads in...
JAVA: Display all even numbers between 1 and 20 --Optional write a program that reads in 20 numbers. A method with an int parameter should display whether the number is odd or even for the number passed
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT