In: Computer Science
Specifications:
Write a Java program called LifeRaft.java that will do all of the following:
Example 1:
Example 2:
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"