Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save enseitankad0/91c607a2b58ff61ffaf9f6064715d640 to your computer and use it in GitHub Desktop.
Save enseitankad0/91c607a2b58ff61ffaf9f6064715d640 to your computer and use it in GitHub Desktop.
ListIterator Playlist [Java]
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_9" project-jdk-name="9" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/70_linkedListChallenge_Kamil.iml" filepath="$PROJECT_DIR$/70_linkedListChallenge_Kamil.iml" />
</modules>
</component>
</project>
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="61a9dd28-3d5d-49f9-be33-a553dd47117d" name="Default" comment="" />
<ignored path="$PROJECT_DIR$/out/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<splitter split-orientation="horizontal" split-proportion="0.57835823">
<split-first>
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="Main.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="193">
<caret line="57" column="5" lean-forward="true" selection-start-line="57" selection-start-column="5" selection-end-line="57" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#printListAlbum#0;class#Main#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Song.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Song.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="36">
<caret line="2" column="17" lean-forward="false" selection-start-line="2" selection-start-column="17" selection-end-line="2" selection-end-column="17" />
<folding />
</state>
</provider>
</entry>
</file>
</leaf>
</split-first>
<split-second>
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file leaf-file-name="Song.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Song.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="11" column="29" lean-forward="false" selection-start-line="11" selection-start-column="29" selection-end-line="11" selection-end-column="29" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Album.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Album.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="53">
<caret line="64" column="9" lean-forward="true" selection-start-line="64" selection-start-column="9" selection-end-line="64" selection-end-column="9" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#489#490#0" expanded="true" />
<element signature="e#521#522#0" expanded="true" />
<element signature="e#654#655#0" expanded="true" />
<element signature="e#681#682#0" expanded="true" />
<element signature="e#721#722#0" expanded="true" />
<element signature="e#753#754#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</split-second>
</splitter>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>linked</find>
</findStrings>
</component>
<component name="GradleLocalSettings">
<option name="externalProjectsViewState">
<projects_view />
</option>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/com/eneseitankad0/Demo.java" />
<option value="$PROJECT_DIR$/src/com/eneseitankad0/Song.java" />
<option value="$PROJECT_DIR$/src/com/eneseitankad0/Album.java" />
<option value="$PROJECT_DIR$/src/com/eneseitankad0/Main.java" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-7" />
<option name="y" value="30" />
<option name="width" value="677" />
<option name="height" value="1057" />
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
<manualOrder />
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="PackagesPane" />
<pane id="AndroidView" />
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="70_linkedListChallenge_Kamil" type="b2602c69:ProjectViewProjectNode" />
<item name="70_linkedListChallenge_Kamil" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="70_linkedListChallenge_Kamil" type="b2602c69:ProjectViewProjectNode" />
<item name="70_linkedListChallenge_Kamil" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="70_linkedListChallenge_Kamil" type="b2602c69:ProjectViewProjectNode" />
<item name="70_linkedListChallenge_Kamil" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="eneseitankad0" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scratches" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$/../Arrays,-Java-inbuilt-Lists,-Autoboxing-and-Unboxing-LinkedList-Challenge-Part-3-(Final-video)-Source-code" />
<property name="settings.editor.selected.configurable" value="editor.preferences.fonts.default" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Application.Main">
<configuration name="Main" type="Application" factoryName="Application" temporary="true">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="MAIN_CLASS_NAME" value="com.eneseitankad0.Main" />
<option name="VM_PARAMETERS" value="" />
<option name="PROGRAM_PARAMETERS" value="" />
<option name="WORKING_DIRECTORY" value="file://$PROJECT_DIR$" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" value="" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="70_linkedListChallenge_Kamil" />
<envs />
<RunnerSettings RunnerId="Run" />
<ConfigurationWrapper RunnerId="Run" />
</configuration>
<configuration default="true" type="Application" factoryName="Application">
<extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
<option name="MAIN_CLASS_NAME" />
<option name="VM_PARAMETERS" />
<option name="PROGRAM_PARAMETERS" />
<option name="WORKING_DIRECTORY" />
<option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
<option name="ALTERNATIVE_JRE_PATH" />
<option name="ENABLE_SWING_INSPECTOR" value="false" />
<option name="ENV_VARIABLES" />
<option name="PASS_PARENT_ENVS" value="true" />
<module name="" />
<envs />
<method />
</configuration>
<recent_temporary>
<list size="1">
<item index="0" class="java.lang.String" itemvalue="Application.Main" />
</list>
</recent_temporary>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="61a9dd28-3d5d-49f9-be33-a553dd47117d" name="Default" comment="" />
<created>1521819711476</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1521819711476</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="22" width="1936" height="1066" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.20727673" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Palette&#9;" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="true" content_ui="tabs" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.26130098" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.108742006" sideWeight="0.5" order="5" side_tool="false" content_ui="combo" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Theme Preview" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.19153675" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="8" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="7" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32866043" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<option name="time" value="4" />
</breakpoint-manager>
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="612">
<caret line="36" column="0" lean-forward="true" selection-start-line="36" selection-start-column="0" selection-end-line="36" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#printListAlbum#0;class#Main#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Song.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="198">
<caret line="11" column="29" lean-forward="true" selection-start-line="11" selection-start-column="29" selection-end-line="11" selection-end-column="29" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Album.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="252">
<caret line="24" column="20" lean-forward="false" selection-start-line="24" selection-start-column="20" selection-end-line="24" selection-end-column="20" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#489#490#0" expanded="true" />
<element signature="e#521#522#0" expanded="true" />
<element signature="e#654#655#0" expanded="true" />
<element signature="e#681#682#0" expanded="true" />
<element signature="e#721#722#0" expanded="true" />
<element signature="e#753#754#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="504">
<caret line="29" column="45" lean-forward="false" selection-start-line="29" selection-start-column="45" selection-end-line="29" selection-end-column="45" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#printListAlbum#0;class#Main#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Album.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="19" column="40" lean-forward="false" selection-start-line="19" selection-start-column="40" selection-end-line="19" selection-end-column="40" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#489#490#0" expanded="true" />
<element signature="e#521#522#0" expanded="true" />
<element signature="e#654#655#0" expanded="true" />
<element signature="e#681#682#0" expanded="true" />
<element signature="e#721#722#0" expanded="true" />
<element signature="e#753#754#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Song.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="36">
<caret line="2" column="17" lean-forward="false" selection-start-line="2" selection-start-column="17" selection-end-line="2" selection-end-column="17" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Demo.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="10" column="2" lean-forward="false" selection-start-line="10" selection-start-column="2" selection-end-line="10" selection-end-column="2" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Song.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="36">
<caret line="2" column="17" lean-forward="false" selection-start-line="2" selection-start-column="17" selection-end-line="2" selection-end-column="17" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Album.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="53">
<caret line="64" column="9" lean-forward="true" selection-start-line="64" selection-start-column="9" selection-end-line="64" selection-end-column="9" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#489#490#0" expanded="true" />
<element signature="e#521#522#0" expanded="true" />
<element signature="e#654#655#0" expanded="true" />
<element signature="e#681#682#0" expanded="true" />
<element signature="e#721#722#0" expanded="true" />
<element signature="e#753#754#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/com/eneseitankad0/Main.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="193">
<caret line="57" column="5" lean-forward="true" selection-start-line="57" selection-start-column="5" selection-end-line="57" selection-end-column="5" />
<folding>
<element signature="imports" expanded="true" />
<element signature="method#printListAlbum#0;class#Main#0" expanded="false" />
</folding>
</state>
</provider>
</entry>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
package com.eneseitankad0;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class Album {
LinkedList<Song> albumList = new LinkedList<>();
private String name;
private String artist;
// konstruktor Albumu
public Album(String name, String artist) {
this.artist = artist;
this.name = name;
System.out.println("New album added");
}
public LinkedList<Song> getAlbumList() {
return albumList;
}
public void setAlbumList(LinkedList<Song> albumList) {
this.albumList = albumList;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
//dodawanie piosenki do albumu
public void addSong(String name, int duration) {
albumList.add(new Song(name, duration));
System.out.println("new song " + name + ": " + duration + "s" + " added to album " + this.name);
}
public void getSongsFromInside() {
for (int i = 0; i < this.albumList.size(); i++) {
System.out.println(" " + this.albumList.get(i).getName());
}
}
// to tzw. foreach za pomocą słowa kluczowego for. Po prostu naucz się tej składni.
// Będzie iterowana kolekcja this.songs, każdy element z niej będzie typu Song i
// zostanie umieszczony w zmiennej checkedSong.
// Sam znak dwukropka nie ma szczególnego znaczenia, jest nieodłączną częścią
// foreacha tak jak średniki są nieodłączną częścią zwykłego fora.
private Song findSong(String name) {
for (Song checkedSong : this.albumList) {
if (checkedSong.getName().equals(name)) {
return checkedSong;
}
}
return null;
}
public boolean addToPlaylist(int trackNumber, LinkedList<Song> playlist) {
int index = trackNumber - 1;
if ((index > 0) && (index <= this.albumList.size())) {
playlist.add(this.albumList.get(index));
return true;
}
System.out.println("this album does not contain track no: " + trackNumber);
return false;
}
//LinkedList<Song> playlist
public boolean addToPlaylist(String songTittle, LinkedList<Song> playlist) {
Song checkedSong = findSong(songTittle);
if (checkedSong != null) {
playlist.add(checkedSong);
System.out.println("Song " + songTittle + " added to playlist");
return true;
}
System.out.println("Can not find song");
return false;
}
}
package com.eneseitankad0;
// Create a program that implements a playlist for songs
// Create a Song class having Title and Duration for a song.
// The program will have an Album class containing a list of songs.
// The albums will be stored in an ArrayList
// Songs from different albums can be added to the playlist and will appear in the list in the order
// they are added.
// Once the songs have been added to the playlist, create a menu of options to:-
// Quit,Skip forward to the next song, skip backwards to a previous song. Replay the current song.
// List the songs in the playlist
// A song must exist in an album before it can be added to the playlist (so you can only play songs that
// you own).
// Hint: To replay a song, consider what happened when we went back and forth from a city before we
// started tracking the direction we were going.
// As an optional extra, provide an option to remove the current song from the playlist
// (hint: listiterator.remove()
// classes: Album -> to arraylist
//menu: quit,skip,>>, <<, replay, listen,
//import sun.awt.image.ImageWatched;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Scanner;
public class Main {
private static LinkedList<Album> albums = new LinkedList<>(); // PRIVATE STATIC
// ^ NON STATIC FIELD ALBUMS CAN NOT BE REFERENCE FROM A STATIC CONTEX
public static void main(String[] args) {
// ADDING SONGS
Album album = new Album("Kill Em All", "ACDC");
album.addSong("Seek & Destory", 12);
album.addSong("Ride The Lightin", 13);
album.addSong("Seek & Destory", 14);
albums.add(album);
album = new Album("Death Magnectis", "Metallica");
album.addSong("The Day That Never Comes", 123);
album.addSong("All NIghtmare Long", 123);
album.addSong("Blood and scared", 123);
albums.add(album);
//printListAlbum(albums);
printEverything(albums);
LinkedList<Song> playlist = new LinkedList<Song>();
albums.get(0).addToPlaylist("Seek & Destory", playlist);
albums.get(0).addToPlaylist(2, playlist);
albums.get(1).addToPlaylist(2, playlist);
printListPlaylist(playlist);
play(playlist);
}
public static void play(LinkedList<Song> playlist) {
Scanner scanner = new Scanner(System.in);
boolean forward = true;
boolean isQuit = false;
ListIterator<Song> listIterator = playlist.listIterator();
// ListIterator<Song> listIterator = playList.listIterator();
if (playlist.size() == 0) {
System.out.println("NO SONG IN PLAYLIST");
return;
} else {
System.out.println("NOW PLAYING " + listIterator.next().toString());
printMenu();
}
while (!isQuit) {
int choose = scanner.nextInt();
scanner.nextLine();
// 0 - to quit
// 1 - to play next song
// 2 - to play previous song
// 3 - to replay the current song
// 4 - list songs in the playlist
// 5 - print available actions.
// 6 - delete current song from playlist
switch (choose) {
case 0:
System.out.println("Playlist is Done");
isQuit = true;
break;
case 1: // PLAY NEXT SONG
if (!forward) { // domyslnie true
if (listIterator.hasNext()) { //jestesmy w pozycji 0 i sprawdzamy czy jest cos dalej
listIterator.next(); // przenosimy ^ wskaznik iteratora dalej
}
forward = true; // kierunek zostaje --->
}
if (listIterator.hasNext()) { // sprawadzamy czy jest cos dalej
System.out.println("Now playing " + listIterator.next().toString()); // gramy to co jest dalej(?)
} else { // jesli nie ma nic dalej
System.out.println("We have reached the end of the playlist");
forward = false;
}
break;
case 2: // PLAY PREVIOUS SONG
if (forward) { // moze byc true or false
if (listIterator.hasPrevious()) { // analogicznie do next
listIterator.previous();
}
forward = false;
}
if (listIterator.hasPrevious()) { // cofamy sie i puszczamy to co bylo wcześniej
System.out.println("Now playing " + listIterator.previous().toString());
} else { // jesli nie ma nic, nie da sie cofnac
System.out.println("We are at the start of the playlist");
forward = true;
}
break;
case 3: // REPLAY CURRENT SONG
if (forward) { // moze byc true or false
// czyli jesli jest cos wstecz to powtarzamy, a jesli nie to ostatnia znana piosenke
if (listIterator.hasPrevious()) {
System.out.println("Now replaying " + listIterator.previous().toString());
forward = false;
} else {
System.out.println("We are at the start of the list");
}
} else {
if (listIterator.hasNext()) {
System.out.println("Now replaying " + listIterator.next().toString());
forward = true;
} else {
System.out.println("We have reached the end of the list");
}
}
break;
case 4: // PRINT PLAYLIST
printListPlaylist(playlist);
break;
case 5: // PRINT THIS MENU
printMenu();
break;
case 6: // DELETE CURRENT SONG
if (playlist.size() > 0) {
listIterator.remove();
if (listIterator.hasNext()) {
System.out.println("Now playing " + listIterator.next());
} else if (listIterator.hasPrevious()) {
System.out.println("Now playing " + listIterator.previous());
}
}
break;
}
}
}
// method to print everything what is storaged in albums LinkedList (everything you've added)
public static void printEverything(LinkedList<Album> linkedList) {
System.out.println("=============================");
// System.out.println("List of song in album: " + albumName);
Iterator<Album> i = linkedList.iterator(); // coś jak for (int i = 0; i < linkedList.size(); i++ )
int j = 0;
while (i.hasNext()) {
j++;
Album currentAlbum = i.next();
System.out.println(j + ": " + currentAlbum.getName());
currentAlbum.getSongsFromInside();
}
System.out.println("=============================");
}
// method to print everything what is storaged in Album LinkedList (everything you've added to Album)
public static void printListAlbum(LinkedList<Album> linkedList) {
System.out.println("=============================");
// System.out.println("List of song in album: " + albumName);
Iterator<Album> i = linkedList.iterator(); // coś jak for (int i = 0; i < linkedList.size(); i++ )
int j = 0;
while (i.hasNext()) {
j++;
Album currentAlbum = i.next();
System.out.println(j + ": " + currentAlbum.getName());
}
System.out.println("=============================");
}
public static void printListPlaylist(LinkedList<Song> playlist) {
System.out.println("============ playlist =================");
// System.out.println("List of song in album: " + albumName);
Iterator<Song> i = playlist.iterator(); // coś jak for (int i = 0; i < playlist.size(); i++ )
int j = 0;
while (i.hasNext()) {
j++;
Song currentSong = i.next();
System.out.println(j + ": " + currentSong.getName());
}
System.out.println("=============================");
}
private static void printMenu() {
System.out.println("Available actions:\npress");
System.out.println("0 - to quit\n" +
"1 - to play next song\n" +
"2 - to play previous song\n" +
"3 - to replay the current song\n" +
"4 - list songs in the playlist\n" +
"5 - print available actions.\n" +
"6 - delete current song from playlist");
}
}
package com.eneseitankad0;
public class Song {
private String name;
private int duration; // duration in seconds
public Song(String name, int duration) {
this.name = name;
this.duration = duration;
// System.out.println("new song added: " + name + " / " + duration);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getDuration() {
return duration;
}
public void setDuration(int duration) {
this.duration = duration;
}
@Override
public String toString() {
return this.name + ": " + this.duration;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment