How do I use or create a variable of a private class in Java -
i'm creating inventory system(doing fun) , have chose use queues data structure in java. use private class within public class , when i'm trying run test queue can't declare variable of private class. here's code
the class contains private class
public class customer {//begining of class private class custque //creating private class use node { private int trn; private string lname; private string fname; private string mname; private string mstatus; private string dob; private string email; private string permanentadd; private string mailingadd; custque next; public custque()//default constructor { trn=0; lname=""; fname=""; mname=""; mstatus=""; dob=""; email=""; permanentadd=""; mailingadd=""; this.next= next; } public custque(int t, string ln, string fn,string mn, string ms, string dob, string email, string pa, string ma)//primary constructor { trn=t; lname=ln; fname=fn; mname=mn; mstatus=ms; dob=dob; email=email; permanentadd=pa; mailingadd=ma; } public void settrn(int t)//trn setter { this.trn= t; } public int gettrn() // trn getter { return trn; } public void setlname(string ln) { this.lname=ln; } public string getlname() { return lname; } public void setfname(string fn) { this.fname=fn; } public string getfname() { return fname; } public void setmname(string mn) { this.mname=mn; } public string getmname() { return mname; } public void setmstatus(string ms) { this.mstatus=ms; } public string getmstatus() { return mstatus; } public void setdob(string dob) { this.dob=dob; } public string getdob() { return dob; } public void setemail(string email) { this.email=email; } public string getemail() { return email; } public void setpermanentadd(string pa) { this.permanentadd=pa; } public string getpermanentadd() { return permanentadd; } public void setmailingadd(string ma) { this.mailingadd=ma; } public string getmailingadd() { return mailingadd; } }// end of private class private custque front; private custque last; public void enqueue (int trn, string ln, string fn, string mn, string ms,string dob,string email,string pa, string ma) { custque que = new custque();// creating variable queue null if (que.equals(null))// testing if queue null system.out.println("an error has occur"); que.settrn(trn); que.setlname(ln); que.setfname(fn); que.setmname(mn); que.setmstatus(ms); que.setdob(dob); que.setemail(email); que.setpermanentadd(pa); que.setmailingadd(ma); if(front.equals(null)) last=front=que; else last.next = que; last = que; }// end of enqueue public custque dequeue() { if (front.equals(null)) { system.out.printf("queue empty"); return null; } custque i; i=front; front = front.next; return front ; }// end of dequeue void display() { custque d; if(front != null) { d=front; system.out.printf("" + d); } } }//end of main class
my driver class
import java.util.scanner; public class driver { public static void main(string[] args) { int t,i; string ln,fn,mn,ms,dob,email,pa,ma; custque s;/* line of error*/ for(i=0; i<5;i++) { system.out.printf(""); scanner num = new scanner(system.in); t= num.nextint(); system.out.printf(""); scanner l = new scanner(system.in); ln = l.nextline(); system.out.printf(""); scanner f = new scanner(system.in); fn = f.nextline(); system.out.printf(""); scanner m = new scanner(system.in); mn = m.nextline(); system.out.printf(""); scanner mar = new scanner(system.in); ms = mar.nextline(); system.out.printf(""); scanner d = new scanner(system.in); dob = d.nextline(); system.out.printf(""); scanner e = new scanner(system.in); email = e.nextline(); system.out.printf(""); scanner per = new scanner(system.in); pa = per.nextline(); system.out.printf(""); scanner mai = new scanner(system.in); ma = mai.nextline(); }// end of loop } }//end of driver
a private inner class means can access inside outer class, in case customer. in fact, if declaring private inner class saying: "i want nobody can see class". going against 1 code.
but, @hovercraft full of eels says, requiremnt behind this. maybe can more. or it's doubt java semantics?
Comments
Post a Comment