• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by AlexSklikas · Apr 15, 2017 at 07:59 AM · variable

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; } }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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; } }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

100 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Assigning variables depending on other variables 1 Answer

Way of Finding/accessing a variable from another script though another variable? 1 Answer

Only plus one to variable in other script 1 Answer

Error CS1612 1 Answer

UNET - syncvars 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges