Program:
import java.util.Scanner;
class find_your_age {
public static void main(String[] args) {
Scanner svrr = new Scanner(System.in);
double age=0.0;
try {
age = svrr.nextDouble();
} catch (Exception e){
errorHandler();
}
if(age<0){
negative();
}else if(age==0){
zero();
}
System.out.println("<=Your age on different planets=>\n--------------------------------\n Planets : Age");
System.out.println(" Earth : "+String.format("%.1f",(double)age)+" Years");
System.out.println(" Mercury : "+String.format("%.2f",(365.26 * age)/87.19)+" Years");
System.out.println(" Venus : "+String.format("%.2f",(365.26 * age)/224.70)+" Years");
System.out.println(" Mars : "+String.format("%.2f",(365.26 * age)/686.68)+" Years");
System.out.println(" Jupiter : "+String.format("%.2f",(365.26 * age)/4328.98)+" Years");
System.out.println(" Saturn : "+String.format("%.2f",(365.26 * age)/10760.55)+" Years");
System.out.println(" Uranus : "+String.format("%.2f",(365.26 * age)/30685.49)+" Years");
System.out.println(" Neptune : "+String.format("%.3f",(365.26 * age)/60191.19)+" Years");
System.out.println(" Pluto : "+String.format("%.3f",(365.26 * age)/90799.98)+" Years\n------------------------------------\n\n<=Your age on some Asteroids=>\n------------------------------------");
System.out.println(" Vesta : "+String.format("%.2f",(365.26 * age)/1325)+" Years");
System.out.println(" Ceres : "+String.format("%.2f",(365.26 * age)/1644)+" Years");
System.out.println(" Pallas : "+String.format("%.2f",(365.26 * age)/1686)+" Years\n------------------------------------\n\n<=Age on some Trans-Neptunian Objects=>\n ------------------------------------");
System.out.println(" Quaoar : "+String.format("%.3f",(365.26 * age)/104099.1)+" Years");
System.out.println(" Eris : "+String.format("%.3f",(365.26 * age)/113227.5)+" Years");
System.out.println(" MakeMake : "+String.format("%.3f",(365.26 * age)/112898.21)+" Years");
System.out.println(" Haumea : "+String.format("%.3f",(365.26 * age)/136108)+" Years");
System.out.println(" Sedna : "+String.format("%.3f",(365.26 * age)/204545.6)+" Years\n-------------------------------------\n\nThanks for trying.......\nComments your age....\nIf you like our post share our post.");
}
static void errorHandler(){
System.out.println("Wrong input, Enter your age, And try again...");
System.exit(0);
}
static void negative(){
System.out.println("Age can't be negative(-)\n\nJust input your real age ");
System.exit(0);
}
static void zero(){
System.out.println("Age can't be 0\n\nJust input your real age");
System.exit(0);
}
}
Post a Comment