Help how to use Random array Number
in
Programming Questions
•
11 months ago
I am trying to turn all these values below into random values how would i do that???
export2008[0] = 4; //assigning value in grams to the mangoe element in the array
export2008[1] = 2; //assigning value in grams to the papaya element in the array
export2008[2] = 1; //assigning value in grams to the banana element in the array
export2008[3] = 5; //assigning value in dollars to the price element
actual code below
boolean a = true;
//FruitCan code from assignment 8
class FruitCan
{
float mangoes; // mango content (grams)
float papaya; // papaya content (grams)
float banana; // banana content (grams)
float totalweight; // total weight (grams)
float price; // retail price of the can
FruitCan(float m, float p, float b, float t, float pr)
{
mangoes = m;
papaya = p;
banana = b;
totalweight = t;
price = pr;
}
}
void draw()
{
//assgining values in grams/dollars to "FruitCan" floats
int[] export2008 = new int[4];
export2008[0] = 4; //assigning value in grams to the mangoe element in the array
export2008[1] = 2; //assigning value in grams to the papaya element in the array
export2008[2] = 1; //assigning value in grams to the banana element in the array
export2008[3] = 5; //assigning value in dollars to the price element
int m = export2008[0]; //assigning m to value 4
int p = export2008[1]; //assigning p to value 3
int b = export2008[2]; //assigning b to value 2
int t = export2008[0]+ export2008[1] + export2008[2];//assigning t(total weight) by adding all the fruits
int pr = export2008[3]; //assigning pr to value in dollars 5
//creating true or false boolean
boolean a = true;
int d = m + b;
//if can contains at least 50% fruit by weight, and there are more papaya than banana boolean equals true
if (d >= t/2 || p < b)
{
a = true; //boolean a equals true
println("true"); //print "true" on the black screen
}
//anything that doesn't fall in the if statement is false
else
{
a = false; //boolean a equals false
println("false"); //print "false" on the black screen
}
}
1