Question

In: Computer Science

JAVA ONLY. Program 3: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source...

JAVA ONLY.

Program 3: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2] Document your code, properly label the input prompts, and organize the outputs as shown in the following sample runs. Note: for C++, #include and then call sqrt(). For Java, you’ll use Math.sqrt() and for C# it’s Math.Sqrt(). See the short appendix below for the general form. Sample run 1: Entered X1: 1.5 Entered Y1: -3.4 Entered X2: 4 Entered Y2: 5 Distance: 8.764131445842194 Sample run 2: Entered X1: -5.5 Entered Y1: -8.8 Entered X2: 25 Entered Y2: 4.5 Distance: 33.27371334852784 Sample run 3: Entered X1: 2 Entered Y1: 2 Entered X2: 10 Entered Y2: 10 Distance: 11.313708498984761

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

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 ProblemThree {


    public static void main(String[] args) {

        // scanner object to accept user input
        Scanner scanner = new Scanner(System.in);

        // create four variables
        double x1, y1, x2, y2;

        // get x1 and y1 from user
        System.out.print("Enter X1: ");
        x1 = scanner.nextDouble();
        System.out.print("Enter Y1: ");
        y1 = scanner.nextDouble();

        // get x2 and y2 from user
        System.out.print("Enter X2: ");
        x2 = scanner.nextDouble();
        System.out.print("Enter Y2: ");
        y2 = scanner.nextDouble();

        //calculate distance using Math.sqrt() method
        double distance = Math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));

        //display distance
        System.out.println("Distance: "+distance);
    }
}

===========================================================================

===========================================================================

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!");
    }
}

===========================================================================

thanks a lot !

let me know for any questions or doubts & please do give a up vote : )


Related Solutions

Java Please Source Only Program 3: Distance calc. This question is fairly straightforward. Design (pseudocode) and...
Java Please Source Only Program 3: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2] Document your code, properly label the input prompts, and organize the outputs as shown in the following sample runs.
IN C++ LANGUAGE PLEASE::: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source...
IN C++ LANGUAGE PLEASE::: Distance calc. This question is fairly straightforward. Design (pseudocode) and implement (source code) a program to compute the distance between 2 points. The program prompts the user to enter 2 points (X1, Y1) and (X2, Y2). The distance between 2 points formula is: Square_Root [(X2 – X1)^2 + (Y2 – Y1)^2]
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the loop). The program should ignore any negative input and should continue to read user inputs until 0 is entered. The program should display the largest value and...
Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values...
Design (pseudocode) and implement (source code) a program (name it DistinctValues) to display only district values in an array. The program main method defines a single-dimensional array of size 10 elements and prompts the user to enter 10 integers to initialize the array. The main method then calls method getValues() that takes an integer array and returns another single-dimensional array containing only distinct values in the original (passed) array. Document your code and properly label the input prompts and the...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project...
Write a program in Java Design and implement simple matrix manipulation techniques program in java. Project Details: Your program should use 2D arrays to implement simple matrix operations. Your program should do the following: • Read the number of rows and columns of a matrix M1 from the user. Use an input validation loop to make sure the values are greater than 0. • Read the elements of M1 in row major order • Print M1 to the console; make...
Design and implement a Java program that creates a GUI that will allow a customer to...
Design and implement a Java program that creates a GUI that will allow a customer to order pizza and other items from a Pizza Paarlor. The customer should be able to order a variety of items which are listed below. The GUI should allow the customer (viaJavaFX UI Controls - text areas, buttons, checkbox, radio button, etc.) to input the following information: Name of the customer First Name Last Name Phone number of the customer Type of food being order...
Design a simple program, using pseudocode, to implement the recursive formula you found in part (a)...
Design a simple program, using pseudocode, to implement the recursive formula you found in part (a) to compute numbers in the Fibonacci sequence. Describe in detail how your program implements the recursive formula. You may find it useful to discuss how it through a concrete example such as F(8) = 21.
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads in the principle 2) reads in additional money deposited each year (treat this as a constant) 3) reads in years to grow, and 4) reads in interest rate And then finally prints out how much money they would have each year. See below for formatting. Enter the principle: XX Enter the annual addition: XX Enter the number of years to grow: XX Enter the...
Write a C-program to implement the Reader/Writer model for the attached pseudocode modified to produce only...
Write a C-program to implement the Reader/Writer model for the attached pseudocode modified to produce only one million output instead of an infinite amount. Use pthreads and Linux semaphores. Include ten readers with one writer. The writer should produce one million outputs. Verify that the readers receive an equal share of the information produced. Meaning each reader receives about 100,000 of information. Explain your results regardless of the balance. No use mutex or monitor functions. ****PSEUDOCODE**** /* program readersandwriters */...
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that...
DESIGN A FLOWCHART IN FLOWGORITHM AND WRITE THE PSEUDOCODE Number Analysis Program Design a program that asks the user to enter a series of 20 numbers. The program should store the numbers in an array and then display the following data: The lowest number in the array. The highest number in the array. The total of the numbers in the array. The average of the numbers in the array. PLEASE AND THANK YOU
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT