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

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"...
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 ()
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 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...
Write a java program that read a line of input as a sentence and display: ...
Write a java program that read a line of input as a sentence and display:  Only the uppercase letters in the sentence.  The sentence, with all lowercase vowels (i.e. “a”, “e”, “i”, “o”, and “u”) replaced by a strike symbol “*”.
Java Program Use for loop 1.) Write a program to display the multiplication table of a...
Java Program Use for loop 1.) Write a program to display the multiplication table of a given integer. Multiplier and number of terms (multiplicand) must be user's input. Sample output: Enter the Multiplier: 5 Enter the number of terms: 3 5x0=0 5x1=5 5x2=10 5x3=15 2 Create a program that will allow the user to input an integer and display the sum of squares from 1 to n. Example, the sum of squares for 10 is as follows: (do not use...
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1....
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods you...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps:...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
Write one Java program and satisfy the following requirements: Write a method called cube that accepts...
Write one Java program and satisfy the following requirements: Write a method called cube that accepts one integer parameter and returns that value raised to the third power. Write a method called randomNumber that returns a random floating-point number in the range of [-20.0, 50.0). (hints: use Random class in the method) Write a method called findMax that accepts three floating-point number as parameters and returns the largest one.(hints: use conditional statement in the method) Overload findMax that accepts one...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT