Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. /**
  2. * Name of Program File:InsuranceQuote_M_P.java
  3. * Author: Mike Peacock
  4. * Date: 2012-10-13
  5. *Program: CTN
  6. * Course: INFO1150
  7. * Description: A program to calculate an insurance quote, depending on many variables. Base
  8. * rate of $10,000 will be adjusted by the answers to the questions. Or a quote
  9. * will not be issued if the user is too risky.
  10. **/
  11.  
  12. import java.util.Scanner; //Scanner class for user input
  13. public class InsuranceQuote_M_P
  14. {
  15.  
  16. public static void main(String[] args)
  17. {
  18. // TODO Auto-generated method stub
  19. //display the title or description
  20. System.out.println(" Mikes Insurance Quote Generator ");
  21. System.out.println(" ############################# \n");
  22. //create a scanner object for obtaining user input
  23. Scanner input = new Scanner(System.in);
  24.  
  25. //start with a base rate of $4000.00
  26. double baseRate=4000.00;
  27.  
  28. //collect all the required inputs for quote
  29. System.out.println("Please answer a few questions to get your personalized quote!\n");
  30.  
  31. //get name
  32. System.out.println("Please enter your name: ");
  33. String userName=input.nextLine();
  34.  
  35. //get gender m or f
  36. System.out.println("Please enter 'm' if you are male or 'f' if you are female :");
  37. String userSex=input.nextLine();
  38.  
  39. //get age
  40. System.out.println("Please enter your age :");
  41. int userAge=input.nextInt();
  42.  
  43. //get years experience driving
  44. System.out.println("Please enter how many years you have been driving :");
  45. int userYearsExp=input.nextInt();
  46.  
  47. //get fault accidents
  48. System.out.println("Please enter the amount of At Fault accidents you've had :");
  49. int userFaultAcc= input.nextInt();
  50.  
  51. //get speeding tickets
  52. System.out.println("Please enter the amount of speeding tickets you have had :");
  53. int userSpeeder=input.nextInt();
  54.  
  55. //get demerit points
  56. System.out.println("Please enter the amount of demerit points you have :");
  57. int userDemerit=input.nextInt();
  58.  
  59. //flush
  60. input.nextLine();
  61. //get vehicle type
  62. System.out.println("Please enter your vehicle type (family, truck, or sports) :");
  63. String userVehicle = input.nextLine();
  64. //char userVehicleChar = userVehicle.charAt(0);
  65.  
  66. //end of collecting info
  67.  
  68. //calculate the quote for the user
  69. //first, check age, demerit, speeding tickets, at fault crashes to determine if user is eligible
  70. if (userAge < 16 || userDemerit > 9 || userFaultAcc > 6)
  71. {
  72. //tell user we will not insure them
  73. System.out.println("Mike's Insurance is not willing to insure you!\n");
  74. }
  75.  
  76. //start quote calculations
  77. //give females a 5% discount,convert string userSex to char
  78. char userSexChar = userSex.charAt(0);
  79. if (userSexChar == 'f' || userSexChar == 'F')
  80. {
  81. baseRate=baseRate*0.95;
  82. userSex = "Female";
  83. }
  84. else
  85. {
  86. userSex= "Male";
  87. }
  88.  
  89.  
  90. //give a 25% discount if user is >=25 or a $0.00 quote if driver is < 16
  91. if (userAge >=25)
  92. {
  93. baseRate=baseRate*0.75;
  94. }
  95. if (userAge < 16)
  96. {
  97. baseRate=0.00;
  98. }
  99.  
  100. //gave a 25% discount if user has 5+ years exp, or 5% per year if less than 5 years
  101.  
  102.  
  103. if (userYearsExp >=5)
  104. {
  105. baseRate = baseRate*0.75;
  106. }
  107. else
  108. {
  109. baseRate = baseRate * (1.00 -(userYearsExp * 0.05) );
  110. }
  111.  
  112.  
  113.  
  114. //give a 20% increase for each at fault accident,or set to 0 if more than 6 at faults
  115. if (userFaultAcc >6)
  116. {
  117. baseRate = 0;
  118. }
  119.  
  120. else if (userFaultAcc > 0)
  121. {
  122. baseRate = baseRate * (1+(userFaultAcc * 0.20));
  123. }
  124.  
  125.  
  126.  
  127. //apply a 10% increase for each speeding ticket
  128. if (userSpeeder > 0)
  129. {
  130. baseRate = baseRate *(1+(userSpeeder *0.10));
  131. }
  132.  
  133. //apply 5% for each demerit point, or if >9 set to zero
  134. if (userDemerit > 9)
  135. {
  136. baseRate = 0.0;
  137. }
  138. else if (userDemerit == 0)
  139. {
  140. //nothing happens, leave baserate alone
  141. }
  142. else
  143. {
  144. baseRate = baseRate * (1+(userDemerit * 0.05));
  145. }
  146.  
  147. char userVehicleChar = userVehicle.charAt(0);
  148.  
  149. //give a 15% increase for truck, or 25%increase for sports, or nothing if family
  150. if (userVehicleChar == 't' || userVehicleChar == 'T')
  151. {
  152.  
  153. baseRate = baseRate * 1.15;
  154. }
  155. else if (userVehicleChar == 's' || userVehicleChar =='s')
  156.  
  157. {
  158. baseRate = baseRate * 1.25;
  159. }
  160. else
  161. {
  162. //nothing happens, leave baserate alone
  163. }
  164.  
  165.  
  166. //if rate has risen over $10,000, do not insure
  167. if (baseRate >= 10000)
  168. {
  169. baseRate = 0.00;
  170. }
  171. //end quote calculations
  172.  
  173. //Truncate baseRate to $xxx.xx format
  174. int tempRate;
  175. baseRate *= 100.0;
  176. tempRate = (int) baseRate;
  177.  
  178. double quoteRate= (double)tempRate/100;
  179.  
  180.  
  181.  
  182.  
  183. //Start outputs
  184.  
  185. //if baserate is 0, then we have disallowed user
  186. if (userAge < 16)
  187. {
  188. System.out.println("You are too young to drive in Canada!");
  189. }
  190. if (quoteRate == 0.00)
  191. {
  192. System.out.println("Unfortunately, you are too high risk for us to insure at this time " + userName +".");
  193. }
  194. //display inputs and give quote
  195. else
  196. {
  197.  
  198. System.out.println(" This is our quote for " +userName);
  199. System.out.println(" **************************************************\n");
  200.  
  201. System.out.println(" Driving history of "+ userName + ".");
  202. System.out.println(" Your Gender is : " +userSex);
  203. System.out.println(" Your Age is : " +userAge);
  204. System.out.println(" Driving history : " +userYearsExp+ " years");
  205. System.out.println(" Number of at-fault accidents : "+userFaultAcc);
  206. System.out.println(" Number of Speeding tickets : "+ userSpeeder);
  207. System.out.println(" Number of Demerit points : "+ userDemerit);
  208. System.out.println(" Your vehicle type is : " + userVehicle +"\n");
  209. //calculate monthly payments, and truncate to xxx.xx format
  210. double monthRate = quoteRate/12;
  211.  
  212. monthRate *= 100.0;
  213. int tempMonthRate = (int) monthRate;
  214. double monthQuoteRate= (double)tempMonthRate/100;
  215.  
  216.  
  217.  
  218.  
  219.  
  220. System.out.println(" The total of your quote is $" +quoteRate+" per year!");
  221. System.out.println(" Your monthly payments would be $" + monthQuoteRate + " per month!");
  222.  
  223.  
  224.  
  225. }
  226. //close the scanner object
  227.  
  228. input.close();
  229. }
  230.  
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement