So I am attempting to write a DJ program that allows me to do some small functio
ID: 3839616 • Letter: S
Question
So I am attempting to write a DJ program that allows me to do some small functions. I may be making this more complicated than I need to and I need some help on figuring out how to get it to work.
This is the current weekly assignment.
Create a working version of your program based on the flowchart. This should be a working program that accepts user input, does some calculation, and shows the results. It does not have to use conditional expressions, loops, and the like.For a DJ manager, it asks for the average song length and the number of songs on a playlist, and it displays the length of the playlist.
and this is my course project overall if it helps any;
DJ Playlist Manager: You will develop a program for a DJ. The DJ needs to be able to enter data about his or her music collection, such as title, artist, length, genre, and so on. The user should be able to create individual playlists from a subset of the entire music collection. A report should be available showing the songs on a particular playlist, as well as their total length and average song length. There should also be a report showing the names of all the playlists and the total length of each playlist
And lastly, here is the code that I have so far. I would write a flow chart but again, I think I am over complicating it.
#include <iostream>
#include "stdafx.h"
using namespace std;
int main()
{
//Declare variables
string playlist1;;
constant rock1 = 2.52;
constant rock2 = 3.43;
constant rock3 = 4.57;
constant rock4 = 6.22;
real playlist1Length;
real songLengthAvg1;
cout << "Welcome to the DJ playlist program. ";
cout << "Please enter the name of the playlist you would like to see: ";
cin >> playlist1;
playlist1Length = rock1 + rock2 + rock3 + rock4
cout << "This is the " << playlist1 << "and the length is : " << playlist1Length;
songLengthAvg1 = (rock1 + rock2 + rock3 + rock4) / 4
cout << "The average song length in this playlist is: " << songLengthAvg;
return 0;
}
I only did a small part so far because of all of the errors but hopefully I can get help understanding how to format my ideas better and organize this project in a better way.
Explanation / Answer
This is just an example to make you understand , this program is using java
There are 3 classes:
Song,Playlist,driver class.
Song class will hold the data related to song.
Playlist class will perform all the fucntion of the playlists.
driver class is to perform the test.
I have commented, to understand better.
package songs;
public class Song {
private Float playTime;
private String songName;
private String artist;
//getters
public Float getPlayTime() { return playTime; }
public String getSongName() { return songName; }
public Song(Float playTime, String songName, String artist) {
super();
this.playTime = playTime;
this.songName = songName;
this.artist = artist;
}
public String getArtist() { return artist; }
}
Playlist Class:
package songs;
import java.util.ArrayList;
import java.util.List;
public class Playlist {
//Instance variable
private List<Song> songs; //arraylist of songs
private String playlistName; //Playlist name
public Playlist(String name) {
songs = new ArrayList<Song>(); //initalize Arraylist to hold Song type
playlistName = name;
}
//Methods:
//Returns the playlist name
public String playlistName() {
return playlistName;
}
//adds Song s to Playlist
public boolean addSong(Song s) {
return songs.add(s);
}
//return list. Note return is List<Song>.
public List<Song> getList() {
System.out.print(playlistName + ":");
for (int i = 0; i < songs.size(); i++)
System.out.print(songs.get(i));
return songs;
}
public boolean removeSong(Song s) {
return songs.remove(s);
}
public double playlistTime() {
double sum = 0;
for (int j = 0; j < songs.size(); j++)
sum = sum + songs.get(j).getPlayTime();
return sum;
}
public boolean isSongInPlaylist(String name) {
boolean x = false;
for (int i = 0; i < songs.size(); i++)
if (songs.get(i).getSongName().equalsIgnoreCase(name))
x = true;
return x;
}
public void songsByArtist(String name) {
for (int i = 0; i < songs.size(); i++)
if( songs.get(i).getArtist().equals(name))
System.out.println(songs.get(i).getArtist());
}
public boolean addSongsFrom(Playlist p) { // enter code here
boolean x = true;
for (int i = 0; i < p.getList().size(); i++)
if (p.getList().get(i).getSongName().equals(songs.get(i).getSongName()))
x = x;
else
this.addSong(p.getList().get(i));
return x;
}
public int totalSongs() {
return songs.size();
}
public String toString() {
return playlistName;
}
}
Driver Class:
package songs;
import java.util.Scanner;
public class Driver {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int flag=1;
Playlist py=null;
Song s = null;
while(flag==1)
{
System.out.println("Welcome DJ!!");
System.out.println("1.Create new playlist:");
System.out.println("2.Add songs:");
System.out.println("3.Remove Song:");
System.out.println("4.Show playlist time:");
int choice = sc.nextInt();
switch(choice)
{
case 1:
System.out.println("Enter the name of the playlist: ");
String name = sc.nextLine();
py = new Playlist(name);
case 2:
System.out.println("Enter the name of the song :");
String sname = sc.nextLine();
System.out.println("Enter playtime:");
float ptime = sc.nextFloat();
System.out.println("Enter artist name");
String aname = sc.nextLine();
s = new Song(ptime,sname,aname);
py.addSong(s);
case 3:
py.removeSong(s);
case 4:
py.playlistTime();
System.out.println("Want to continue?(1-yes/0-no)");
flag=sc.nextInt();
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.