arrays - Outputs how many times you input -
my goal output amount of how many times filled up. ex: filled 3 students, program should output 3 students too. need simple loop , array. hope me. i've been struggling analyzing put forloop.
public static void main(string[] args) { nso = new nso (); int[]loop=new int[2]; string[]ask={"sure","not now"}; a.setname(joptionpane.showinputdialog("enter name: ")); a.setgender(joptionpane.showinputdialog("enter gender: ")); a.setaddress(joptionpane.showinputdialog("enter address: ")); a.setcourse(joptionpane.showinputdialog("enter course: ")); a.setage(integer.parseint(joptionpane.showinputdialog("enter age: "))); a.setbday(integer.parseint(joptionpane.showinputdialog("enter birth date: "))); int tanong=0; while(tanong==joptionpane.yes_option){ tanong = joptionpane.showoptiondialog(null,"do want input student?",null,joptionpane.yes_no_option, joptionpane.question_message,null,ask,ask[0]); while(tanong==joptionpane.yes_option){ a.setname(joptionpane.showinputdialog("enter name: ")); a.setgender(joptionpane.showinputdialog("enter gender: ")); a.setaddress(joptionpane.showinputdialog("enter address: ")); a.setcourse(joptionpane.showinputdialog("enter course: ")); a.setage(integer.parseint(joptionpane.showinputdialog("enter age: "))); a.setbday(integer.parseint(joptionpane.showinputdialog("enter birth date: ")));break; } } while(tanong==joptionpane.no_option){ joptionpane.showmessagedialog(null,"\nname: " + a.getname() +"\ngender: " + a.getgender() +"\naddress: " + a.getaddress() +"\ncourse: " + a.getcourse() +"\nage: " + a.getage() +"\nbirth date: " + a.getbday());break; } } }
this give example on how it.
final int maxsize = 3; nso a[] = new ns0[maxsize]; // loop input (int = 0; < maxsize; i++) { a[i].setnames(joptionpane.showinputdialog("enter name: ")); a[i].setgender.... etc. } // loop output (int j = 0; j < maxsize; j++) { joptionpane.showmessagedialog(null, "\name" + a[j].getname(), ) // , on.. } // alternative output enhanced loop (nso tmp : a) { joptionpane.showmessagedialog(null, "\name" + a.getname(), ) // , on.. }
by creating array of nso object able access within loop. hope got idea on how adjust source code. luck , have fun programing.
Comments
Post a Comment