-4

This is my code, for each array we have been asked to extract a value, to make a getter a math.random and a .length. I'm trying all but purtropo I can not go on. can I come? thank you all

public Integer [] year = {2010, 2008, 2018, 2015, 1994,};

(Edit: Here is the code. How can I create a random and a switch with 3 case?)

utility package;
import java.util.Random;
public class TavoloLavoro {
  private static Integer [] year = {2010, 2008, 2018, 2015, 1994,};
  private static string [] brand = {"Fiat", "Ford", "Ducati", "BMW", "Yhamaha"};
  private static integer [] displacement = {1200, 250, 1400, 1000, 600};
  Entire static private [] times = {2,4};
  private static integer [] ports = {5, 3};
  private static power supply [] power supply = {power supply.
  private static integer [] capacity = {1000, 2000, 3000};
}

Alain Merigot
  • 10,667
  • 3
  • 18
  • 31
  • 3
    I don't understand what your requirements are. Can you explain them in more detail? – khelwood Feb 26 '19 at 14:07
  • 1
    Do you have to select a random element out of that array? If so `Math.random()` and the array's `length` property are a good start. Do you understand what both do? – Thomas Feb 26 '19 at 14:09
  • If I understand you, you want to select element from list with math random so try this, int var = (int)(Math.random()*year.length()); then use var and get your number from array. – Y.Kakdas Feb 26 '19 at 14:15
  • Possible duplicate of [How to randomly pick an element from an array](https://stackoverflow.com/questions/8065532/how-to-randomly-pick-an-element-from-an-array) – Ole V.V. Feb 26 '19 at 14:46
  • Welcome to Stack Overflow. I understand that it may be difficult making oneself understood on an English language site. On the other hand, if you can’t, we probably can’t help you, very sorry. – Ole V.V. Feb 26 '19 at 14:50

1 Answers1

1

Your question is quite unclear, but as far is i understand you want to pick a random element out of your year array. BTW DON'T MAKE YOUR GLOBAL VARIABLES PUBLIC!!!

private Random random = new Random(); //u need to import java.util.Random
private int year[] = new int[]{2010, 2008, 2018, 2015, 1994}; //you had a comma behind the last element...

private int random_value_from_array = year[random.nextInt(year.length)];