Created
November 6, 2014 13:29
-
-
Save yassaa/f8f442535a63cca0f60b to your computer and use it in GitHub Desktop.
mainCinemaproject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.time.*; | |
import java.util.*; | |
import java.lang.*; | |
import java.io.*; | |
public class MainMovie { | |
public static void main(String[] args) { | |
Scanner input = new Scanner(System.in); | |
System.out.println("Enter your Name"); | |
String Name = input.nextLine(); | |
System.out.println("Enter your email"); | |
String Email = input.nextLine(); | |
System.out.println("Enter your Phonenumber in the format DDDDDDDD "); | |
String Phonenumber = input.next(); | |
if (Phonenumber.length() != 8){ | |
System.out.println("The Phonenumber is not valid, please enter a valid phonenumber in the format DDDDDDDD"); | |
} | |
Movie[] availableMovies = { | |
new Movie () {{ | |
movieName = "Die Hard 12 - THE SMACKDOWNENING"; | |
time = "18.30 - 20.00"; | |
Cinema= "1"; | |
}}, | |
new Movie () {{ | |
movieName = "Fast and Furious 10"; | |
time = "18.30 - 20.00"; | |
Cinema= "2"; | |
}}, | |
new Movie () {{ | |
movieName = "Zombievers 2"; | |
time = "18.30 - 20.00"; | |
Cinema= "3"; | |
}} | |
}; | |
Movie selectedMovie = promtUserMovieSelection(availableMovies); | |
System.out.println("You have selected: " + selectedMovie.movieName); | |
} | |
public static Movie promtUserMovieSelection(Movie[] movies) throws IOException { | |
System.out.println("Please chose a movie "); | |
int index = 1; | |
for(Movie m : movies) { | |
System.out.println(index ++ + ": " + m.movieName); | |
} | |
System.out.println(""); | |
System.out.print("Enter the number of the movie you like to watch: "); | |
Movie selectedMovie = null; | |
while(selectedMovie == null) { | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
try { | |
int i = Integer.parseInt(br.readLine()); | |
if(i-1 < 0 || i-1 > movies.length) { | |
System.err.println("Number has to be between 1 and " + movies.length+1); | |
} | |
else { | |
System.out.print(i); | |
selectedMovie = movies[i-1]; | |
} | |
} | |
catch(NumberFormatException nfe){ | |
System.err.println("Please try again. It has to be a WHOLENUMBER"); | |
} | |
} | |
System.out.println(""); | |
return selectedMovie; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment