Advertisement
brilliant_moves

Car_Insurance.java

Sep 26th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.20 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Car_Insurance {
  4.  
  5.     @SuppressWarnings("resource")
  6.     public static void main(String[] args) {
  7.     // TODO Auto-generated method stub
  8.  
  9.         char option, female = 'f', male = 'm';
  10.         int age, driving, due = 0;
  11.         double discount;
  12.  
  13.         Scanner input = new Scanner(System.in);
  14.  
  15.         System.out.print("Please enter your age: ");
  16.         age = input.nextInt();
  17.         System.out.print("Please enter your gender: ");
  18.         option = input.next().charAt(0);
  19.         System.out.print("Please enter accident free years: ");
  20.         driving = input.nextInt();
  21.  
  22.         if (age<20 || age>75) {
  23.          // no insurance available for age group
  24.             System.out.println("Sorry no because of age");
  25.             return;
  26.         } // end if
  27.  
  28.         if (option == female) {
  29.             if (age<25) {
  30.                 due = 1500;
  31.             } else {
  32.                 due = 800;
  33.             } // end if age
  34.         } else if (option == male) {
  35.             if (age < 25) {
  36.                 due = 1700;
  37.             } else {
  38.                 due = 1000;
  39.             } // end if age
  40.         } else {
  41.             System.out.println("Incorrect gender was input - must be m or f");
  42.             return;
  43.         } // end if option
  44.  
  45.         if (driving>5) driving = 5; // five years maximum discount
  46.         discount = due * 0.10 * driving;
  47.         System.out.println("Amount due: "+ (due-discount));
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement