Question

In: Computer Science

IN JAVA PLEASE Program 4: Is there a Prius version? Did you know that the average...

IN 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.

Sample run 1: Enter the flight distance: 1000 Enter the current cost of jet fuel: $2 The flight will cost $10000.0 in fuel. Enter the number of passengers: 5 Enter the average cost of a ticket: 1000 You will make a profit of $-5000.0 You averaged 1.0 miles per person per gallon!

Sample run 2: Enter the flight distance: 500 Enter the current cost of jet fuel: $3 The flight will cost $7500.0 in fuel. Enter the number of passengers: 500 Enter the average cost of a ticket: 300 You will make a profit of $142500.0 You averaged 100.0 miles per person per gallon!

Sample run 3: Enter the flight distance: 4200 Enter the current cost of jet fuel: $1.80 The flight will cost $37800.0 in fuel. Enter the number of passengers: 550 Enter the average cost of a ticket: 600 You will make a profit of $292200.0 You averaged 110.0 miles per person per gallon!

Solutions

Expert Solution

// do comment if any problem arises

//code

import java.util.Scanner;

public class Airplane {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

System.out.print("Enter the flight distance: ");

// read distance to travel

int distance = sc.nextInt();

System.out.print("Enter the current cost of jet fuel: $");

// read cost of fuel per gallon

float fuel_cost = sc.nextFloat();

// calculate total cost to operate flight

float flight_cost = (float) distance * fuel_cost * 5;

System.out.println("The flight will cost $" + flight_cost + " in fuel.");

System.out.print("Enter the number of passengers: ");

// read number of passengers that are boarding in flight

int passengers = sc.nextInt();

System.out.print("Enter the average cost of a ticket: ");

// read cost of each ticket

float ticket_cost = sc.nextFloat();

// calculate total cost produced by tickets

float Ticket_total = ticket_cost * (float) passengers;

// calculate profit of flight

float profit = Ticket_total - flight_cost;

System.out.println("You will make a profit of $" + profit);

// calculate miles per person per gallon

float miles_per_person = (float) passengers / 5;

System.out.println("You averaged " + miles_per_person + " miles per person per gallon!");

}

}

Output of 3 sample runs:


Related Solutions

PLEASE DO THIS IN C#.Is there a Prius version? Did you know that the average Boeing...
PLEASE DO THIS IN C#.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...
IN C++ LANGUAGE PLEASE:::: Is there a Prius version? Did you know that the average Boeing...
IN C++ LANGUAGE PLEASE:::: 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...
Please do in java Program 3: Give a baby $5,000! Did you know that, over the...
Please do in java Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by the time that baby is ready for retirement...
you will create a program with Java to implement a simplified version of RSA cryptosystems. To...
you will create a program with Java to implement a simplified version of RSA cryptosystems. To complete this project, you may follow the steps listed below (demonstrated in Java code) to guide yourself through the difficulties. Step I Key-gen: distinguish a prime number (20 pts) The generation of RSA's public/private keys depends on finding two large prime numbers, thus our program should be able to tell if a given number is a prime number or not. For simplicity, we define...
rite a Java Program to play your version of the Texas Pick 3 Lottery. You will...
rite a Java Program to play your version of the Texas Pick 3 Lottery. You will need to include the provided code given below in your program. Task:The program will prompt for a number between 0 and 999. Your program will display the number of attempts it took for the entered number to match a randomly generated number. In the main() method, declare an int named myPick3choice. Create a prompt for myPick3choice as "Enter your Pick 3 choice:0-999". Create a...
FOR #4 A & B I don't know if I did it correctly.....Please check & the...
FOR #4 A & B I don't know if I did it correctly.....Please check & the other questions I'm having a heard time on. Thanks! A. You have been given a tube of E. coli. You are asked to make 1 mL total volume of 10-1 dilution of the bacterial culture. Explain how you would do this. Show all necessary calculations. ____ ml cells   +    _____ ml water    = 1 ml    (total volume) V1 D1 X V2 D2 1 mL...
Calculate Interest in a Java program. If you know the balance and the annual percentage interest...
Calculate Interest in a Java program. If you know the balance and the annual percentage interest rate, you can compute the interest on the next monthly payment using the following formula: interest = balance * (annualInterestRate/1200) Write a program that reads the balance and the annual percentage interest rate and displays the interest for the next month. Create a scanner Prompt the user to enter a name and create variable for scanner Prompt the user to enter a balance and...
The following is a C program that is a video game version of Connect 4. The...
The following is a C program that is a video game version of Connect 4. The code works fine as is now but I want to change the way you input which column you drop a disk into. Currently, you type in 1 and it goes into column 1. If you type in 6, it goes into column 6 and so on. But I want to make it so you input A or a, then it goes into column 1...
4 Implement a Java program that meets the following requirements • You can use the Java...
4 Implement a Java program that meets the following requirements • You can use the Java standard sequence data structure API types for sets, lists, stack,queue and priority queue as needed. All are available in the java.util package, which you will want to import in your program. 1. Argue in code comments which data structure, stack or queue, you will use to implement this method. Implement a method which creates some String objects as food orders for a small restaurant,...
Write a modified version of the program below. In this version, you will dynamically allocate memory...
Write a modified version of the program below. In this version, you will dynamically allocate memory for the new C-string and old C-string, using the new keyword. Your program should ask the user for the size of the C-string to be entered, and ask the user for the C-string, then use new to create the two pointers (C-strings).   Then, call Reverse, as before. Don’t forget to use delete at the end of your program to free the memory! #include <iostream>...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT