# Need help - very beginner

**URL:** <https://discourse.processing.org/t/need-help-very-beginner/14964>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [October 27, 2019, 2:20pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964 "2019-10-27T14:20:59Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![actuallyagod](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@actuallyagod](https://discourse.processing.org/u/actuallyagod)\
**Post date:** [October 27, 2019, 2:20pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/1 "2019-10-27T14:20:59Z")

</div>

I have gotten a little school project, should be rather easy but i am completely lost. hope to find some help here.

I am supposed to make something like this:

[https://gyazo.com/d9f0a1921c3eea3fc2fe6c691838be37](https://gyazo.com/d9f0a1921c3eea3fc2fe6c691838be37)

On the top left i have the number i am currently writing for example “271”, when i hit enter the number is supposed to go down to the 10 next numbers in the left row where the last 10 numbers ive written are. And on the bottom left is the average.

On the top right i have my mouse’s cursor position, when i click left mouse the number will go down to the next 10 numbers in the right row and the last number is the average.

This is the code I have as of right now, however I cant get the enter function to work. please help:

```auto
int numbers[] = new int [10];
int currentNumberIndex = 0;
int mouseClicks[] = new int[10];
int currentClickIndex = 0;
String currentNumberString = "";
int aaa = currentNumberString.length();

void setup() {
  size(300,300);
  background(0);
  fill(255,105,180);
  textSize(25);
  textAlign(LEFT, TOP);
}

void draw() {
  clear();
  if(currentNumberString != "") {
    printNumbers(Integer.parseInt(currentNumberString), mouseY, 0);
  }
  else {
    printNumbers(0, mouseY, 0);
  }
  
  for(int i = 0; i < numbers.length; i++) {
    text(Integer.toString(numbers[i]) + "" + Integer.toString(mouseClicks[i]),0,1 + 30 +30);
  }  
}

void mouseReleased() {
  mouseClicks[currentClickIndex] = mouseY;
  currentClickIndex = currentClickIndex == 9 ? 0 : currentClickIndex + 1;
}
  
  

void keyPressed() {
  if(Character.isDigit(key) && aaa <= 5) {
    currentNumberString += key;
  }
  else if (keyCode == 10 && currentNumberString != "") {
    numbers[currentNumberIndex] = Integer.parseInt(currentNumberString);
    currentNumberIndex = currentNumberIndex == 9 ? 0 : currentNumberIndex + 1;
    currentNumberString = "";
  }
}

void printNumbers(int number1, int number2, int row) {
  textAlign(LEFT, TOP);
  text(Integer.toString(number1), 0, row * 30);
  textAlign(RIGHT, TOP);
  text(Integer.toString(number2), 300, row * 30);
}

int calculateAverage(int[] numbers) {
  int sum = 0;
  for(int i = 0; i < numbers.length; i++) {
    sum += numbers[i];
  }
  return sum / numbers.length;
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 27, 2019, 2:28pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/2 "2019-10-27T14:28:34Z")

</div>

> [@actuallyagod](#):
>
> currentNumberString != “”

This == or != won’t work with String

You need to use equals  
Use

if( ! currentNumberString.equals(“”) )

---

<div class="post-metadata">

**Author:** ![actuallyagod](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@actuallyagod](https://discourse.processing.org/u/actuallyagod)\
**Post date:** [October 27, 2019, 2:37pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/3 "2019-10-27T14:37:53Z")

</div>

Still only gives me this [https://gyazo.com/bdb3fea9db2551d682e3646087ae8839](https://gyazo.com/bdb3fea9db2551d682e3646087ae8839) wher i am supposed to get [https://gyazo.com/d9f0a1921c3eea3fc2fe6c691838be37](https://gyazo.com/d9f0a1921c3eea3fc2fe6c691838be37)  
im really stuck i dont see a way to make this work

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 27, 2019, 2:43pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/4 "2019-10-27T14:43:04Z")

</div>

> [@actuallyagod](#):
>
> printNumbers

Is this function crucial for that what’s missing?

I noticed you pass 0 as y value?

Try 40 instead.

Shouldn’t you have a for loop?

Also get rid of clear for testing this

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 27, 2019, 2:46pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/5 "2019-10-27T14:46:01Z")

</div>

Although not essentially at the moment I noticed you don’t update aaa

You need to set it anew every time

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 27, 2019, 2:48pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/6 "2019-10-27T14:48:32Z")

</div>

> [@actuallyagod](#):
>
> currentNumberString != “”

This appears twice

What’s

> [@actuallyagod](#):
>
> keyCode == 10

again? Return or Enter?

---

<div class="post-metadata">

**Author:** ![actuallyagod](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@actuallyagod](https://discourse.processing.org/u/actuallyagod)\
**Post date:** [October 27, 2019, 2:49pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/7 "2019-10-27T14:49:06Z")

</div>

When removing clear the numbers just stack on top of each other  
setting it to 40 makes everything go black.

keycode 10 is enter

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 27, 2019, 2:53pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/8 "2019-10-27T14:53:05Z")

</div>

So removing clear brought us a step forward: we now know that clear deletes our output (that we want to be permanent) AND that it stacks on top (instead of being underneath each other line by line)

Both points need to be adressed separately by you

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 27, 2019, 2:54pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/9 "2019-10-27T14:54:31Z")

</div>

The first point is that clear deletes where we want to keep it.

Possible solution:

Try set a boolean to true so that you know what and if to display

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 27, 2019, 3:02pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/10 "2019-10-27T15:02:29Z")

</div>

The second point is that you need better lines underneath each other

So in text() have a y value that you increase after every text() like y+=19;

---

<div class="post-metadata">

**Author:** ![actuallyagod](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@actuallyagod](https://discourse.processing.org/u/actuallyagod)\
**Post date:** [October 27, 2019, 3:04pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/11 "2019-10-27T15:04:25Z")

</div>

Why increase after every text?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 27, 2019, 3:17pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/12 "2019-10-27T15:17:16Z")

</div>

I thought you meant you had the text stack on top of each other (instead of having it underneath each other line by line)

If this assumption is correct then you want to increase the y value after each text to avoid this

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 27, 2019, 3:18pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/13 "2019-10-27T15:18:33Z")

</div>

When my assumption was wrong and the columns with the text are just not there you have to make them using a for loop or so

---

<div class="post-metadata">

**Author:** ![actuallyagod](https://avatars.discourse-cdn.com/v4/letter/a/e9bcb4/32.png) [@actuallyagod](https://discourse.processing.org/u/actuallyagod)\
**Post date:** [October 27, 2019, 3:22pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/14 "2019-10-27T15:22:08Z")

</div>

i believe ur assumption was correct. ill give it a shot

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 29, 2019, 3:52pm UTC](https://discourse.processing.org/t/need-help-very-beginner/14964/15 "2019-10-29T15:52:53Z")

</div>

In draw() your main for-loop was wrong:

The x-value must be 150 (because of ` textAlign(RIGHT, TOP);` in printNumbers() - when I use this textAlign, I usually make another ` textAlign(LEFT);` to go back to default after `text()`; I haven’t done this here). You could also say ` textAlign(LEFT);` before the for-loop.

and I inserted i\*30 at y-value of text() so we got a line-feed

```auto
int numbers[] = new int [10];
int currentNumberIndex = 0;
int mouseClicks[] = new int[10];
int currentClickIndex = 0;
String currentNumberString = "";
int aaa = currentNumberString.length();

void setup() {
  size(700, 500);
  background(0);
  fill(255, 105, 180);
  textSize(25);
  textAlign(LEFT, TOP);
}

void draw() {
  clear();
  //translate(55, 50); 
  if (currentNumberString != "") {
    printNumbers(Integer.parseInt(currentNumberString), mouseY, 0);
  } else {
    printNumbers(0, mouseY, 0);
  }

  for (int i = 0; i < numbers.length; i++) {
    text(Integer.toString(numbers[i]) + "" + Integer.toString(mouseClicks[i]), 
      150, 1 + 30 +30 + i * 30); // x-value 150 and I inserted i*30 at y-value !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  }
}

void mouseReleased() {
  mouseClicks[currentClickIndex] = mouseY;
  currentClickIndex = currentClickIndex == 9 ? 0 : currentClickIndex + 1;
}

void keyPressed() {
  if (Character.isDigit(key) && aaa <= 5) {
    currentNumberString += key;
  } else if (keyCode == 10 && currentNumberString != "") {
    numbers[currentNumberIndex] = Integer.parseInt(currentNumberString);
    currentNumberIndex = currentNumberIndex == 9 ? 0 : currentNumberIndex + 1;
    currentNumberString = "";
  }
}

void printNumbers(int number1, int number2, int row) {
  textAlign(LEFT, TOP);
  text(Integer.toString(number1), 0, row * 30);
  textAlign(RIGHT, TOP);
  text(Integer.toString(number2), 300, row * 30);
}

int calculateAverage(int[] numbers) {
  int sum = 0;
  for (int i = 0; i < numbers.length; i++) {
    sum += numbers[i];
  }
  return sum / numbers.length;
}
//

```
