Note that there are some explanatory texts on larger screens.

plurals
  1. POArray output problems?
    primarykey
    data
    text
    <p>Hello StackOverflow Community,</p> <p>I am having a problem with some output involving adding elements into an array. I had created a program in class and it ran properly but when I run the same program/code on my own computer, I get the following output (sometimes, different numbers/errors are generated): </p> <p>"The toys:</p> <p>toysdemo.ToysDemo@15f5897toysdemo.ToysDemo@b162d5"</p> <p>To make it more clear, here is the code:</p> <pre><code>package toysdemo; public class ToysDemo { private float price; private String name; public float getPrice(){ return price; } public void setPrice(float newPrice){ price = newPrice; } public String getName() { return name; } public void setName(String newName) { name = newName; } public static void printToys(ToysDemo arrayOfToys[], int size) { //display content of array System.out.println("The toys: "); for (int i = 0; i &lt; size; i++) { System.out.print(arrayOfToys[i]); } System.out.println(); }//print toys public static void main(String[] args) { ToysDemo arrayOfToys[] = new ToysDemo[5]; int numberOfToys = 0; // create two toys and save into array ToysDemo toy = new ToysDemo(); toy.setPrice((float)111.99); toy.setName("Giant Squid"); arrayOfToys[numberOfToys++] = toy; ToysDemo toy2 = new ToysDemo(); toy2.setPrice((float)21.99); toy2.setName("small Squid"); arrayOfToys[numberOfToys++] = toy2; //print toys into array printToys(arrayOfToys, numberOfToys); //the call } } </code></pre> <p>It is a real simple program but it's frustrating on how the correct output will not display.</p> <p>I would really appreciate it if anyone can help me figure out this dilemma. </p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload