public
Created

java hw

  • Download Gist
gistfile1.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
import java.util.Scanner;
 
 
public class Driver {
private int age, carValue, tickets;
Scanner in;
 
public Driver(){
this.in = new Scanner(System.in);
System.out.println("Enter Age: ");
age = in.nextInt();
Age(age);
System.out.println("Enter Car Value: ");
carValue = in.nextInt();
System.out.println("Enter the number of tickets you have: ");
tickets = in.nextInt();
Tickets(tickets);
Calculate(Age(age), Tickets(tickets), carValue);
}
public double Age(int age){
double agePremium;
if (age < 25){
agePremium = 1.15;
}
else if (age <= 29){
agePremium = 1.10;
}
else{
agePremium = 1.0;
}
return agePremium;
}
public double Tickets(int tickets){
double ticketPremium = 0;
switch (tickets){
case 1: tickets = 1;
ticketPremium = 1.10;
break;
case 2: tickets = 2;
ticketPremium = 1.25;
break;
case 3: tickets = 3;
ticketPremium = 1.50;
break;
case 4:
if (tickets >= 4){
ticketPremium = 0;
}
break;
case 5: tickets = 0;
ticketPremium = 1;
break;
}
return ticketPremium;
}
public void Calculate(double agePremium, double ticketPremium, int carValue){
double premium = 0;
if (ticketPremium == 0){
System.out.println("Coverage Denied.");
}
else{
premium = (carValue * .05)*agePremium*ticketPremium;
System.out.println(premium);
}
}
 
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.