Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
java hw
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.