Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Car_Insurance {
- @SuppressWarnings("resource")
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- char option, female = 'f', male = 'm';
- int age, driving, due = 0;
- double discount;
- Scanner input = new Scanner(System.in);
- System.out.print("Please enter your age: ");
- age = input.nextInt();
- System.out.print("Please enter your gender: ");
- option = input.next().charAt(0);
- System.out.print("Please enter accident free years: ");
- driving = input.nextInt();
- if (age<20 || age>75) {
- // no insurance available for age group
- System.out.println("Sorry no because of age");
- return;
- } // end if
- if (option == female) {
- if (age<25) {
- due = 1500;
- } else {
- due = 800;
- } // end if age
- } else if (option == male) {
- if (age < 25) {
- due = 1700;
- } else {
- due = 1000;
- } // end if age
- } else {
- System.out.println("Incorrect gender was input - must be m or f");
- return;
- } // end if option
- if (driving>5) driving = 5; // five years maximum discount
- discount = due * 0.10 * driving;
- System.out.println("Amount due: "+ (due-discount));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement