Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part LC20.Points) Purpose: The purpose of this exercise is to become familiar wi

ID: 3842799 • Letter: P

Question

Part LC20.Points) Purpose: The purpose of this exercise is to become familiar with Java basic syntax. program structure, and problem solving. In addition, you should learn how to submit a program using the fie submit capability of Blackboard. Exercise: Write a Java program that calculates the cost of gas for a road trip. Your program will need to collect the following pieces of information from the user. First name Miles per gallon (mpg) of the car Number of miles planned to drive Current price per gallon of gas After collecting the user's information and the performing the calculations your program should display the results in a format similar to Sample Run (user's inputs are shown in bold: Ralph Please enter your First Name: Please enter the MPG of your car: 160 Please enter the miles to be traveled What is the price per gallon of gas: 2.000 Hello, Ralph! Thank you for providing your information! Car MPG: 160 Miles to Drive $2.00 Price per gallon of gas: $16.00 Your trip will cost: Program File Suggestions: Call your application Calculate Trip,java Call your output file HW3output.bd Part IL(20 Points): Purpose: To become familiar with Java language basics (variable declaration, numeric expression, assignment statement, input using Scanner, and formatting output). Problem Description: Write a program to accept inputs from a user including yourName, numbersharesshares (only whole shares allowed) purchased of some stock (for example the Microsoft stock symbol is MSF) at the price of buyPrice per share and paid the

Explanation / Answer

import java.util.*;
import java.util.Scanner;


public class Gascost
{
public static void main(String args[])
{
String name;
int Mpg, Milplan;
float price;

Scanner SC=new Scanner(System.in);

System.out.print("please enter yourFirst Name: ");
name=SC.nextLine();
System.out.print("Please enter MGP of your car: ");
Mpg=SC.nextInt();
   System.out.print("Please enter the miles to be traveled ");
Milplan=SC.nextLine();
System.out.print("what is the price gallon of gas: ");
price=SC.nextInt();
  

float tripcost=(Milplan/Mpg)*price;
  
System.out.println("hello," + name+"Thank you for providing information");
System.out.println("car MPG:" + Mpg);
   System.out.println("Miles to Drive:" + Milplan);
   System.out.println("price per gallon:" + price);
System.out.println("Trip will cost:" + tripcost);

}
  
}