subject

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.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 21:00
Which of these is most responsible for differences between the twentieth century to the twenty-first century?
Answers: 2
question
Computers and Technology, 23.06.2019 00:00
Donna and her team of five have invented a new gadget for the science exhibition in their college. which intellectual property right will protect their invention?
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
Anul 2017 tocmai s-a încheiat, suntem trişti deoarece era număr prim, însă avem şi o veste bună, anul 2018 este produs de două numere prime, 2 şi 1009. dorel, un adevărat colecţionar de numere prime, şi-a pus întrebarea: “câte numere dintr-un interval [a,b] se pot scrie ca produs de două numere prime? “.
Answers: 1
question
Computers and Technology, 24.06.2019 04:10
Write a program that reads a set of floating-point values. ask the user to enter the values, then print • the average of the values. • the smallest of the values. • the largest of the values. • the range, that is the difference between the smallest and largest. of course, you may only prompt for the values once.
Answers: 3
You know the right answer?
You want to buy a new car, and you are thinking about two alternatives, car A and car B. You like bo...
Questions