Created
February 7, 2012 02:47
-
-
Save stevepm/1756809 to your computer and use it in GitHub Desktop.
java hw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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