In: Computer Science
JAVA please
Program 4: Is there a Prius version? Did you know that the average Boeing 747 airplane uses approximately 1 gallon of fuel per second? Given the speed of the airplane, that means it gets 5 gallons to the mile. No, not 5 miles to the gallon, 5 gallons to the mile. You may be questioning why such a horribly inefficient machine is allowed to exist, but you’ll be happy to find out that, because this airplane hold 568 people, it averages about 0.01 gallons per person – (100 miles per gallon per person). Your job is to design (pseudocode) and implement (source code) a program that asks the user for a distance the plane has to fly (i.e. the length of the trip) and also asks the cost of jet fuel (which is currently $1.80 per gallon). The program should then calculate the total fuel charges to make the trip. Next, ask the user how many people will fly, as well as the average cost of a ticket. Finally, print the total profit made (or lost) and the average gas mileage per person. Document your code and properly label the input prompts and the outputs as shown below.
Thanks for the question. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks =========================================================================== import java.util.Scanner; public class ProblemFour { private static final double GALLON_PER_SECOND=5.0; public static void main(String[] args) { // scanner object to accept user input Scanner scanner = new Scanner(System.in); double flightDistance; double fuelCost; int passengersInFlight=0; double averageTicketCost =0; // take user inputs System.out.print("Enter the flight distance: "); flightDistance=scanner.nextDouble(); System.out.print("Enter the current cost of jet fuel: $"); fuelCost = scanner.nextDouble(); double flightCost = flightDistance*fuelCost*GALLON_PER_SECOND; System.out.println("The flight will cost $"+String.format("%.1f",flightCost)+" in fuel"); System.out.print("Enter the number of passengers: "); passengersInFlight = scanner.nextInt(); System.out.print("Enter the average cost of a ticket: "); averageTicketCost = scanner.nextDouble(); // calculate profit Selling Price - Cost Price double profit = passengersInFlight*averageTicketCost-flightCost; System.out.println("You will make a profit of $"+String.format("%.1f",profit)); // calculate average miles per person double averageMilesPerPerson = passengersInFlight/GALLON_PER_SECOND; System.out.println("You averaged "+String.format("%.1f",averageMilesPerPerson) + " miles per person per gallon!"); } }
=============================================================================
thank you & please do up vote for me
regards,
friend : )