I am quite new to Java and I wanted to try and make a smoking calculator that tells the user how much they would save over a certain time period. I would appreciate if someone could tell me where they would improve my code and what other features they would add?
Should I always use objects when coding in java even for a basic program like this one?
import java.util.Scanner;
public class Calculator {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
//Packets
System.out.println("How many packets do you smoke a week?");
double packets = scan.nextDouble();
//cost
System.out.println("How much is each packet?");
double cost = scan.nextDouble();
//weekly
double weekly;
weekly = (cost*packets);
System.out.println("In one week you would save: €" + weekly);
//monthly
double monthly;
monthly = (weekly*4);
System.out.println("In one month you would save: €" + monthly);
//threeMonths
double threeMonths;
threeMonths = (weekly*12);
System.out.println("In three months you would save: €" + threeMonths);
//sixMonths
double sixMonths;
sixMonths = (weekly*26);
System.out.println("In six months you would save: €" + sixMonths);
//yearly
double yearly;
yearly = (weekly*52);
System.out.println("In one year you would save: €" + yearly);
//user input
System.out.println("Enter a number of years and see how much you will save over that time period...");
double user = scan.nextDouble();
double userInput;
userInput = (yearly*user);
System.out.println("You would save €" + userInput + " in " + user + " years.");
scan.close();
}
}