Solve the following programming problems by developing algorithm and then implem
ID: 3818101 • Letter: S
Question
Solve the following programming problems by developing algorithm and then implementing it in Java. source code for java
The variable fuelAmount and fuelCapacity hold the actual amount of fuel, and the size of the fuel tank of a vehicle. If less than 10 percent is remaining in the tank, a status light should show a red color; otherwise it shows a green color. Simulate this process with the values of the fuelAmount and fuelCapacity read from the user, and the program printing “red” or “green” for the particular values.
Explanation / Answer
Answer:
Algorithm:
1)Read the fuelamount and fuelcapacity from user
2)Calculate the 10 percent of fuelcapacity
3) If 10 percent of fuel capcity is great the fuel amount then print "Red" Otherwise "green"
below is the code in java
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
class sol{
public static void main(String[] args) {
double fuelAmount,fuelCapacity;
Scanner in = new Scanner(System.in);
System.out.println("Enter the fuel amount and fuel capacity");
fuelAmount=in.nextDouble();//reading from user
fuelCapacity=in.nextDouble();//reading from user
double re=fuelCapacity/10;
if(fuelAmount<re)
System.out.println("Red");
else
System.out.println("Green");
}
}
Compilation Successful
Input (stdin)
Your Output
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.