java - The two Strings don't update, keep returning "?" -


this class file of whole project. i've checked everyother class , found culprit. it's supposed take in city , state parsed in class(so you're left city=dallas , state=tx example) when parameter passed through, don't update private string state , private string city.

i keep getting ?,? output tostring method

    public class address  { private string city; private string state;  public address()     {     city="?";     state="?";     }  public string getcity()     {     return city;     }  public string getstate()     {     return state;     }  public void setstate(string s)     {     //system.out.println(s);     state=s;     //system.out.println(state);     }  public void setcity(string c)     {     city=c;     }  public string tostring()     {     string citystate=city+","+state;     return citystate;     }  } 

tester class

    import java.io.*;     import java.util.*;      public class assignment4     {     public static void main (string[] args)     { // local variables, can accessed anywhere main method   char input1;   string inputinfo = new string();   string line = new string(), line2;   //instantiate bank array   bank[] accounts = new bank[10];   bank bank1 = null;    scanner scan = new scanner(system.in);   int index = 0;   // print menu    printmenu();     // ask user input     {      system.out.println("what action perform?");      line = scan.nextline().trim();      input1 = line.charat(0);      input1 = character.touppercase(input1);       if (line.length() == 1)       {// matches 1 of case statements        switch (input1)         {          case 'a':   //add bank            system.out.print("please enter bank information:\n");            inputinfo = scan.nextline();            bank1 = bankparser.bankparser(inputinfo);            accounts[index] = bank1;            index++;            break;          case 'b':   //display banks            (int i=0; i< index; i++)                     system.out.print(accounts[i].tostring());            break;          case 'q':   //quit            break;          case '?':   //display menu            printmenu();            break;          default:            system.out.print("unknown action\n");            break;         }       }      else       {        system.out.print("unknown action\n");       }     } while (input1 != 'q' || line.length() != 1);   }     /** method printmenu displays menu user**/   public static void printmenu()   {    system.out.print("choice\t\taction\n" +                     "------\t\t------\n" +                     "a\t\tadd bank\n" +                     "b\t\tdisplay banks\n" +                     "q\t\tquit\n" +                     "?\t\tdisplay help\n\n");   }  } 

bank.java class

    public class bank      {     address address=new address();     private string bankname;     private string bankid;     private address bankaddress= new address();      public bank() { bankname="?"; bankid="?";  }      public string getbankname() { return bankname; }      public string getbankid() { return bankid; }      public address getbankaddress() { return bankaddress; }      public void setbankname(string bname) { bankname=bname; }      public void setbankid(string bid) { bankid=bid; }      public void setbankaddress(string city, string state) { address.setcity(city); address.setstate(state); }      public string tostring() { string bankinfo="\nbank name:\t\t"+bankname+"\nbank id: \t\t"+bankid+"\nbank        address:\t\t"+bankaddress+"\n\n"; return bankinfo; }     } 

bankparser.java class

    public class bankparser      { public static bank bankparser(string linetoparse) {     bank bank=new bank();     string delims="[/]+";     string[] primaryparse=linetoparse.split(delims);     bank.setbankname(primaryparse[0]);     bank.setbankid(primaryparse[1]);     string[] secondaryparse=primaryparse[2].split("[,]");     //string city=secondaryparse[0];     //string state=secondaryparse[1];     bank.setbankaddress(secondaryparse[0], secondaryparse[1]);     //system.out.println(secondaryparse[1]);     return bank; }       }   

public void setbankaddress(string city, string state) {     address.setcity(city);     address.setstate(state); } 

here problem, did want do

public void setbankaddress(string city, string state) {     bankaddress.setcity(city);     bankaddress.setstate(state); } 

instead.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -