• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

2d Array problem gasprices

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A consumer protection group who is concerned about these wild swings in gasoline prices has asked you to write a simple Java program that let them record the prices of gasoline at various stations through the city and then display them in a table format. The group leader sketches out what she would like to see on the displayed data:


Each gasoline station will have an ID number and this will be entered in the first column. The morning price will be entered in the second column, and the Evening Price will be entered in the third column.
MILD VERSION Specifications for GasPrices.java

Your program should do the following:
1) Print a short description to the screen that this program will record gas station ID�s and the morning and evening prices for each gas station.

2) You will store the data in a 2D array called gasPriceArray. The number of columns in the 2D array will be three, but the program will ask the user how many gas stations they will be entering. Use this value to set the number of rows in your 2D array.

3) Your program will then loop and ask the user to enter first the gas station ID, then the morning price, and then the evening price, until you have entered all of the data for your gas stations.



I'm stuck on this please help, I cant seem to display the data, here is my coding so far


[B]
[/B]

it does loop, I think it takes the arrays into memory but cant seem to display it, any help will be much appreciated.


this is the output:

Please enter number of stations:
3
Please enter Station ID:
1001
Please enter morning price:
101.2
Please enter evening price:
103.2
Please enter Station ID:
1002
Please enter morning price:
99.9
Please enter evening price:
100.9
Please enter Station ID:
1003
Please enter morning price:
110.9
Please enter evening price:
15.8
Station ID: [[email protected]
Station ID: [[email protected]
Station ID: [[email protected]



[ January 21, 2008: Message edited by: fuka fuka ]
[ January 21, 2008: Message edited by: fuka fuka ]
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at this line:



Hint: Is the station id really a whole row? Or is it a particular column of a row?

Henry
 
rafeeq khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still can't make it, please can you tell me where should I enter the code you told me.

thanks
 
rafeeq khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
station id is particular column of a row(say first column)
 
rafeeq khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


cant get the station id to show, it shows some garbage
 
Marshal
Posts: 80634
471
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not showing garbage, it's showing something you are unfamiliar with. The bit about [D means that it is an object of type array-of-doubles and the @ is an @ sign and the bit afterwards is the hashCode; if you look in the API for the Object class and find its toString() method specification you find that is what it prints.

What it means is that you have managed to get your hands on the ith array, when you thought you had got the jth member of the ith array.

There is not actually such a thing in Java as a two-dimensional array. Have you read the Java tutorial about arrays (push ctrl-F and look for [][])?

Can't give you any more hints, I am afraid. Henry Wong has already given you a very useful hint.
 
rafeeq khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks guys I appreciate your help very much
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you are confused about 2D array. And I don't see the reason for the second for-loop either ( Unless you want afternoon price or whatever).

 
rafeeq khan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Pine
reply
    Bookmark Topic Watch Topic
  • New Topic