Creating Playlist From Songs That User Has Entered
May 3, 2015
I'm trying to implement a playlist class that creates a playlist from songs that the user has entered. Basically, it'll have the following requirements:
There can be a maximum of 2 playlists.
Each playlist holds a maximum of 3 songs.
Can't be over 12 mins.
Can't be over 10 MB.
Can't use arrays (a real pain).
I'm really struggling with how to even go about this. I'll post majority of my code below, I know a lot of it can be condensed/improved but I'm just trying to focus on functionality at the moment.
Interface class:
public class Interface
{
Scanner console = new Scanner(System.in);
private SongDatabase database = new SongDatabase();
private Playlist playlist = new Playlist();
private int songCount=0;
[Code] .....
In short, the aspects that are relevant to the playlist functionality are the addSongtoPlaylist() method in Interface class, the getSong() method in SongDatabase class and the Playlist class.
Basically I need to make a program prompts the user for an integer, check to make sure the length entered by the user is a power of 2 and at least 2. Then I need to convert from base e to base 2 then I need to print the tick marks of a ruler based of the value of the length.
I got the whole converting thing working and the check for a power of 2, that wasn't an issue because it didn't require any recursion. I just don't know how to print out the proper tick mark values.
The way it is supposed to work is that it needs to look like this. Say the user enters 8;
012131210 012345678
Or if the user enters 16;
01213121412131210 01234567890123456
The bottom row is pretty much just the index value, that I print fine.
The top row though is supposed to be the length of the ticks on a ruler, with the middle most value being the value of the conversion from base e to base 2 from above. I can get that printed and what I get just looks like this.
For 8;
000030000 012345678
For 16;
00000000400000000 01234567890123456
As you can see I can get the middle value and the index values below but I don't know how to use recursion to get the right numbers.
Here's my current code.
import java.util.*; public class TickMarks { public static void main (String args[]){ Scanner input = new Scanner(System.in); boolean looping = true; while(looping == true){ System.out.print("Please enter a length: ");
[Code]...
Now the methods isPowerOfTwo() and printLength() both work fine. However, I'm not sure how to get the left and right side working.
My thoughts were to split the length in half and get a left and right side. I gave both of them arrays so I can keep track of the values. Now as you've seen above I get all zeros and I know it's because that's the default value in an array, I just don't know how to get the proper values.
Before continuing a task, any more accurate way to identify hashes? Currently, I am using regex + length of hash to give the user possible hashes.
Identifier class:
package votek; * Purpose: Class is used to run checks on possible hashes that the user has entered. */ public class Identifier {
//Hash entered by user is stored here private String hash; //String that will contain all possible hashes to share with user private String results = "Possible Hashes: "; //Method that runs the other hash methods checks and prints out the results.
I have a GUI with a textArea for the user to input numbers, a button which should "listen" for those numbers, and then a textField to display the sum. I have my code working for user input of one number; but I'm at a loss as to what sort of loop I need to create to get it to read each line of input. I wasn't sure whether to put this in the beginner forum or here, because I am definitely a beginner.
My program seems to work ok when i enter number in order like 1,2,3 = true , and all the numbers for false seem to be working as well! my problem is when i enter number like 3,2,4 that are not in order but still are consecutive!! I thought that another if statement would be the solution but i have tray several different ones and still can't make it work !!!
Java Code:
import java.util.*; public class Consecutive{ public static void main (String [] args){ Scanner console= new Scanner(System.in); System.out.println("Enter three numbers"); String numbers = console.nextLine();
Ask user to enter a name alphabet by alphabet, and print d whole word as output,,,,,, use while loop?Since i am new to JAVA..i have no clue on how to begin?
/** * Auto Generated Java Class. */ import java.util.*; public class Hangman { public static void main(String[] args) { Scanner input = new Scanner (System.in); int guess; boolean revealed[] = {false, false, false, false, false}; String word [] = {"c", "a", "n", "a", "d", "a"};
[Code] ....
I am not sure how to make the program check if the letter entered by the user matches the one in the array. also i am not sure how to make the program run again with a new word.
I have the code below that just keeps getting the user's name and displaying it until the user enter's an empty string. Well, to simulate that, I just hit the keyboard instead of entering any name but for some reasons I am not seeing in my code, the programme just keeps looping.
System.out.println("Enter your name : "); Scanner st = new Scanner(System.in); while(st.hasNext()){ System.out.println("Enter your name : "); String name = st.nextLine(); System.out.println(name); if(name==" ") break; } System.out.println("you are out of the while loop now!!");
I have returned with yet another problem but I think this one might be a bit easier to fix.
So the whole MO of this program is to take user input, and display the sum of the digits of the number they entered. I am supposed to do this by utilizing methods. So far this is what I have and when I compile it tells me that it "cannot find symbol", which I don't understand as I define what "m" is in the for loop. The other error is that it says:
"Exercise6_2.java:22: error: incompatible types: possible lossy conversion from long to int return result; ^
I don't understand why it's giving me this error nor do I understand why result seems to inherently be an int. (Also the public static int sumDigits(long n) method was given to me by the book so that is what I am supposed to use).
import java.util.Scanner; public class Exercise6_2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a integer"); long n = input.nextLong();
I need to write a Java program to perform a mathematical calculation between two numbers entered by the user. User has to choose the mathematical operation and input it and then when the user enters 2 numbers, he gets the answer. When user enters any other character other than *, /, + and - he should be able to exit. Perform calculation between numbers should be until user decided to exit from the program. My code is below, calculation part goes well, but can't get it exit when user enter any other character.. How to fix it?
import java.io.*; public class q11 { public static void main(String[]args)throws IOException { InputStreamReader ISR=new InputStreamReader(System.in); BufferedReader BR=new BufferedReader(ISR); while(true){ System.out.println("Enter.."); System.out.println("* : For multiplication");
Logic her eis when user selects option1, it asks for user to enter name and as soon as user enters name, it should compar name to existing names in txt file. I have user while loop and for loop but for some reason, it doesnt compare properly as there seems to be some mistake in looping and it just read first line or you can say single line rather than comparing it with all lines in txt file. i have attached votes.txt file with this. Also, if user doesnt exists infile, it will ask user to enter vote as yes or no and add it to file and then count total number of Yes and No votes from file and compare them.
my votes.txt file looks as below with two columns namely (name and vote).
Hiren No samir yes bob no rikul no master yes patrick no summer yes bhanja no
I'm trying to learn Java and my current project is to write a short program to determine the factorial of a number entered by the user. I haven't looked. There may be a method that will do it, but I want to use a for loop specifically.
What I have compiles just fine. I'm actually pretty thrilled just with that. Here is what I have:
class factorial { public static void main( String[] args) { Scanner scan = new Scanner(System.in ); int num; int product = 1;
Write a Java program that asks the user to store 10 numbers in an array. You should then print the array in the order entered and then print in reverse order. However, instead of putting all the information in the main, you should use a class called PrintIt. The PrintIt class should have an instance variable that is an array to hold the numbers. You should have a method that will print the array in the order entered. You will also need a method to print in reverse oder. Then create a tester class that asks the user to enter 10 numbers and puts them in an array.
So far I've got this.
public class printIt { int i; int [] numArr = new int [10]; public printIt () { i = -1;
[Code] .....
Output:
Enter a number:
8 34
Forward:
8 34
Reverse:
34 8
end
what i want as an number is being able to print out 10 numbers but this only lets me do two numbers. Why is that so?
The project is a program that allows the user to enter students and enter grades for each student. One of the requirements is that if there is already a grade stored for the student that it will display the previous grade. IF the user then enters a new grade the new grade will be stored. IF the user simply presses enter (enters an empty string) nothing is done. I have everything working except for the requirement of doing nothing if the user enters an empty string. If I just press enter at this point I get a NumberFormatException.
The below code is a method "setTestGrades" from the student class. This method iterates through each student object stored in an array list and then checks if there is a previous grade (Requirement# unset grades have to default to -1) before allowing the user to set a new grade.
public void setTestGrades(int testNumber) { //Sets the grade for the specified test number for each student in the arraylist. testNumber -= 1; Scanner input = new Scanner(System.in); for (int i = 0; i < studentList.size(); i++) { System.out.println("Please enter the grade for Test #" + (testNumber + 1) + " For Student " + studentList.get(i).getStudentName());
I am making a project that should play, stop, and loop three different songs (not at the same time). I am calling this SoundPlayer class from my main class:
import javax.sound.sampled.*; import java.util.*; public class SoundPlayer { List<AudioInputStream> songs = new ArrayList<AudioInputStream>(); int currentSong, currentPlayType;
[Code] ....
When my class calls setPlayType(2), which should make it play, I get the following runtime error:
java.lang.NullPointerException at SoundPlayer.playSong(SoundPlayer.java:32) at SoundPlayer.setPlayType(SoundPlayer.java:64) at MainPanel$AListener.actionPerformed(MainPanel.java:60) (...)
Line 32 is if(clip.isOpen()), but I'm pretty sure I instantiated clip properly in the constructor.
I'm having trouble with the last few lines of the code. It's supposed to take a replacement string entered by the user and print out the new string. For some reason it's now allowing me to enter a replacement string
import java.util.Scanner; public class Project02 { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter a long string: "); String lString = keyboard.nextLine();
[Code] ....
Output:
Enter a long string: the quick brown fox jumped over the lazy dog Enter a substring: jumped Length of your string: 44 Length of your substring: 6 Starting position of your substring in string: 20 String before your substring: the quick brown fox String after your substring: over the lazy dog Enter a position between 0 and 43: 18 The character at position 18 is x
Enter a replacement string: Your new string is: the quick brown fox over the lazy dog <------ isn't taking user input
I have an assignment for my intro class that requires me to read from a file that is a list of songs, their artists, and the year they were released. As seen below, a print line statement prompts the user to enter an artist name, and then it uses a buffered reader to gain input, and then it is supposed to match that input.I realize that this is not a complete statement, but I'm mostly concerned with getting the .indexOf statement to work.Currently it only returns the first object in the array.
for(int i = 0; i < song.length; i++) { System.out.println("Enter an Artist name"); String input1 = kb.readLine(); if (song[i].getArtist().indexOf(input1) > -1) { /*tried changing -1 to -2. When I do, it returns the first array entry, regardless of what I input*/ System.out.println(song[i].toString()); } }
The assignment is to: Use arrays to create an applet that lists five of your favorite songs.
The applet should scroll the list of song titles, one at a timeeach song title should start at the top of the applet and scroll to the middle then, scroll off the right hand sideeach new song title should scroll in a different colourthe applet should loop, that is, when it gets to the end of the list, start over again at the beginning of the list
I already have it looping the text with different colors. It's just they all loop at the same time. How to loop them separately. How to switch the program to where the strings will change with content and color on each loop that would work too.
Here is the code I got so far:
import java.awt.*; import java.applet.Applet; public class FavouriteSongs extends Applet implements Runnable { String[] Songs = {"Travelling Man-Chameleon Circuit", "Sing-Ed Sheeran", "It's Time-Imagine Dragons", "I See Fire-Ed Sheeran", "Colder Weather- Zac Brown Band"}; int yPos = 0, xPos = 50; Thread runner;
I am instructed to create a program that reads input from the user and turns it into a desired matrix size (row and column between 0-10). I have written the code for the input window, however I am having trouble with the Event Handler for the JButton in said window. The JButton should read the info (row and column size) and create three new windows. Two of the windows will hold info entered into the matrix by the user, and the third window will have another button that adds the two matrices together and shows the output. I have always had trouble comprehending how to use and implement JButtons. Here's my code thus far.