jeudi 21 septembre 2017

Java - Insurance program (issue with adding the final amount)

This is my first post here, so forgive me for any formatting errors.

So as you can see my program requests the gender, # of accidents and year of car to display a fictitious insurance quote.

Based on all that information I need to add the subtotal of the insurance cost to the end.

I have my code working up until the Total Cost comment (posted it all for reference). I am stuck there because the genders have different base amounts. I'm trying to figure out a way to only do one if statement if it matches the gender that was input by the user.

Any ideas?

import java.util.*;
public class Insurance {
  public static void main(String [] args) {
    Scanner scanner = new Scanner(System.in);

   int currentYear = 2017; //used for calculating the age of the users car
   int maleGender = 1000;
   int femaleGender = 500;

   //Letting user know they are inputting data for car insurance purposes
   System.out.println("Car insurance questionnaire. Please input correct information when prompted.");

   // gender information from user
   System.out.println("What is your gender? m/f");
   String gender = scanner.next();

   // accident quantity information from user
   System.out.println("How many accidents have you had?");
   int acc = scanner.nextInt();

   // car year information from user
   System.out.println("What year was your car manufactured?");
   int carAge = scanner.nextInt();

   //if statements which refer to the users data input
    if (gender.equals("m")) {
     System.out.println("You are a male.\nThe base cost is $1000."); 
     } else {
     System.out.println("You are a female.\nThe base cost is $500.");
     }


     if (acc == 0) {
     System.out.println("You have no accidents. Insurance increase is $0.");
     } else if (acc >= 1) {
     System.out.println("You have " + acc + " accidents. Insurance increase is $" + acc * 100 + ".");
     }


     if (carAge >= 2007) {
      System.out.println("Your car is " + (currentYear - carAge) + " years old.\nYour car is still in warranty, no savings added.");
      } else 
      System.out.println("Your car is out of warranty, final cost is halved.");

      //Total cost
     /*
      if (carAge <= 2007) {
      System.out.println("Your total price is $" + ((acc * 100 + femaleGender) / 2) + ".");
      } else 
      System.out.println("Your total price is $" + (acc * 100 + femaleGender) + ".");
        */


 }
}

Aucun commentaire:

Enregistrer un commentaire