Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 23-05-2009
Member
 
Join Date: Feb 2009
Posts: 96
I need JAVA help code inside

I have 2 classes but this is my main--- how do i have it so it takes 1 name at a time and displays 4999 spaces between the names? the test class is below.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class Friend extends Thread //make the class
{
private String spac = " ";
private final int wait = 4999;
private final int END = 1;
private String fName;

public Friend(String name)
{
fName = name;
}

public void run()
{
for(int x = 0; x < END; ++x)
{
System.out.print(fName);

try
{
sleep(4999);
}
catch(InterruptedException e)
{
}
}
}
}


Test Class:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class testFriend //make the class
{
public static void main(String[] args)
{
Friend a = new Friend(" Trista ");
Friend b = new Friend(" Nate ");
Friend c = new Friend(" Ash ");

a.start();
b.start();
c.start();

}
}
Reply With Quote
  #2  
Old 23-05-2009
Member
 
Join Date: Feb 2009
Posts: 96
Re: i need JAVA help code inside

also when the thread is started the names should print and the ordeer will change and the amount of blank spaces will be different between the names
Reply With Quote
  #3  
Old 23-05-2009
Member
 
Join Date: May 2008
Posts: 685
Re: i need JAVA help code inside

I have a small question regarding your program. What output do you want? Otherwise your code seems to be just fine. Did you tried to run your program? Do you got any error or wrong output? The only thing which I should change is replace your statement:

Code:
System.out.print(fName);
with

Code:
System.out.print(spac);
in your run().
Reply With Quote
  #4  
Old 23-05-2009
Member
 
Join Date: Feb 2009
Posts: 96
Re: i need JAVA help code inside

what i need is the following:
1st class creates thread with a constructor that accepts the name of a friend and stores the name in an instance variable. The run() method prints 4999 blank spaces then the friends name.

create a 2nd program with a main that creates 3 friends. The names are hard coded. Start the thread to see which name comes out 1st. When you run the program several times a different friend will win by a different margin-- represented by the number of blank spaces between the names.

output might look like:

alex

pat







sam

running 2nd time may look like:

same
alex




pat


thanks for your help
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "I need JAVA help code inside"
Thread Thread Starter Forum Replies Last Post
help me to understand java code (calendar java code) ? so0oma Software Development 2 10-01-2011 12:01 AM
how to put cookie inside this particular counter code? xitdude Software Development 4 21-09-2010 06:47 AM
Embedding Flex SDK .jar files inside a Java Project Tanveer Joshi Software Development 6 14-07-2010 12:07 AM
Inserting image inside the php code garfield1 Software Development 3 03-12-2009 02:00 PM
I have a code inside that needs tweaking JAVA Daren Software Development 1 28-05-2009 12:07 PM


All times are GMT +5.5. The time now is 03:30 PM.