Ok, i'm very new to java and coding overall, and I have this assignment where I have to take user input , which will be a month, day and year, and multiply the month by the day and compare it to the last two digits of the year to check wether its a magic day or its not. While I accomplished this if the user only uses numbers as an input, I want to try and do another program where the users inputs the Month(Ex. April(not 4)) and I want to see if its possible for the program to check the enum, check for April and its value, and assign its value to the String month which then I will convert to a int. Sorry if my explanation is messy, But I explained to the best of my ability and feel free to ask if your confused about something.
Here's my code so far:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package magicadvanced;
import java.util.Scanner;
/**
*
* @author yfernandez
*/
public class MagicAdvanced {
public enum Months{
January(1),February(2),March(3),April(4),May(5),June(6),July(7),August(8),September(9),October(10),November(11),December(12);
private int value;
Months(int value){
this.value = value;
}
public int valueInt(){
return value;
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner ls=new Scanner(System.in);
String month,year,yrTwo;
int day,yearInt;
System.out.println("Please enter a month.");
month = ls.next();
System.out.println("Please enter a day.");
day = ls.nextInt();
System.out.println("Please enter the year.");
year = ls.next();
yrTwo = year.substring(2,4); //getting last two characters of the string year
yearInt = Integer.valueOf(yrTwo);// converting last two character of the string year into an integer
System.out.println(yearInt*2);//this is a just a test code to check if my conversion to integer works, will remove when program is done
}
}