Write a program that calculates the cost of a camping trip based on the followin
ID: 666290 • Letter: W
Question
Write a program that calculates the cost of a camping trip based on the following chart of costs.
Camping Trip Cost
Here is an example program dialogues to guide your efforts:
Lemme Calculate Your Camping Trip Cost!
How Many Miles Are You Driving? 1000
How Many People? 2
How Many Days? 1
How Many Nights? 1
Driving A Hybrid? [1=YES, 0=NO] 0
Your Road Trip Will Cost: $290.00
Drive Safely
Lemme Calculate Your Camping Trip Cost!
How Many Miles Are You Driving? 1000
How Many People? 2
How Many Days? 1
How Many Nights? 1
Driving A Hybrid? [1=YES, 0=NO] 1
Your Road Trip Will Cost: $260.00
Drive Safely
Your program should properly request input from the user and use constants to represent certain fixed values.
Camping Trip Cost
Type Amount Driving Cost $0.15 per mile driven Overnight Stay $50 for each overnight per person Meal Cost $20 per day per person Hybrid Car Savings 20% driving cost decreaseExplanation / Answer
import java.util.Random;
import java.util.Scanner;
public class Driving{
public static void main(String[] args){
final double drivingC=0.15;
final double Overnight=50;
final double hybrid=0.8;
final double meal=20;
Scanner s=new Scanner(System.in);
System.out.println("Lemme Calculate Your Camping Trip Cost!");
System.out.print("How Many Miles Are You Driving?");
double miles=s.nextDouble();
System.out.print("How Many People?");
double numofP=s.nextDouble();
System.out.print("How Many Days? ");
double numD=s.nextDouble();
System.out.print("How Many Nights? ");
double numN=s.nextDouble();
System.out.print("Driving A Hybrid? [1=YES, 0=NO]");
int isHybrid=s.nextInt();
double tCost=0;
tCost=miles*drivingC;
tCost=tCost+numN*numofP*Overnight;
tCost=tCost+numofP*numD*meal;
if(isHybrid==1){
tCost=tCost*hybrid;
}
System.out.println("Your Road Trip Will Cost:"+tCost+" Drive Safely");
}}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.