java - how do I print out one element from an object array -
i trying print out 1 object array of objects, array contains 5 objects , asking how print 1 of objects example store[1]?
public static void main(string args[]){ customer[] store = new customer[5]; customer c = new customer(1, "szabi", "master"); console console = new console(); store[0] = new customer(1, "szabi", "finchley"); store[1] = new customer(2,"anca", "finchley") ; store[2] = new customer (3, "deniz","cricklewood"); store[3] = new customer(4,"suzanna", "cricklewood") ; store[4] = new customer (5, "lavinia", "ealing"); //how print out store[0] or store[1]? }
i having trouble print out @ index example store[1] or store[0] print out value @ store[4], no matter put in square brackets. customer class follows:
package eldorado; import java.util.arrays; public class customer implements customeritem , comparable<customer> { static int id; static string name; static string address; public customer(){ id=0; name=null; address=null; } public customer(int _id, string _name, string _address){ this.id=_id; this.name=_name; this.address=_address; } public void setid(int _id){ this.id=_id; } public void setname(string _name){ this.name=_name; } public void setaddress(string _address){ this.address=_address; } @override public int getid(){ return id; }@override public string getname(){ return name; }@override public string getaddress(){ return address; }@override public boolean equals(customeritem other){ customer = new customer(); customer b = new customer(); if(a.compareto(b)==0){ return true; }else{ return false; } }@override public int compareto(customer that){ if(this.id==that.id&&this.name==that.name&&this.address==that.address){ return 0; }else if(this.id>that.id){ return 1; }else{ return -1; } } @override public string tostring(){ return integer.tostring(getid())+getname()+getaddress(); } }
use system.out.println(store[0]);
should override tostring
method print want object, default method, inherited object
class doesn't print useful information application, imagine.
Comments
Post a Comment