• Post Reply Bookmark Topic Watch Topic
  • New Topic

help  RSS feed

 
Tthuta Soe
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
help me with this errror


 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On line 17 you have

on line 21 you have

 
Les Morgan
Rancher
Posts: 779
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
deleted it.
 
Tthuta Soe
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:On line 17 you have

on line 21 you have



line 27 got error then
 
Tthuta Soe
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




this is my code now and it got error in line 27
 
Carey Brown
Saloon Keeper
Posts: 3310
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have two incompatible types: double[][] and double[].
A double[][] is an array of arrays of doubles.
When you have a double[][] and get a double[i], what it will return is a double[], not a double.
Your error is actually on line 26. You have aDoubleVar = aDoubleVar + aDoubleArray. These are not compatible types.
To get an individual double value from a double[][] you'll need to specify indexes for both dimensions, as in score[i][j].
Another way you could have done this is to have left line 21 as a double[], and then on line 18 use processScore(scores[0]);
This would work except that you'd only be processing the 1st row of values. You'll have to decide what you want to do to process all rows, perhaps using a loop.
 
Tthuta Soe
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:You have two incompatible types: double[][] and double[].
A double[][] is an array of arrays of doubles.
When you have a double[][] and get a double[i], what it will return is a double[], not a double.
Your error is actually on line 26. You have aDoubleVar = aDoubleVar + aDoubleArray. These are not compatible types.
To get an individual double value from a double[][] you'll need to specify indexes for both dimensions, as in score[i][j].
Another way you could have done this is to have left line 21 as a double[], and then on line 18 use processScore(scores[0]);
This would work except that you'd only be processing the 1st row of values. You'll have to decide what you want to do to process all rows, perhaps using a loop.


Like how? I'm pretty new to this so I might need aliit bit of your help
 
Tthuta Soe
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
actually what im trying to do is this

Write a program to calculate students average test scores and their grades. You may
assume the following data:
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
Cooper 78 81 11 90 73
Gupta 92 83 30 69 87
Blair 23 45 96 38 59
Clark 60 85 45 39 67
Kennedy 77 31 52 74 83
Bronson 93 94 89 77 97
Sunny 79 85 28 93 82
Smith 85 72 49 75 63
Use three arrays: a one-dimensional array to store the student names, a (parallel) twodimensional
array to store the test score, and a parallel one-dimensional array to store
grades. Your program must contain at least the following methods: a method to read
and store data into two arrays, a method to calculate the average test score and grade
and a method to output the results. Have your program also output the class average.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Stop for a while and read once again requirements. Try not to start from coding right away.
Tthuta Soe wrote:Your program must contain at least the following methods: a method to read
and store data into two arrays, a method to calculate the average test score and grade
and a method to output the results.
You have quite a lot of written code, but it is not exactly what you have been asked for. You have one method (apart from the main) processScore(...), even tho the intension of this method is hardly understandable. At least its name does not tell anything.

I'd say start from the very first method (once you get full understanding of task).

1. So, the first task sounds like: read and store data into two arrays.
Question: where do you have those grades initially, somewhere in text file?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tthuta Soe wrote:actually what im trying to do is this
Write a program to calculate students average test scores and their grades. You may
assume the following data:
Johnson 85 83 77 91 76
Aniston 80 90 95 93 48
...

OK, well that looks like character data to me, but you seem to have populated your arrays directly.

Now there's absolutely nothing wrong with that - in fact, at this stage, it may well be the best way to go - but I suspect at some point you may need to add extra logic to convert a file containing lines like the ones above to data in your arrays. But for now, forget about that, and deal with what you've got, which is fine.

Another thing: although Java allows you to write:
  double Scores[][] = ...
DON'T DO IT.

Most Java programmers find it confusing (and people like me wish that the language didn't allow it)). Write:
  double[][] scores = ...
instead - because the type you're defining is a double[][], not a double.

And ALL variable names should start with a LOWERCASE letter.

The other thing to understand (as Carey tried to point out) is that "two-dimensional array" is a misnomer.
There is no such thing as a two-dimensional array in Java; there is only "an array" - and ALL arrays are ONE-dimensional.

However, a Java array can contain anything you like, including another array, so a
  double[][]
is, in fact, a one-dimensional array of double[]'s, NOT a grid of double's.

It can be confusing when you're starting out, because the notation looks like you're defining a 2D array, but you're not.

HIH

Winston
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe this template could be helpful in the later stage as a program structure:
Think is this structure fits your needs, if not - look for the way to amend it. In general, keeping a right structure makes easier to understand your program flow. By looking at lines 8, 9, 10 and 11 you can have a first impression what your program is meant to do. Notice the class name, it also reveals program's intension. Each variable name gives a clue too, what they are meant to store and it is rather important, as makes mostly of the inline comments redundant. Try to spend as much time as needed in order to come up with self revealing class, methods, variables names, it makes your code the way more readable.

Best luck
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know whether anybody has said this, but parallel arrays as you have here are a very poor design design.
Please don't write such long lines; I have broken it so you can see how it ought to be done.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!