Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Random

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Random

    Here is my code my question is how do i pick one of these superstars at random and get them to print out. This isnt my main application just the bit for creating superstars.
    import java.util.*;
    import javax.swing.*;
    import java.io.*;
     
    public class Superstars{
     
     
    /*
    public ArrayList superstar ;
    public CreateWrestler temp;
    CreateWrestler newWres;
     
     
     
     public void addSuperstar() throws IOException, FileNotFoundException{
    	    superstar = new ArrayList();
          	temp = new CreateWrestler();
          	temp.setName(JOptionPane.showInputDialog("Name: "));
          	temp.setHeight(JOptionPane.showInputDialog("Format this way(6'6\")Height: "));
          	temp.setWeight(Integer.parseInt(JOptionPane.showInputDialog("Weight: ")));
          	temp.setFrom(JOptionPane.showInputDialog("From: "));
     
     
          	superstar.add(temp);
     
          	File myFile = new File("superstar.dat");
     		FileOutputStream myFileOutputStream = new FileOutputStream(myFile);
     		ObjectOutputStream myObjectOutputStream = new ObjectOutputStream(myFileOutputStream);
     		myObjectOutputStream.writeObject(superstar);
     		superstarReader();
     
          }*/
     
    	public String getTrippleH(){
    		String trippleH = "General Information"+"\nHeight: 6'4\""+"\nWeight: 255 lbs."+"\nFrom: Greenwich, Conn."+
    				"\nSignature Move: Pedigree"+"\nCareer Highlights: WWE Champion, World Heavyweight Champion,"+"\nIntercontinental Champion, Unified WWE Tag Team Champion,"+
    				"\nWorld Tag Team Champion, European Champion, 1997 King of the Ring,"+"\n2002 Royal Rumble Match winner, WWE Chief Operating Officer.";
    		return trippleH;
    	}
     
    	public String getStoneCold(){
    		String stoneCold = "General Information\n"+"Height: 6'2\""+"\nWeight: 252 lbs"+"\nFrom: Victoria, Texas"+
    				"\nSignature Move: Stone Cold Stunner"+"\nCareer Highlights: WWE Champion, Intercontinental Champion,"+"\nWorld Tag Team Champion, King of the Ring (1996)"+
    				"\nRoyal Rumble winner (1997, 1998, 2001), WCW U.S. Champion"+"\nWCW Tag Team Champion, WWE Hall of Fame Class of 2009\n"+
    				"\nQuote: \"And thats the bottom line because Stone Cold said so!\"";
    		 return stoneCold;
    	}
     
     
    	public String getTheRock(){
    	String theRock =	"General Information"+"\nHeight: 6'5\""+"\nWeight: 260 lbs"+"\nFrom: Miami, Fla"+
    				"\nSignature Move: Rock Bottom, People's Elbow"+"\nCareer Highlights: WWE Championship, Intercontinental Champion, \nWorld Tag Team Champion, Royal Rumble winner (2000)"+
    				"\nWCW Champion\n"+"\nQuote: \"If you smell what the Rock is cooking\"";
    	return theRock;
     
    	}
     
    	public String getTheUndertaker(){
    		String theUndertaker = "General Information"+"\nHeight: 6'10\""+"\nWeight: 299 lbs"+"\nFrom: Death Valley"+
    			    "\nSignature Move: Chokeslam, Tombstone, Last Ride"+"\nCareer Highlights: WWE Champion, World Heavyweight Champion,"+
    			    "\nWorld Tag Team Champion, WCW Tag Team Champion,"+"\nHardcore Champion, undefeated at WrestleMania (20-0). ";
    	    return theUndertaker;
    	}
     
    	public String getRyback(){
    		String ryback = "General Information"+"\nHeight: 6'3\""+"\nWeight: 291 lbs."+"\nFrom: Sin City"+
    				"\nSignature Move: Shell Shocked\n"+"\nQuotes:\"FEED ME MORE\""+"\n\"FINISH IT....DONE!!!!\"";
    		return ryback;
    	}
     
    	public String getCMPunk(){
    		String cmPunk = "General Information"+"\n"+"\nHeight: 6'2\""+"\nWeight: 218 lbs"+"\nFrom: Chicago, IL"+
    				"\nSignature Move: G.T.S. (Go to Sleep), Anaconda Vise"+"\nCareer Highlights: WWE Champion; World Heavyweight Champion"+
    				"\nECW Champion; World Tag Team Champion"+"\nIntercontinental Champion, Raw commentator.";
    		return cmPunk;
    	}
     
    	public String getJohnCena(){
    		String johnCena = "General Information"+"\nHeight: 6'1\""+"\nWeight: 251 lbs"+"\nFrom: West Newbury, Mass"+
    				"\nSignature Move: Attitude Adjustment, STF"+"\nCareer Highlights: World Heavyweight Champion, WWE Champion,"+"\nU.S. Champion, World Tag Team Champion"+
    				"\nWWE Tag Team Champion, 2008 Royal Rumble Winner,"+"\n2012 Money in the Bank Ladder Match winner for a WWE Championship Contract\n "+"\nQuuote: \"The champ is here\"";
    		return johnCena;
    	}
     
    	public String getSheamus(){
    		String sheamus = "General Information"+"\nHeight: 6'4\""+"\nWeight: 267 lbs"+"\nFrom: Dublin, Ireland"+
    				"\nSignature Move: High Cross, Brogue Kick, Irish Curse"+"\nCareer Highlights: WWE Champion, U.S. Champion,"+
    				"\n2010 King of the Ring, 2012 Royal Rumble Match winner"+"\nWorld Heavyweight Champion";
    		return sheamus;
    	}[COLOR="Silver"]
    [/COLOR]

    --- Update ---

    can anyone help me????


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Random

    Please explain what the problem is. What does the code do incorrectly? What do you want it to differently?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Random

    i does nothing incorectly i just need to know how do i select one of these strings at random and to get it to print out

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Random

    how do i select one of these strings at random and to get it to print out
    Look at using the Random class's method to generate a random number and then use that number as an index into the array of Strings.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    JGriff (December 3rd, 2012)

  6. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Random

    ah cool now i understand thanks alot man nice one !!!

Similar Threads

  1. Generation of random number using random class
    By JavaPF in forum Java SE API Tutorials
    Replies: 1
    Last Post: December 7th, 2011, 05:46 PM
  2. Math.Random()
    By xionyus in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 26th, 2011, 10:22 PM
  3. Help with a random loop
    By A1one1nDarkness in forum Loops & Control Statements
    Replies: 1
    Last Post: October 20th, 2011, 07:54 AM
  4. random
    By b109 in forum Java Theory & Questions
    Replies: 2
    Last Post: June 3rd, 2010, 04:19 AM
  5. Generation of random number using random class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 16th, 2009, 06:10 AM

Tags for this Thread