You want to buy a new car, and you are thinking about two alternatives, car A and car B. You like both cars, and you are considering keeping whichever one you buy for many years to come. As a result, you want to evaluate the total cost of ownership of both cars over many years. Car A costs $20,000, whereas car B costs $30,000. Car A runs 25 miles with a gallon of gas, whereas car B runs 32 miles with a gallon of gas. You estimate that you will drive about 15,000 miles each year, and that gas price is going to be around $2.50 per gallon for the foreseeable future. The maintenance cost of car A is $1,300 in the first year, then that cost increases 15% (with compound growth) each year. The maintenance cost of car B is $1,000 in the first year, then that cost increases 10% (with compound growth) each year. Task 1. Write a method named compareCars(int years) that takes an integer number of years and prints a table with the total ownership cost of each car for each year, starting from year 0 which represents the time of purchase. The method will return the name of the most economical car on the last year. Note: For this problem, you are allowed to break the usual "no print statements inside a method" recommendation. Task 2. Using your method, answer this question: which car would you buy if you plan on keeping it for 5 years? 10 years? Discuss the results. Write your answer in a comment at the top of your code. Task 3. Answer this question: in a method, what is the difference between printing something and returning it? Write your answer in a comment at the top of your code.

Respuesta :

Answer:

Task 1: T = c + (2.5n(A/M))+ m(1+r/100)ⁿ

Task 2: In both 5 & 10 years, Car A is more economical

Task 3: Printing returns the answer in a different dialogue box while return displays the answer in the same window.

Explanation:

Task 1:

C = Cost of car

n = Number of years

m = Maintenance Cost

r = Rate

M = Mileage per gallon

A = Annual mileage

T= Total Cost

T = c + (2.5n(A/M))+ m(1+r/100)ⁿ

Task 2

Car A In 5 years; T = 20000+ (2.5*5(15000/25))+1300(1+0.15)⁵= $30115

Car B In 5 years; T = 30000+ (2.5*5(15000/32))+1000(1+0.10)⁵= $37470

Therefore in 5 years, Car A is more economical.

Car A In 10 years; T = 20000+ (2.5*10(15000/25))+1300(1+0.15)¹⁰= $40259.225

Car B In 10 years; T = 30000+ (2.5*10(15000/32))+1000(1+0.10)¹⁰= $ 44312.49

Therefore in 10 years, Car A is still economical.

Task 3: Printing returns the answer in a different dialogue box while return displays the answer in the same window.