Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tools;
- import java.util.Scanner;
- import java.util.ArrayList;
- public class Driverclass {
- @SuppressWarnings("resource")
- public static void main(String[] args) {
- //Total of 4 classes, driver class and 3 others
- //one constructor at each class, 1 class with multiple constructors
- //all classes have getters and setters, and at least one method with a parameter
- //at least 1 method who returns something
- //at least 1 array with objects
- //at least 1 loop , and use of if statements
- //input by the user
- //error processing exception at least once
- //program should enable the user to choose things
- //your classes use private properties - getters and setters
- String tempName;
- String tempPassword;
- String tempEmail;
- Playlist tempPlaylist;
- Musicplayer player = new Musicplayer();
- ArrayList<Playlist> playlists = new ArrayList<Playlist>();
- System.out.println("Welcome to Spotify");
- System.out.println("What would you like to do today?");
- while(true) {
- //Main menu//
- Scanner numberInput = new Scanner(System.in);
- int number;
- System.out.println("\nCreate an account = \t \t 1 \nCheck playlists = \t \t 2 \nAccess the music player = \t 3 \nQuit program = \t \t \t 0 ");
- number = numberInput.nextInt();
- //---------------------------------------------------------------------//
- //This exits the program.
- if (number == 0) {
- System.out.println("You've chosen to exit the program");
- System.out.println("Thanks for using Spotify, hope to see you soon");
- return;
- }
- //------------------------------------------------------------------//
- //This menu lets you create accounts or see premade accounts//
- if (number == 1){
- System.out.println("There are no created accounts yet, would you like to create one?");
- Scanner scanner = new Scanner(System.in);
- String input = scanner.next();
- switch(input) {
- case "yes":
- System.out.println("Creating your account...");
- Scanner in = new Scanner(System.in);
- System.out.println("Create a username");
- tempName = in.next();
- System.out.println("Create a password");
- tempPassword = in.next();
- System.out.println("Enter your Email");
- tempEmail = in.next();
- Account a1 = new Account(tempName, tempPassword, tempEmail);
- System.out.println("Thank you for registering, here are your account details:" + "\n" + a1);
- break;
- case "no":
- //return to main menu?
- break;
- }
- }
- //------------------------------------------------------------------//
- //This menu brings you to the playlists.
- if (number == 2){
- if (playlists.size() == 0) {
- System.out.println("There are no playlists available");
- System.out.println("Would you like to create a playlist?");
- }else {
- for(int i = 0; i < playlists.size(); i++) {
- System.out.println(playlists.get(i));
- }
- System.out.println("Would you like to create a new playlist?");
- }
- Scanner scanner = new Scanner(System.in);
- String input = scanner.next();
- switch(input) {
- case "yes":
- System.out.println("Creating a playlist...");
- Scanner in = new Scanner(System.in);
- System.out.println("Enter a name for your playlist");
- tempPlaylist = new Playlist(in.next());
- for (int i = 0; i < 2; i++) {
- System.out.println("Enter a song name");
- tempPlaylist.addSong(in.next());
- }
- playlists.add(tempPlaylist);
- System.out.println("Playlist has been added");
- System.out.println(tempPlaylist);
- break;
- case "no":
- break;
- }
- }
- //------------------------------------------------------------------//
- //This menu brings you to the music player.
- if (number == 3) {
- System.out.println("Welcome to the music player \n type 'play' to start playing \n "
- + "type 'insert to add a playlist to play \n type 0 to return to main menu");
- Scanner scanner = new Scanner(System.in);
- String input = null;
- boolean inProgress = true;
- while(inProgress) {
- input = scanner.next();
- switch(input) {
- case "insert":
- System.out.println("Please select the index of the playlist you want to insert");
- for(int i = 0; i < playlists.size(); i++) {
- System.out.println("index " + i + ": " + playlists.get(i));
- }
- int selectedIndex = Integer.valueOf(scanner.next());
- try {
- player.setPlaylist(playlists.get(selectedIndex));
- System.out.println("Inserted playlist: " + playlists.get(selectedIndex));
- }catch (java.lang.IndexOutOfBoundsException e) {
- System.out.println("There is no playlist, please create one first");
- break;
- }
- break;
- case "play":
- try {
- player.playMusic();
- System.out.println("Now playing..." + player.getPlaylist());
- }catch (NoPlaylistException e) {
- System.out.println("Please insert a playlist first");
- }
- break;
- case "0":
- inProgress = false;
- break;
- }
- }
- }
- //------------------------------------------------------------------//
- }
- }
- }
- --------------------------------------------------------------------------------------------------------------------------------
- package tools;
- public class Account {
- //lets the user create an account, multiple times and check already made accounts
- private String name;
- private String password;
- private String email;
- public Account (String name, String password, String email) {
- this.name = name;
- this.password = password;
- this.email = email;
- }
- public Account () {
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- public String toString() {
- return "Your account name" + "\t" + "\t: " + name + "\n" +
- "Your account password" + "\t" + "\t: " + password + "\n" +
- "Your account email" + "\t" + "\t: " + email + "\n";
- }
- }
- ------------------------------------------------------------------------------------------------------------------------
- package tools;
- import java.util.ArrayList;
- public class Playlist {
- //has an array with pre-made playlists and an option to create your own array with playlists
- private String name;
- private ArrayList<String> songs;
- public Playlist (String name) {
- this.name = name;
- this.songs = new ArrayList<String>();
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public void addSong(String name) {
- this.songs.add(name);
- }
- public void removeSong(String name) {
- this.songs.remove(name);
- }
- public String toString() {
- return this.name + ": " + songs.toString();
- }
- }
- ---------------------------------------------------------------------------------------------------------------
- package tools;
- public class Musicplayer {
- //this lets you see a random number that is playing, and you can pause it or play again.
- Playlist playlist;
- boolean playing;
- public Musicplayer() {
- }
- public void playMusic() throws NoPlaylistException {
- if(playlist == null) {
- throw new NoPlaylistException("Insert playlist first");
- }
- playing = true;
- }
- public void stopMusic() {
- playing = false;
- }
- public Playlist getPlaylist() {
- return playlist;
- }
- public void setPlaylist(Playlist playlist) {
- this.playlist = playlist;
- }
- public boolean getPlayMusic() {
- return playing;
- }
- }
- class NoPlaylistException extends Exception {
- NoPlaylistException(String s) {
- super(s);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement