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

PROGRAMMING 2: Write a program to read vehicles speed, travel time and the vehic

ID: 3783850 • Letter: P

Question

PROGRAMMING 2:
Write a program to read vehicles speed, travel time and the vehicles MPG, calculate distance traveled and the number of gallons used.
Use either C++ or java language Public static void main PROGRAMMING 2:
Write a program to read vehicles speed, travel time and the vehicles MPG, calculate distance traveled and the number of gallons used.
Use either C++ or java language Public static void main PROGRAMMING 2:
Write a program to read vehicles speed, travel time and the vehicles MPG, calculate distance traveled and the number of gallons used.
Use either C++ or java language Public static void main

Explanation / Answer

import java.util.Scanner;

public class DistanceCovered {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
       double speed, travelTime, distance,distanceInMiles;
       int MPG;
      
       Scanner in=new Scanner(System.in);
      
       System.out.println("Enter the Speed of Vehicle in km/hr");
      
       speed=in.nextDouble();
      
       System.out.println("Enter the travel time in Minutes");
      
       travelTime= in.nextDouble();      
      
       System.out.println("Enter the Vehicle MPG");
      
       MPG=in.nextInt();
      
       System.out.println("numOfMPG= "+MPG);
      
       speed= speed * (5.0/18.0) ;      
      
       travelTime=travelTime*60;          
      
       distance = speed * travelTime;
      
       System.out.println("Distance travel in Meters= "+ (int)distance +" m");
      
       System.out.println("Distance travel in KiloMeters= "+ (int)(distance/1000) + " km");
      
       distanceInMiles= (distance/1000) * 0.6214;
      
       System.out.println("Distance travel in Miles= "+ distanceInMiles +" miles");
      
       System.out.println("Number of gallon used= "+ (int)(distanceInMiles/MPG));      
              
       in.close();
   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote