Java Create a computer program that will calculate the range for 3 different veh
ID: 3696243 • Letter: J
Question
Java Create a computer program that will calculate the range for 3 different vehicles. The program should create a "programmer created" class, where 3 int objects are created passengers, fuel capacity, mpg. Create a void() method inside the "programmer created" class to calculate vehicle range, range = fuel capacity * miles per gallon. Each Vehicle type should have unique values for number of passengers, fuel capacity, and miles per gallon. Follow the sample below and return information on 3 vehicle types. Sample Output://Create similar output for 3 Vehicle Types The minivan carries= 7 The minivan has a fuel capacity of = 16 The minivan mpg = 21 The minivan has a range of: 336 miles Create a Die "programmer created" class. Inside the "programmer created class" create 2 instance variables, each instance variable will be an integer type. Create a void method that returns the value of a die roll, (random number between 1-6) Create a void method the returns the value of two dice being rolled. All calculations and integer assignment will take place in the "programmer created" class, main in your program will only operate the execution of the program. Output will be the value of one random die roll and then the value of 2 random dice being rolled. Sample Output 1 die Roll = 5 2 dice Roll = 7 Example of main in the program.//main only contains calls to methods/objects created in the "programmer created" class public class DieRollClassDemo { public static void main(String[] args) { Die rollingdice = new Die(); rollingdice.dieroll(); rollingdice.diceroll();Explanation / Answer
1)
VehicleRange.java
package org.students;
public class VehicleRange
{
private String vname;
private int noofpassengers;
private int fcapacity;
private int milpergal;
public VehicleRange(String vname, int noofpassengers, int fcapacity,
int milpergal) {
super();
this.vname = vname;
this.noofpassengers = noofpassengers;
this.fcapacity = fcapacity;
this.milpergal = milpergal;
}
void calRange()
{
int range=fcapacity * milpergal;
System.out.println("The "+vname+" carries ="+noofpassengers);
System.out.println("The "+vname+" has a fuel capacity ="+fcapacity);
System.out.println("The "+vname+" mpg ="+fcapacity);
System.out.println("The "+vname+" has a range of :"+range+" miles");
System.out.println("_________________________________");
}
}
________________________________________________________________________-
Test.java
package org.students;
public class Test {
public static void main(String[] args) {
VehicleRange vr,vr1,vr2;
vr=new VehicleRange("Minivan", 7, 16, 21);
vr.calRange();
vr=new VehicleRange("Car", 4, 30, 15);
vr.calRange();
vr=new VehicleRange("Bus", 50, 40, 10);
vr.calRange();
}
}
______________________________________________________________________________-
output:
The Minivan carries =7
The Minivan has a fuel capacity =16
The Minivan mpg =16
The Minivan has a range of :336 miles
_________________________________
The Car carries =4
The Car has a fuel capacity =30
The Car mpg =30
The Car has a range of :450 miles
_________________________________
The Bus carries =50
The Bus has a fuel capacity =40
The Bus mpg =40
The Bus has a range of :400 miles
_________________________________
__________________________________________________________________________________-
2)
DiceRolled.java
package org.students;
import java.util.Random;
public class DiceRolled
{
private int single;
private int doubles;
public void singleDiceRolled()
{
Random r = new Random();
single=r.nextInt((6 - 1) + 1) + 1;
System.out.println("1 die rolled:"+single);
}
public void twoDiceRolled()
{
Random r = new Random();
doubles=r.nextInt((12 - 2) + 1) + 2;
System.out.println("2 dies rolled:"+doubles);
}
}
______________________________________________________________________________
DiesTest.java
package org.students;
public class DiesTest {
public static void main(String[] args) {
DiceRolled dr=new DiceRolled();
dr.singleDiceRolled();
dr.twoDiceRolled();
}
}
_______________________________________________________________
output:
1 die rolled:6
2 dies rolled:7
___________________________________________________________________________
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.