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;
 
[Code] .....

View Replies


ADVERTISEMENT

Array Of Objects To Create 3 CDs (music) - Moving Songs?

Oct 17, 2014

Do I need to use inheritance for this type of program? How to move my song list in main to songs and from songs to cd to make 3 separate cd's.

I have 3 classes: main, Cd, and Song. I am having trouble moving the songs from main to the song class and from the song class to Cd.

package p2;
public class Main {
public static void main(String[] args) {
String tempStr;
//array for song names
String [] songNames={

[Code] ....

View Replies View Related

Creating Applet With Dropdown Lists - Method Not Abstract

Oct 21, 2011

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");

[Code] .....

View Replies View Related

Big-O Involving Arrays And Linked Lists When Using PriorityQueue

Oct 25, 2014

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?

View Replies View Related

Java Arrays - Entering Lists Only Let To Enter 2 Numbers?

Oct 9, 2014

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: ");

[code]...

My output looks like this:

Enter list1: 1
2
Enter list 2: 2
3
2

Two lists are not identical

View Replies View Related

Trying To Create Clickable Applet But Won't Compile

Apr 18, 2014

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;

[Code] ....

View Replies View Related

Use FileInputStream To Open A File That Contains Name Of User Favorite Book And Then Displays It

Aug 9, 2014

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)

[code]....

View Replies View Related

How To Create Sports Tables Java Applet

Jun 1, 2014

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.

View Replies View Related

Use Applet To Create Two Instances Of Employee Class

Jan 9, 2014

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.

View Replies View Related

Program That Asks To Create 2 Arrays

Oct 24, 2014

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.

View Replies View Related

Unable To Create A Program For Class Using Two Dimensional Arrays

Dec 6, 2014

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.

View Replies View Related

Play / Stop And Loop Three Different Songs

May 13, 2014

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.

View Replies View Related

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.

View Replies View Related

Create A Method Called MirrorImage Which Takes Two Integer Arrays As Input Parameters

Jan 8, 2009

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

runtime error (line 8, column 0): java.lang.ArrayIndexOutOfBoundsException: 10

-> array.ArrayQuestions.mirrorImage()

View Replies View Related

Searching Array - Read From A File That Is List Of Songs

Oct 10, 2014

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());
}
}

View Replies View Related

What Is The Difference Between Regular Arrays And Multi Dimensional Arrays

Jun 28, 2014

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.

View Replies View Related

Recursion And Lists?

Aug 6, 2014

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?

View Replies View Related

How To Iterate Two Lists At A Time

Mar 25, 2015

List list1 = query1.list();
List list2 = query2.list();
 
for (Iterator itr = list1.iterator(); itr.hasNext();) {
Object[] row = (Object[]) itr.next();
}

View Replies View Related

Linked Lists In Java

Nov 27, 2014

I currently don't understand how the node's work.

private static class Node<AnyType>
{
private AnyType data;
private Node<AnyType> next;
public Node(AnyType data, Node<AnyType> next)
{
this.data = data;
this.next = next;
}
}

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.

View Replies View Related

Iterating Through Linked Lists

Apr 27, 2014

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 >>

public LinkedList Sum2List(LinkedList l1, LinkedList l2){
LinkedList l3 = new LinkedList();
ListNode Current1 = L1.getFront();
ListNode Current2 = L2.getFront();
while(Current1 != null){
l3.Add(Current1.getItem() + Current2.getItem());

[Code] .....

This my attempt to write the code , but the dr. side that we have not to use the build in methods ( getNext()...etc)
in the function .

View Replies View Related

MergeSort With Comparable And Lists

Jun 1, 2014

I have big problem with mergesort in Java. I can't figure out why it do not works. I need write it on lists using Comparable. Here is piece of code:

Java Code:

class MergeSort{
Comparator _comparator;
List lista = new ArrayList<>();
List list_temp = new ArrayList<>();
MergeSort(Comparator comparator){

[Code] ....

I have tried everything, still no results. It's return list with random placed numbers.

View Replies View Related

How To Iterate Through Linked Lists And Add Them To A Map

Mar 10, 2014

I have an XML sheet and my project is top retrieve the required elements from XML sheet. So my format of XML was like follows:

<Class>
<Employees>
<EMPLOYEE>
<ENum> Abc123</ENum>
<Ename> John<?Ename>
<EType>Mathematics</EType>

[Code] ....

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.

View Replies View Related

Array Lists In A Class

Dec 6, 2014

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");

[code].....

View Replies View Related

Array Lists - Adding New Elements

Apr 1, 2014

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)

View Replies View Related

Delete Method With Linked Lists?

Jul 19, 2014

Why is this method throwing a null pointer exception when I call it from main?

I'm trying to submit an integer to indicate the number of nodes in a linked list to delete and then delete them headfirst.

public boolean delete(int x){
if (x > count || head == null){
return false;
}else{ while (x>0){
head = head.getPrevious();

[Code] ....

View Replies View Related

Sorting Lists In Employee Class

Feb 5, 2014

A Employee Class where i want to sort there lists one by there salary and one by there name individually as per the requirement ? How we do it?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved