Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Name of Program File:K_R_Lifeboats.java
- * Author:Karlie Rogerson
- * Student #:
- * Program: CPA
- * Course: INFO1150
- * Date:Feb 15, 2012
- * Description:
- */
- import java.util.Scanner;
- public class K_R_Lifeboats
- {
- public static void main(String[] args)
- {
- //Create a Scanner object
- Scanner input = new Scanner(System.in);
- // Inform user what program they are using
- System.out.println("Lifeboat Capacity Analysis");
- System.out.println("--------------------------");
- // Inform user that they are about to enter some information
- System.out.println("\nFirst some information is needed...");
- //ask user to enter the name of the ship
- System.out.print("\nEnter the name of the ship: ");
- //create variable
- String shipName = input.nextLine();
- //ask the user to enter the number of people on board
- System.out.print("Enter the number of people on board the " +shipName+ ": " );
- //create variable
- double onBoard = input.nextDouble();
- //flush the buffer
- input.nextLine();
- //ask the user to enter the maximum number of people per lifeboat
- System.out.print("Enter the maximum number of people per lifeboat: ");
- //create variable
- double perBoat = input.nextDouble();
- //flush the buffer
- input.nextLine();
- //ask the user the number of lifeboats that are available
- System.out.print("Enter the number of lifeboats that are avaliable on the " +shipName+ ": ");
- //create variable
- double lifeBoats = input.nextDouble();
- //flush the buffer
- input.nextLine();
- //create variable
- System.out.println("\nHere are the results...");
- double amountRescued = (lifeBoats * perBoat);
- double requiredAmount = (onBoard / perBoat);
- double amountDrowned = (onBoard - amountRescued);
- double amountDrownedPercent = (double)amountDrowned / onBoard * 100;
- double amountRescuedPercent = (double)amountRescued / onBoard * 100;
- double avaliableSpace = (lifeBoats * perBoat - onBoard);
- System.out.println("\nA minimum of " +requiredAmount+ " lifeboats are required to rescue everyone on board");
- System.out.println( (amountRescued) + " people " + "(" + amountRescuedPercent + "%)" + " would be rescued.");
- System.out.println (amountDrowned + " people " + "(" + amountDrownedPercent + "%)" + " would likey drown.");
- if(avaliableSpace >= 0)
- {
- System.out.println ("There would be room for an extra " +avaliableSpace+ " people in the lifeboats.");
- }
- if(avaliableSpace <= 0)
- {
- System.out.println ("There would be no room for extra people in the lifeboats.");
- }
- }//end main
- }//end class
Add Comment
Please, Sign In to add comment