If in the program someone gives me the number of days(ab="days") I need to set the variable 'days' as the same number(value in 'val'), if some one gives me the months(ab="months") then I need to convert(value in 'val') it into days, if someone gives me years(ab="years") then I need to convert(value in 'val') it into days. ie if the user specifies the type of values(ie whether it is month or year or date) in variable 'ab' and the number (of days/months/years) in variable 'val', I need to get number of days in the variable 'days'.
For example ab="years" and val = 3 then days is 1095(approximate).
What I tried is as below. Is it the right approach for the above problem? Thanks in advance.
public class conversionofdate {
public static void main(String args[]) {
String ab = "days";
int val = 0, days, month = 0, years = 0;
switch (ab) {
case "days":
days = val;
break;
case "months":
days = val * 30;
break;
case "years":
days = val * 12 * 30;
break;
default:
System.out.println("Incorrect value");
}
}
}