Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Fill an input array of size 10 with random numbers in the range between 1 and 10

ID: 3546094 • Letter: F

Question

Fill an input array of size 10 with random numbers in the range between 1 and 100

using the built-in subroutine random. Then ask the user to input a number. Output

the sum of numbers that are larger than the input number. Also, change the colour

of the numbers that are larger than this number, to red, only add code to areas specified in skeleton code

language should be java, a list of functions are here http://www.processing.org/reference/

String lastInput = new String();
String currentInput = new String();
int num;// num is the number entered by the user
int[] array = new int[10];// input array
PFont myFont;
int hOffset, vOffset, vSpacing, hSpacing;
int sum;
// Declare variables that you may need in here.


void setup()
{
size(700, 200);
smooth();
myFont = createFont("FFScala", 32);
textFont(myFont);
textAlign(LEFT);
vSpacing = 50;// vertical spacing between text
hSpacing = 50;// horizontal spacing between numbers
// initialize the array below


}
void draw()
{
background(255);
fill(0);
sum = 0;// sum of numbers
hOffset = 50;// horizontal offset. The position to show the first character
vOffset = 50;// vertical offset.
// add code below


// add code above
}

// keyPressed is a subroutine to handle input
// The most important information
// that is needed is that the inputs are in the variables i and s.
// num is the number entered by the user
void keyPressed()
{
if (key == ENTER)
{
lastInput = currentInput;
num = int(currentInput);
currentInput = "";
}
else
{
lastInput = "";
currentInput = currentInput + key;
}
}

Explanation / Answer

String lastInput = new String();

String currentInput = new String();

int num;// num is the number entered by the user

int[] array = new int[10];// input array

PFont myFont;

int hOffset, vOffset, vSpacing, hSpacing;

int sum;

// Declare variables that you may need in here.


void setup()

{

size(700, 200);

smooth();

myFont = createFont("FFScala", 32);

textFont(myFont);

textAlign(LEFT);

vSpacing = 50;// vertical spacing between text

hSpacing = 50;// horizontal spacing between numbers

// initialize the array below

int i;

for(i=0;i<10;i++)

{

array[i]=random(1,100);//random function

}

}



void draw()

{

background(255);

fill(0);

sum = 0;// sum of numbers

hOffset = 50;// horizontal offset. The position to show the first character

vOffset = 50;// vertical offset.

// add code below

int i;

for(i=0;i<10;i++)

{

if(array[i]>num)

{

fill(255,0,0);

sum=sum+array[i];

}

else

{

fill(0);

}

print(array[i]," ");

}

println("The sum is:",sum);

// add code above

}

// keyPressed is a subroutine to handle input

// The most important information

// that is needed is that the inputs are in the variables i and s.

// num is the number entered by the user



void keyPressed()

{

if (key == ENTER)

{

lastInput = currentInput;

num = int(currentInput);

currentInput = "";

}

else

{

lastInput = "";

currentInput = currentInput + key;

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote