• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

2D Array

 
Greenhorn
Posts: 21
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to make this code output the array, make it show min, max, and average for each of the array groups at the bottom of the listed array's and make it put 1 * per 10 behind eacht number (ie 25=**)

Right now it gives out all the arrays by day, and at the bottom it shows "average". The average doesn't work right thoughm I get
"Das durchschnitts Wert für tag 1 beträgt: 6.5
Das durchschnitts Wert für tag 2 beträgt: 9.0
Das durchschnitts Wert für tag 3 beträgt: 10.0
Das durchschnitts Wert für tag 4 beträgt: 0.0" the number at the end is the average.

Could you guys give me some help with that?

Would also be nice if you could give me tips on how to do min/max and the stars =D


 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check carefully the place in your code where you update the total. Are you actually adding together all the values in the array? Or is something else happening?
 
lowercase baba
Posts: 12871
62
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say you have several things here:
1) output the array
2) find the min
3) print the min
4) find the max
5) print the max
6) find the average
7) print the average
8) calculate the number of stars for a given number
9) print some number of stars.

Each and every one of these is independent of the others...Printing the min has no connection at all to how i find the min. Calculating a number of stars has nothing to do with printing some number of stars.

So...pick one of the above, and get it to work. Once you've done that, pick the next, and get it to work. Then, if it makes sense, connect them. it is possible your method to print the min may call the method that finds the min, for example.
 
Marshal
Posts: 69814
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fred, you are slipping. You are supposed to say, “if Campbell were here he would tell you there is no such thing as a 2D array.”

Which is true. That is not a 2D array, but an array of arrays. Which is better; you can change the length of one array (by re‑assigning it) without changing the other elements.
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Fred, you are slipping. You are supposed to say, “if Campbell were here he would tell you there is no such thing as a 2D array.”


Well I'll say it instead: What an almighty surprise to find a thread entitled '2D array' with your name on it as last replier. Posted at 7:41 BST too I notice, so I presume you got up specially to do it.

chris rous wrote:I am trying to make this code output the array, make it show min, max, and average for each of the array groups at the bottom of the listed array's and make it put 1 * per 10 behind eacht number (ie 25=**)


Well, min, max and average sound very much like functions to me, so I'd look at making them methods. If I was writing them, I'd also want to make them as loosely coupled as possible, so that I could use them in other programs/classes if I wanted.

I won't help you with how to write them, but this what their signatures should probably look like:
  • public static final double average(double[] values) { ...
  • public static final int max(double[] values) { ...
  • (I'll leave min() - or minimum() - up to you).

    As for the 4th requirement, you'll have to explain what you mean by "behind each number". Do you mean the results or the values in the arrays? Perhaps if you show us an example it would be clearer.

    Winston
     
    Campbell Ritchie
    Marshal
    Posts: 69814
    277
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    7.41 isn’t that early. At least not on a Thursday.
     
    chris rous
    Greenhorn
    Posts: 21
    Android Eclipse IDE Chrome
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Dennis Deems wrote:Check carefully the place in your code where you update the total. Are you actually adding together all the values in the array? Or is something else happening?



    I just noticed that for the Average all it does is take the first number form each array and divide it by 4.

    Thanks for all the reply's guys, I'll say if they helped or not once I've tried them out.
     
    chris rous
    Greenhorn
    Posts: 21
    Android Eclipse IDE Chrome
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I added an attachment here to show you what the program is supose to do.

    messwerte fuer tag *= measured data for day *
    messwert= measured data
    auswertung fuer tag * = analysis for day*
    durchschnitt = average
    laenge= length

    Right now it looks like (the "messwerte" from the picture aren't the ones I'm useing for my program):

    messwerte für tag: 1
    wert: 25.0
    wert: 26.0
    wert: 29.0
    wert: 35.0
    wert: 45.0
    wert: 55.0
    wert: 97.0
    wert: 110.0
    wert: 150.0
    wert: 160.0
    wert: 180.0
    wert: 201.0
    wert: 222.0
    wert: 200.0
    wert: 190.0
    wert: 189.0
    wert: 180.0
    wert: 154.0
    wert: 120.0
    wert: 92.0
    wert: 80.0
    wert: 44.0
    wert: 33.0
    messwerte für tag: 2
    wert: 35.0
    wert: 36.0
    wert: 38.0
    wert: 39.0
    wert: 35.0
    wert: 55.0
    wert: 65.0
    wert: 107.0
    wert: 120.0
    wert: 160.0
    wert: 177.0
    wert: 192.0
    wert: 224.0
    wert: 234.0
    wert: 220.0
    wert: 199.0
    wert: 179.0
    wert: 177.0
    wert: 144.0
    wert: 120.0
    wert: 90.0
    wert: 77.0
    wert: 45.0
    wert: 30.0
    messwerte für tag: 3
    wert: 7.0
    wert: 40.0
    wert: 42.0
    wert: 45.0
    wert: 51.0
    wert: 59.0
    wert: 67.0
    wert: 110.0
    wert: 0.0
    wert: 150.0
    wert: 190.0
    wert: 209.0
    wert: 232.0
    wert: 245.0
    wert: 250.0
    wert: 249.0
    wert: 240.0
    wert: 230.0
    wert: 208.0
    wert: 180.0
    wert: 160.0
    wert: 110.0
    wert: 89.0
    wert: 70.0
    messwerte für tag: 4
    wert: 0.0
    wert: 0.0
    wert: 0.0
    wert: 0.0
    wert: 0.0
    wert: 0.0
    wert: 0.0
    wert: 0.0
    wert: 0.0
    wert: 0.0
    wert: 0.0
    wert: 0.0
    Das durchschnitts Wert für tag 1 beträgt: 6.5
    Das durchschnitts Wert für tag 2 beträgt: 9.0
    Das durchschnitts Wert für tag 3 beträgt: 10.0
    Das durchschnitts Wert für tag 4 beträgt: 0.0
    1345750110967.jpg
    [Thumbnail for 1345750110967.jpg]
     
    fred rosenberger
    lowercase baba
    Posts: 12871
    62
    Chrome Java Linux
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I think we understand what the program is supposed to do.

    What we don't understand is what - specifically - you need help with. Have you tried any of the suggestions given? If so, what happened? What does your code look like now? Where are you confused or stuck?

    If you are looking for someone to hand you the complete solution, you are in the wrong spot. If you want all the help in the world figuring out how to do it yourself, you need to let us know exactly where you need that help.
     
    Consider Paul's rocket mass heater.
      Bookmark Topic Watch Topic
    • New Topic