You are to write a program for small insurance company. The program is supposed
ID: 638753 • Letter: Y
Question
You are to write a program for small insurance company. The program is supposed to determine the cost of automobile insurance premium for each family member, based on their ages. The basic insurance price is $1,000 per year per person plus an additional amount based on age, per the table below.
Age
Rate
16 to 19
Additional 15% of basic price
20 to 25
Additional 5% of basic price
Over 25
Discount 10% of basic price
Any other age
No insurance
Your program must read name and age from the following file named data.txt.
Data.txt :
Lisa Smith 21
Jack Smith 56
John Baker 23
Marry Jones 32
Age
Rate
16 to 19
Additional 15% of basic price
20 to 25
Additional 5% of basic price
Over 25
Discount 10% of basic price
Any other age
No insurance
Explanation / Answer
import java.io.*;
import java.util.*;
class insurance{
public static double value(int age){
double price = 10000.0;
if (age >= 16 && age <= 19)
return (15*price)/100+price;
else if (age >= 20 && age <= 25)
return (5*price)/100+price;
else if (age > 25)
return (10*price)/100+price;
return price;
}
public static void main(String[] args) throws IOException{
FileReader sc=new FileReader("data.txt");
BufferedReader file=new BufferedReader(sc);
String s = file.readLine();
System.out.println("the cost of automobile insurance premium for each person is ge");
while (s != null){
String[] l = s.split(" ");
String age = "";
for (int i = 0; i < l.length-1; i++){
age += l[i] + " ";
}
System.out.println("the cost of automobile insurance premium for "+age +" is "+value(Integer.parseInt(l[l.length-1])));
s = filereader.readLine();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.