Budding programmer. Wanna learn. How can I improve?
This program is an imaginary scenario to see if the user is eligible for a tax rebate.
import javax.swing.JOptionPane;
public class CarMileage
{
public static void main (String[] args)
{
//---Constant and Variable delcaration---//
final double WORKING_DAYS_PER_WEEK = 5.0; //No work on weekends
final double TO_AND_FROM = 2.0; //Takes into account traveling to AND from work.
final double PERCENT = 100.0; //Decimal result is multiplied by this to show actual percentage
double totalMileage;
double distanceToWork;
double weeksWorkedPerYear;
String userInput; //Handles the JOptionPane
//---User input---//
userInput = JOptionPane.showInputDialog("Enter total mileage");
totalMileage = Double.parseDouble(userInput);
userInput = JOptionPane.showInputDialog("Enter the distance you drive to work (in miles)");
distanceToWork = Double.parseDouble(userInput);
userInput = JOptionPane.showInputDialog("Enter the weeks you work per year");
weeksWorkedPerYear = Double.parseDouble(userInput);
//---Working out % of mileage not commuting to and from work---//
double mileageNotWork = (totalMileage - ((WORKING_DAYS_PER_WEEK * weeksWorkedPerYear) * (distanceToWork * TO_AND_FROM)));
double percentNotCommuting = ((mileageNotWork / totalMileage) * PERCENT);
System.out.println (percentNotCommuting + "% of mileage is not to and from work");
//---Checking if eligible for tax rebate---//
if (percentNotCommuting > 50){
System.out.println ("You are not eligible for a Tax Rebate!");
} else if (percentNotCommuting <= 50){
System.out.println ("You are eligible for a Tax Rebate!");
}
}
}