Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is how far we've come in class, So please write the code in java only. and Write it in a beginner-friendly way ( its

image text in transcribed

This is how far we've come in class, So please write the code in java only. and Write it in a beginner-friendly way ( its a beginner clas).

import java.util.Scanner;

public class Main {

public static void main(String[] args) { Scanner sc = new Scanner(System.in); String name, location; double distanceKm, distanceMi, mph, mpg, gasPrice, totalPrice, gallonsUsed, hours; final double MILES_IN_A_KM = 0.621371; // greet the user and prompt them for their name System.out.print("What is your name? "); name = sc.next(); System.out.println(" Hello " + name + ". Welcome to the trip calculator! "); // obtain the location, distance, mph, mpg, and cost of gas from the user System.out.print("Location: "); location = sc.next(); System.out.print("Distance (km): "); distanceKm = sc.nextDouble();

System.out.print("Vehicle Speed (mph): "); mph = sc.nextDouble();

System.out.print("Vehicle mpg: "); mpg = sc.nextDouble();

System.out.print("Cost of Gas per Gallon: "); gasPrice = sc.nextDouble(); System.out.println(" ---------------------------------------- "); System.out.println("Below are the results for your trip to " + location); // convert the distance in km to miles distanceMi = distanceKm * MILES_IN_A_KM; // calculate how many gallons of gas were used gallonsUsed = distanceMi / mpg; // calcaulte how many hours the trip will take hours = distanceMi / mph; // calculate the total price of the trip totalPrice = gasPrice * gallonsUsed; // output the gallons used, hours, and trip cost System.out.printf("%-15s %.1f gals ", "Gallons used: ", gallonsUsed); System.out.printf("%-15s %.1f hrs ", "Hours driven: ", hours); System.out.printf("%-15s $%.2f ", "Trip cost: ", totalPrice);

}

}

PURPOSE This assignment will test your ability to write a basic computer program in Java. By the end of this assignment, you should feel comfortable utilizing basic input/output, variables, arithmetic expressions, and other basic concepts we have gone over in class. PROBLEM Create a program that allows the user to select a specific quantity of items from a market. The market has 4 items: 1) Bread - $1.40/ loaf 2) Chicken - $2.75/lb 3) Chips - $3.30/ bag 4) Cookies - $2.60/ box Start by greeting the user and displaying the items of the market. Then, prompt the user to enter the quantity of each item. Then, calculate the total of each item purchased, the subtotal, the tax, and the final price. Assume there is a standard sales tax rate of 6%. Display these results as a formatted receipt to the console. RUBRIC 15 points - Your program can produce the EXACT output seen in the sample input/output 15 points - Your program adheres to the best practices discussed in class. 10 points - Your program compiles and runs without any errors. 10 points - Your code is well documented with comments

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions