[JAVA] [Practice] Enumeration

Enumeration practice

◎ rekkyo practice class

package rekkyo_renshu;

public class Film {
	private String Name;		//Reservation name
	private FilmType filmType;	//Movie name

	//Enumeration type declaration. You cannot create an instance by specifying anything else
	enum FilmType{
		COMEDY,LOVE,HORROR
	}

	public Film(String name,FilmType ft) {
 //Use the received name as it is (because it is not used in the switch statement)
 //Substitute here
		String Name=name; 
        
//Processing when an instance containing variables of each enumeration type is created in a switch statement
		switch(ft) {
		case COMEDY:
			filmType=FilmType.COMEDY;
			System.out.println("Reserved movie name[AustinPowers]Reservation person name["+Name+"]");
			break;

		case LOVE:
			filmType=FilmType.LOVE;
			System.out.println("Reserved movie name[AboutTime]Reservation person name["+Name+"]");
			break;

		case HORROR:
			filmType=FilmType.HORROR;
			System.out.println("Reserved movie name[Shining]Reservation person name["+Name+"]");
			break;

		}

	}

}

◎ Main class


package rekkyo_renshu;

import rekkyo_renshu.Film.FilmType;

public class Main {

	public static void main(String[] args) {
		Film film1=new Film("Takayuki Yamada",FilmType.COMEDY);

	}
}


Execution result

Reserved movie name [Austin Powers] Reserved person name [Yamada Takayuki]

Recommended Posts

[Practice] Enumeration
[Practice] ArrayList
Array practice
[Practice] ArrayList
Array practice 2
if else practice
[Swift] Type type ~ Enumeration type ~
String Buffer practice
java practice part 1
[Practice] Map method