Hi when i create a new object of class Customer it displays the error Object has never been assigned a value.
import java.util.; //import ou.; /** Write a description of class Customer here. @author (your name) @version (a version number or a date) */ public class Customer { // instance variables - replace the example below with your own private int age; private String gender;
/** Constructor for objects of class Customer / public Customer() { // initialise instance variables super(); age = this.genAge(); gender = this.genCustGender(); }
/** Method that genarates the age of the clients. / public int genAge() { Random rand = new Random(); int n = rand.nextInt(100) + 5; //50 is the maximum and the 1 is our minimum ] return n; }
/** Getter Method that returns the number of age. / public int getAge() { int custAge = age; return custAge; }
/** Method that genarates a gender. / public String genCustGender() {
List genGender = new ArrayList(); genGender.add("Male"); genGender.add("Female");
//System.out.println(genGender);
Random randGen = new Random();
int x = randGen.nextInt(genGender.size()) + 0;
String genderAllocation = genGender.get(x);
return genderAllocation;
}
/** Method that genarates the age of the clients. / public void printCustAttr() { System.out.println(genCustGender()+ " " + getAge()); }
/** Creates and returns a new SchoolCoord object. Reads in the state of the object from the file School.data; if there is no such file, returns the object in its initial state. @return a new SchoolCoord object / public Customer getCustomerObject() { Customer aCustomer = new Customer(); return aCustomer; } }
Answer by AlexSklikas · Apr 15, 2017 at 08:00 AM
mport java.util.; //import ou.; /** Write a description of class Customer here. @author (your name) @version (a version number or a date) */ public class Customer { // instance variables - replace the example below with your own private int age; private String gender;
/** Constructor for objects of class Customer / public Customer() { // initialise instance variables super(); age = this.genAge(); gender = this.genCustGender(); }
/** Method that genarates the age of the clients. / public int genAge() { Random rand = new Random(); int n = rand.nextInt(100) + 5; //50 is the maximum and the 1 is our minimum ] return n; }
/** Getter Method that returns the number of age. / public int getAge() { int custAge = age; return custAge; }
/** Method that genarates a gender. / public String genCustGender() {
List genGender = new ArrayList(); genGender.add("Male"); genGender.add("Female");
//System.out.println(genGender);
Random randGen = new Random();
int x = randGen.nextInt(genGender.size()) + 0;
String genderAllocation = genGender.get(x);
return genderAllocation;
}
/** Method that genarates the age of the clients. / public void printCustAttr() { System.out.println(genCustGender()+ " " + getAge()); }
/** Creates and returns a new SchoolCoord object. Reads in the state of the object from the file School.data; if there is no such file, returns the object in its initial state. @return a new SchoolCoord object / public Customer getCustomerObject() { Customer aCustomer = new Customer(); return aCustomer; } }