Using Arrays To Create Applet That Lists Five Of Favorite Songs
Jan 15, 2015
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 trying to create an applet with drop-down lists. When I compile the program the following error message appears '. . .is not abstract and doesn't override abstract method action Performed. . . Here is my code . . .
import java.awt.*; import java.awt.event.*; import java.applet.*; public class DavidApplet extends Applet implements ActionListener //class header { Label fName=new Label("First Name");
I'm not sure if my understanding of PriorityQueues is correct, so I'm trying to check if my reasoning is valid. I'm supposed to compare the Big-O for arrays and linked lists for the following instructions:
Insert 100 objects having the priorities 1, 2, 3, ... , 99, 100 Big-O for Array: __________ Big-O for Linked List: ___________
Insert 100 objects having the priorities 100, 99, 98, ... , 2, 1 Big-O for Array: __________ Big-O for Linked List(Assume no tail reference): ___________
If my understanding is correct, priority queues take in items randomly with no particular order, but they are removed according to the priority of each element. If what I've said is true, wouldn't that mean that inserting any number of objects would be O(1) for both linked lists and arrays? If the PriorityQueue has no particular order, then wouldnt each add() simply insert something to the next array index/linked list node?
I am trying to write a code that allows you to input 2 lists and it tells you if they are identical or not. However, when I enter my fist list I can only enter two values and then it asks for the next list. How would I fix this to allow me to enter more than two values?
Also, If the second list is different it has me enter more values that list one.
public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter values for list1 System.out.print("Enter list1: "); int size1 = input.nextInt(); int[] list1 = new int[size1]; for (int i = 0; i < list1.length; i++) list1[i] = input.nextInt(); // Enter values for list2 System.out.print("Enter list 2: ");
On my code, I am getting errors to put ; after the public void's. I'm not sure where the problem is seeing as my textbook pretty much had the same code that I just transferred the different data to....
import java.awt.*; import java.awt.event.*; import java.applet.*; public class MoveIt extends Applet implements ActionListener { private Image cup; private Panel keypad;
I'm working on a problem where I have to use the FileInputStream to opens a file that contains the name of a user's favorite book and then displays it.
If the file doesn't exist, then I prompt for the book title and write it to the file using FileOutputStream. This is what I have so far but I'm lost because if I put a file that exists in line 8 then it closes, but if I don't and the user puts their favorite book nothing happens. Or, as far as I can tell nothing does.
import java.io.*; class DisplayBook { public static void main(String[] args)
I've been using a Java applet for sports tables.It has been very useful for me. However, the recent developments from the people at Oracle have made this program impossible to use. The point is that I need this program and I need it fast.I've been in touch with the person who once created this applet and he has no intentions at all to upgrade it or do anything to make it function. How to make the program works with their new updates.
What I have to do: Use Applet to create two instances of the Employee class. Display the data on the Graphics object. Display in the applet the names and values of all of the instance variables in each instance of the class. Also display the value of any static variables.
What I'm doing:
import java.applet.Applet; import java.awt.*; public class EmployeeApplet extends Applet { public static int topSalary = 195000; int hoursPerWeek; public static void setTopSalary (int s) { if (s > topSalary)
[Code]...
I'm not able to display hours per week for e1 and e2.
I'm just learning about arrays. I have a small program to write that asks to create 2 arrays. One holding 5 names of flowers. One holding the prices of those 5 flowers. I ask the user what kind of flower they want and the quantity. I then need to create a loop that locates the flower name and uses that index to find the cost of the flower. I am struggling on how to write in code how to use one array index to find another. Example: Roses and $.50.
I am trying to create a program for class the uses two dimensional arrays. I am stuck on the second step that states Use two parallel arrays. One is a two-dimensional array -- a row of this array will hold six values in this order: [0] number of hours worked, [1] hourly pay rate, [2] gross pay, [3] net pay, [4] federal withholding, and [5] state withholding.
This is what I have so far:
Java Code:
double [][] data = new double [30][6]; String [] names = new String [30]; String str = null; String detail = null; int n = input(data, names, inputFile); mh_sh_highlight_all('java'); (there's more but i don't believe it pertains to this question)
My question is how would I create this array. Or, is that right above? I've searched online and in my book and I just don't understand.
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 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.
Create a method called mirrorImage, which takes two integer arrays as input parameters. You may assume that the two actual parameters have the same length. Your method should return true if the arrays are the reverse of each other. Otherwise mirrorImage should return false.
Examples:
data1:{1,2,3} data2:{3,2,1} ==> true
[code].....
I'm pointing a place outside of the array or something
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()); } }
I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff.
public void myFunc(MyNode n, ArrayList<MyNode> path) { boolean hasChildren = false; path.add(n); int index = path.indexOf(n); ArrayList<MyNode> statefulPath = new ArrayList<MyNode>();
[Code] ....
I have similar code that I stepped through in a debugger. After running the code I found that it built the desired tree, in this case a root node H with left child L and right child P. I want list of lists to contain all paths from root to leaf. I expected [H, L] and [H, P]. I discovered that statefulPath is not stateful; after a recursive stack frame pops, statefulPath still contains n! But that stack frame just popped! I expected to see statefulPath be [H] in the debugger and it was [H, L]! So I later have a list [H,L,P] which I don't want. How do I make the statefulPath list I want for my algorithm?
Why do I make private Node<AnyType> next;And why do I have an inner class of Node for a linked list?I had the same topic in C, but there it was somehow easier than in java. Because there you have pointers.
Write a Java function Sum2List that takes two lists L1 and L2 of the same size and returns list L that contains the sum of data inside the corresponding nodes of lists L1 and L2.
ex: L1 = {1,2,3} L2 = {4,5,6} L = {5,7,9}
I do not know how to iterate through two different lists >>
I have used unmarshalling concept to retrieve the data elements... I have to check whether the elements satisfy few regulations when compared with data in Database. So, i thought of grouping the employees depending on EType. I have created a Map with linkedlist of employees. Say Map<String, LinkedList<Employe>>EmpMap=new Map<String, LinkedList<Employe>>();
I have already created a class named Employee which has all the setter and getter methods for employee.
Here am going to take Etype(Employee type) as key and linkedlist(list of employees of certain type) as value. How to iterate these linked lists and place them in my Map.
What is going on here in the main class is a zoo that requires information to be read from and saved to a .txt file. I have made three arrayLists for each .txt file, I am getting errors for illegal start to an expression
import java.io.*; import java.util.*; public class ColumbusZoo { public static void addHelper(ArrayList<DomesticAnimal> a){ Scanner s = new Scanner(System.in); System.out.println("What species");
I am working on a assignment that has to do with array lists, it mainly has to do with adding new elements, telling then where it is it located, if the memory block is empty , ect. so far i have been having problems with my indexOf method which should display the array cell number that a input element E is in, and if it is not in there it should display a -1.
public class MyArrayList<E> { private E[] data_store = (E[])new Object[2]; private int sizeofa = 0; private void resize()// makes the array list bigger if need { E[] bigspacemaker = (E[])new Object[data_store.length * 2]; for(int x = 0 ; x< sizeofa ; x++)
[Code] ....
Error message: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 512 at MyArrayList.indexOf(MyArrayList.java:28) at MyArrayListDemo1.main(MyArrayListDemo1.java:26)