Jump to content

School Related > Arrays


Drewyboyo

Recommended Posts

1 minute ago, FrostBug said:

CBA to read all of that :boge: sorry.
If you could give a summary of what you're supposed to make with this, that'd probably help

4 people in an array/list,

4 locations in an array/list,

randomly select a person , and a place

and then I just simply print out the result.

Initial idea was to assign everyone a value, generate a value, and print whatever the value was assigned to

Link to comment
Share on other sites

2 minutes ago, Drewyboyo said:

4 people in an array/list,

4 locations in an array/list,

randomly select a person , and a place

and then I just simply print out the result.

Initial idea was to assign everyone a value, generate a value, and print whatever the value was assigned to

public class Clue {
	
	private final static String[] PEOPLE = {"Tom", "FrostBug", "NormieNurd", "Moldy" };
	private final static String[] PLACES = {"Library", "House", "Place", "OtherPlace" };
	
	public static void main(String[] args) {
		String person = PEOPLE[(int)(Math.random() * PEOPLE.length)];
		String place = PLACES[(int)(Math.random() * PLACES.length)];
		
		System.out.println("Murder at " + place + " by " + person);
	}
}

Like that?

  • Like 1
Link to comment
Share on other sites

4 minutes ago, FrostBug said:

public class Clue {
	
	private final static String[] PEOPLE = {"Tom", "FrostBug", "NormieNurd", "Moldy" };
	private final static String[] PLACES = {"Library", "House", "Place", "OtherPlace" };
	
	public static void main(String[] args) {
		String person = PEOPLE[(int)(Math.random() * PEOPLE.length)];
		String place = PLACES[(int)(Math.random() * PLACES.length)];
		
		System.out.println("Murder at " + place + " by " + person);
	}
}

Like that?

yea, i just added..
String person1 = PEOPLE[(int)(Math.random() * PEOPLE.length)];

and added in the print to make a murdered, and not just a murderer, thanks : D

Link to comment
Share on other sites

On 2/17/2018 at 1:58 PM, liverare said:

If you haven't figured out arrays work in Java, then I know you haven't a clue what 


private final static

means. You should probably tweak your code, unless you want to be that kid who hands in an A+ work, but who can't explain any of it.

i know final when regarding declaring variables, any different there? if so, then I could learn. Didn't even spot that part of the code till you pointed it out.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...