Commit 51353aa3 authored by mahdikarami0111's avatar mahdikarami0111

initial commit

parents
Pipeline #5910 failed with stages
# Default ignored files
/shelf/
/workspace.xml
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?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_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/APW_S3.2.iml" filepath="$PROJECT_DIR$/APW_S3.2.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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>
\ No newline at end of file
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
MusicCollection pop = new MusicCollection();
MusicCollection rock = new MusicCollection();
MusicCollection jazz = new MusicCollection();
MusicCollection country = new MusicCollection();
MusicCollection temp = new MusicCollection();
int command = 0;
Scanner sc = new Scanner(System.in);
while (command != 6){
System.out.print("""
1.pop playlist
2.rock playlist
3.jazz playlist
4.country playlist
5.exit
""");
command = sc.nextInt();
if(command != 5){
switch (command) {
case 1 -> temp = pop;
case 2 -> temp = rock;
case 3 -> temp = jazz;
case 4 -> temp = country;
}
while (command != 7){
System.out.print("""
1.Add file
2.Get number of files
3.list all files
4.Remove file
5.Start playing
6.Stop playing
7.back
""");
command = sc.nextInt();
String file;
int index;
switch (command) {
case 1 -> {
System.out.println("Enter file name");
file = sc.nextLine();
file = sc.nextLine();
temp.addFile(file);
}
case 2 -> System.out.println(temp.getNumberOfFiles());
case 3 -> {temp.listAllFiles();
sc.nextLine();
}
case 4 -> {
System.out.println("Enter file index");
index = sc.nextInt();
temp.removeFile(index);
sc.nextLine();
}
case 5 -> {
System.out.println("Enter file index");
index = sc.nextInt();
temp.startPlaying(index);
sc.nextLine();
}
case 6 -> {temp.stopPlaying();
sc.nextLine();
}
}
System.out.println("Press Enter to continue");
file = sc.nextLine();
}
}
}
}
}
package com.company;
import java.util.ArrayList;
import java.util.Iterator;
public class MusicCollection {
// An ArrayList for storing the file names of music files.
private ArrayList<String> files;
// A player for the music files.
private MusicPlayer player;
/**
* Create a MusicCollection
*/
public MusicCollection()
{
files = new ArrayList<>();
player = new MusicPlayer();
}
/**
* Add a file to the collection.
* @param filename The file to be added.
*/
public void addFile(String filename)
{
files.add(filename);
}
/**
* Return the number of files in the collection.
* @return The number of files in the collection.
*/
public int getNumberOfFiles()
{
return files.size();
}
/**
* List a file from the collection.
* @param index The index of the file to be listed.
*/
public void listFile(int index)
{
if(validIndex(index)){
System.out.println(files.get(index));
}
}
/**
* Show a list of all the files in the collection.
*/
public void listAllFiles()
{
Iterator<String> it = files.iterator();
int i = 0;
while (it.hasNext()){
System.out.println(""+ i + "-"+ it.next());
i++;
}
}
/**
* Remove a file from the collection.
* @param index The index of the file to be removed.
*/
public void removeFile(int index)
{
if(validIndex(index)){
files.remove(index);
}
}
/**
* Start playing a file in the collection.
* Use stopPlaying() to stop it playing.
* @param index The index of the file to be played.
*/
public void startPlaying(int index)
{
if (validIndex(index)){
player.startPlaying(files.get(index));
}
}
/**
* Stop the player.
*/
public void stopPlaying()
{
player.stop();
}
/**
* Determine whether the given index is valid for the collection.
* Print an error message if it is not.
* @param index The index to be checked.
* @return true if the index is valid, false otherwise.
*/
private boolean validIndex(int index)
{
if(index > files.size()-1){
System.out.println("invalid index");
return false;
}
return true;
}
}
package com.company;
public class MusicPlayer {
// The current player. It might be null.
private boolean isPlaying;
/**
* Constructor for objects of class MusicFilePlayer
*/
public MusicPlayer()
{
isPlaying = false;
}
/**
* Start playing the given audio file.
* The method returns once the playing has been started.
* @param filename The file to be played.
*/
public void startPlaying(String filename)
{
System.out.println(filename + " is playing...");
isPlaying = true;
}
public void stop()
{
System.out.println("player is stopped!");
isPlaying = false;
}
}
# Default ignored files
/shelf/
/workspace.xml
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?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_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/APW_S3.iml" filepath="$PROJECT_DIR$/APW_S3.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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>
\ No newline at end of file
package com.company;
public class ClockDisplay {
private NumberDisplay hours;
private NumberDisplay minutes;
private NumberDisplay seconds;
private String displayString; // simulates the actual display
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at 00:00.
*/
public ClockDisplay()
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
seconds = new NumberDisplay(60);
updateDisplay();
}
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at the time specified by the
* parameters.
*/
public ClockDisplay(int hour, int minute, int second)
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
seconds = new NumberDisplay(60);
setTime(hour, minute, second);
}
/**
* This method should get called once every minute - it makes
* the clock display go one minute forward.
*/
public void timeTick()
{
seconds.increment();
if(seconds.getValue() == 0){
minutes.increment();
if(minutes.getValue() == 0) { // it just rolled over!
hours.increment();
}
}
updateDisplay();
}
/**
* Set the time of the display to the specified hour and
* minute.
*/
public void setTime(int hour, int minute, int second)
{
hours.setValue(hour);
minutes.setValue(minute);
seconds.setValue(second);
updateDisplay();
}
/**
* Return the current time of this display in the format HH:MM.
*/
public String getTime()
{
return displayString;
}
/**
* Update the internal string that represents the display.
*/
private void updateDisplay()
{
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue() + ":" + seconds.getDisplayValue();
}
public void print(){
System.out.println(displayString);
}
}
package com.company;
public class Main {
public static void main(String[] args) {
ClockDisplay c = new ClockDisplay();
c.timeTick();
c.print();
int i;
for(i=0;i<250;i++){
c.timeTick();
}
c.print();
for(i=0;i<2500;i++){
c.timeTick();
}
c.print();
for(i=0;i<3400;i++){
c.timeTick();
}
c.print();
for(i=0;i<13400;i++){
c.timeTick();
}
c.print();
}
}
package com.company;
public class NumberDisplay {
private int limit;
private int value;
/**
* Constructor for objects of class NumberDisplay.
* Set the limit at which the display rolls over.
*/
public NumberDisplay(int rollOverLimit)
{
limit = rollOverLimit;
value = 0;
}
/**
* Return the current value.
*/
public int getValue()
{
return value;
}
/**
* Return the display value (that is, the current value as a two-digit
* String. If the value is less than ten, it will be padded with a leading
* zero).
*/
public String getDisplayValue()
{
if(value < 10) {
return "0" + value;
}
else {
return "" + value;
}
}
/**
* Set the value of the display to the new specified value. If the new
* value is less than zero or over the limit, do nothing.
*/
public void setValue(int replacementValue)
{
if((replacementValue >= 0) && (replacementValue < limit)) {
value = replacementValue;
}
}
/**
* Increment the display value by one, rolling over to zero if the
* limit is reached.
*/
public void increment()
{
value = (value + 1) % limit;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment