Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Name of Program File:InsuranceQuote_M_P.java
- * Author: Mike Peacock
- * Date: 2012-10-13
- *Program: CTN
- * Course: INFO1150
- * Description: A program to calculate an insurance quote, depending on many variables. Base
- * rate of $10,000 will be adjusted by the answers to the questions. Or a quote
- * will not be issued if the user is too risky.
- **/
- import java.util.Scanner; //Scanner class for user input
- public class InsuranceQuote_M_P
- {
- public static void main(String[] args)
- {
- // TODO Auto-generated method stub
- //display the title or description
- System.out.println(" Mikes Insurance Quote Generator ");
- System.out.println(" ############################# \n");
- //create a scanner object for obtaining user input
- Scanner input = new Scanner(System.in);
- //start with a base rate of $4000.00
- double baseRate=4000.00;
- //collect all the required inputs for quote
- System.out.println("Please answer a few questions to get your personalized quote!\n");
- //get name
- System.out.println("Please enter your name: ");
- String userName=input.nextLine();
- //get gender m or f
- System.out.println("Please enter 'm' if you are male or 'f' if you are female :");
- String userSex=input.nextLine();
- //get age
- System.out.println("Please enter your age :");
- int userAge=input.nextInt();
- //get years experience driving
- System.out.println("Please enter how many years you have been driving :");
- int userYearsExp=input.nextInt();
- //get fault accidents
- System.out.println("Please enter the amount of At Fault accidents you've had :");
- int userFaultAcc= input.nextInt();
- //get speeding tickets
- System.out.println("Please enter the amount of speeding tickets you have had :");
- int userSpeeder=input.nextInt();
- //get demerit points
- System.out.println("Please enter the amount of demerit points you have :");
- int userDemerit=input.nextInt();
- //flush
- input.nextLine();
- //get vehicle type
- System.out.println("Please enter your vehicle type (family, truck, or sports) :");
- String userVehicle = input.nextLine();
- //char userVehicleChar = userVehicle.charAt(0);
- //end of collecting info
- //calculate the quote for the user
- //first, check age, demerit, speeding tickets, at fault crashes to determine if user is eligible
- if (userAge < 16 || userDemerit > 9 || userFaultAcc > 6)
- {
- //tell user we will not insure them
- System.out.println("Mike's Insurance is not willing to insure you!\n");
- }
- //start quote calculations
- //give females a 5% discount,convert string userSex to char
- char userSexChar = userSex.charAt(0);
- if (userSexChar == 'f' || userSexChar == 'F')
- {
- baseRate=baseRate*0.95;
- userSex = "Female";
- }
- else
- {
- userSex= "Male";
- }
- //give a 25% discount if user is >=25 or a $0.00 quote if driver is < 16
- if (userAge >=25)
- {
- baseRate=baseRate*0.75;
- }
- if (userAge < 16)
- {
- baseRate=0.00;
- }
- //gave a 25% discount if user has 5+ years exp, or 5% per year if less than 5 years
- if (userYearsExp >=5)
- {
- baseRate = baseRate*0.75;
- }
- else
- {
- baseRate = baseRate * (1.00 -(userYearsExp * 0.05) );
- }
- //give a 20% increase for each at fault accident,or set to 0 if more than 6 at faults
- if (userFaultAcc >6)
- {
- baseRate = 0;
- }
- else if (userFaultAcc > 0)
- {
- baseRate = baseRate * (1+(userFaultAcc * 0.20));
- }
- //apply a 10% increase for each speeding ticket
- if (userSpeeder > 0)
- {
- baseRate = baseRate *(1+(userSpeeder *0.10));
- }
- //apply 5% for each demerit point, or if >9 set to zero
- if (userDemerit > 9)
- {
- baseRate = 0.0;
- }
- else if (userDemerit == 0)
- {
- //nothing happens, leave baserate alone
- }
- else
- {
- baseRate = baseRate * (1+(userDemerit * 0.05));
- }
- char userVehicleChar = userVehicle.charAt(0);
- //give a 15% increase for truck, or 25%increase for sports, or nothing if family
- if (userVehicleChar == 't' || userVehicleChar == 'T')
- {
- baseRate = baseRate * 1.15;
- }
- else if (userVehicleChar == 's' || userVehicleChar =='s')
- {
- baseRate = baseRate * 1.25;
- }
- else
- {
- //nothing happens, leave baserate alone
- }
- //if rate has risen over $10,000, do not insure
- if (baseRate >= 10000)
- {
- baseRate = 0.00;
- }
- //end quote calculations
- //Truncate baseRate to $xxx.xx format
- int tempRate;
- baseRate *= 100.0;
- tempRate = (int) baseRate;
- double quoteRate= (double)tempRate/100;
- //Start outputs
- //if baserate is 0, then we have disallowed user
- if (userAge < 16)
- {
- System.out.println("You are too young to drive in Canada!");
- }
- if (quoteRate == 0.00)
- {
- System.out.println("Unfortunately, you are too high risk for us to insure at this time " + userName +".");
- }
- //display inputs and give quote
- else
- {
- System.out.println(" This is our quote for " +userName);
- System.out.println(" **************************************************\n");
- System.out.println(" Driving history of "+ userName + ".");
- System.out.println(" Your Gender is : " +userSex);
- System.out.println(" Your Age is : " +userAge);
- System.out.println(" Driving history : " +userYearsExp+ " years");
- System.out.println(" Number of at-fault accidents : "+userFaultAcc);
- System.out.println(" Number of Speeding tickets : "+ userSpeeder);
- System.out.println(" Number of Demerit points : "+ userDemerit);
- System.out.println(" Your vehicle type is : " + userVehicle +"\n");
- //calculate monthly payments, and truncate to xxx.xx format
- double monthRate = quoteRate/12;
- monthRate *= 100.0;
- int tempMonthRate = (int) monthRate;
- double monthQuoteRate= (double)tempMonthRate/100;
- System.out.println(" The total of your quote is $" +quoteRate+" per year!");
- System.out.println(" Your monthly payments would be $" + monthQuoteRate + " per month!");
- }
- //close the scanner object
- input.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement