Wednesday 15 August 2012

java - how to make more than condition in toString method -


I want to list all names that end with "red" and I want to ignore the sensitivity of the case, I have the bottom string method, but it will not print anything.

  Public class customer {public static zero main (string [] args throws IOException {file = a new file ("customer.txt"); Fiver V = New Firator (A); Buffed Vector B = New Baffed Vitter (V); Print Vitter P = new printrover (B); Human eman = new person ("Imaan", 5000); Mannour = new person ("Noor", 3500); Human Redah = New Person ("Redah", 0); Human Belief = New Person ("Imaan", 200); Human Mohamed Raid = new person ("Mohamedreda", 3000); Human Mohamed_Reda = new person ("Mohamed Reda", 2000); Human [] H = new person [6]; H [0] = belief; H [1] = noor; H [2] = redhat; H [3] = believe; H [4] = Mohamed Raida; H [5] = Mohamed_Dardah; P.println (believe); P.println (noor); P.println (Redah); P.println (believe); P.println (MohamedREDA); P.println (Mohamed_Redah); P.flush (); }} Class Human {public string name; Public double balance; Public Human (String N, Double B) {this.balance = b; This.name = n; } @ Override public string to string () (if (NamekequalsIgnoreCase ( 'Reda ") & Amp; Amp; Amp; Amp; (NamekequalsIgnoreCase (' Reda"))) {return name + "" + remainder;} And return "";}}    

please toString method Avoid betting condition. Remove the condition

  public string toString () {return name + "" + balance;}   

and clients < Change your logic in / code> class

  human [] H = new person [6]; [0] = iman; j [1] = noor; h [2] = redhat; H [3] = iman; h [4] = Mohamed Reda; h [5] = mo For Mmd_redah; (int i = 0; i & lt; h.length; i ++) {if (h [i] .name.toLowerCase (). EndsWith ( "reda")) {// Position on p. not println (h [i]);}}   

and copy the lines of loops using code. everywhere you are writing manually line .

Check and use the methods required to add a condition.

No comments:

Post a Comment