Results 1 to 4 of 4

Thread: I need JAVA help code inside

  1. #1
    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();

    }
    }

  2. #2
    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

  3. #3
    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().

  4. #4
    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

Similar Threads

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

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,425,210.86901 seconds with 17 queries