This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
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
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: [D@1a758cb103.2 Station ID: [D@1b67f74100.9 Station ID: [D@69b33215.8
[ January 21, 2008: Message edited by: fuka fuka ] [ January 21, 2008: Message edited by: fuka fuka ]
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.