Guest User

Untitled

a guest
Jun 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. /**
  2. * Name of Program File:K_R_Lifeboats.java
  3. * Author:Karlie Rogerson
  4. * Student #:
  5. * Program: CPA
  6. * Course: INFO1150
  7. * Date:Feb 15, 2012
  8. * Description:
  9. */
  10. import java.util.Scanner;
  11. public class K_R_Lifeboats
  12. {
  13.  
  14. public static void main(String[] args)
  15. {
  16. //Create a Scanner object
  17. Scanner input = new Scanner(System.in);
  18.  
  19. // Inform user what program they are using
  20. System.out.println("Lifeboat Capacity Analysis");
  21. System.out.println("--------------------------");
  22. // Inform user that they are about to enter some information
  23. System.out.println("\nFirst some information is needed...");
  24.  
  25. //ask user to enter the name of the ship
  26. System.out.print("\nEnter the name of the ship: ");
  27.  
  28. //create variable
  29. String shipName = input.nextLine();
  30.  
  31.  
  32. //ask the user to enter the number of people on board
  33. System.out.print("Enter the number of people on board the " +shipName+ ": " );
  34.  
  35.  
  36. //create variable
  37. double onBoard = input.nextDouble();
  38. //flush the buffer
  39. input.nextLine();
  40.  
  41. //ask the user to enter the maximum number of people per lifeboat
  42. System.out.print("Enter the maximum number of people per lifeboat: ");
  43.  
  44. //create variable
  45. double perBoat = input.nextDouble();
  46. //flush the buffer
  47. input.nextLine();
  48.  
  49. //ask the user the number of lifeboats that are available
  50. System.out.print("Enter the number of lifeboats that are avaliable on the " +shipName+ ": ");
  51.  
  52. //create variable
  53. double lifeBoats = input.nextDouble();
  54. //flush the buffer
  55. input.nextLine();
  56. //create variable
  57.  
  58.  
  59. System.out.println("\nHere are the results...");
  60.  
  61.  
  62. double amountRescued = (lifeBoats * perBoat);
  63. double requiredAmount = (onBoard / perBoat);
  64. double amountDrowned = (onBoard - amountRescued);
  65. double amountDrownedPercent = (double)amountDrowned / onBoard * 100;
  66. double amountRescuedPercent = (double)amountRescued / onBoard * 100;
  67. double avaliableSpace = (lifeBoats * perBoat - onBoard);
  68.  
  69. System.out.println("\nA minimum of " +requiredAmount+ " lifeboats are required to rescue everyone on board");
  70.  
  71. System.out.println( (amountRescued) + " people " + "(" + amountRescuedPercent + "%)" + " would be rescued.");
  72.  
  73. System.out.println (amountDrowned + " people " + "(" + amountDrownedPercent + "%)" + " would likey drown.");
  74.  
  75.  
  76. if(avaliableSpace >= 0)
  77. {
  78. System.out.println ("There would be room for an extra " +avaliableSpace+ " people in the lifeboats.");
  79. }
  80.  
  81. if(avaliableSpace <= 0)
  82. {
  83. System.out.println ("There would be no room for extra people in the lifeboats.");
  84. }
  85.  
  86.  
  87. }//end main
  88.  
  89. }//end class
Add Comment
Please, Sign In to add comment