Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to import my own class into another class
    text
    copied!<p>I am coding in blueJ. My objectives are this: 1)Write a User class</p> <p>A User:</p> <pre><code>has a username e.g 'fj3' has a userType which can be: 'user', 'editor' or 'admin' has a name e.g 'Francis' has a constructor which takes the username, userType and name as parameters has a getUsername() method has a getUserType() method has a getName() method has a setUserType() method which takes one of the user types as a parameter </code></pre> <p>2)Write a UserGroup class</p> <p>-The UserGroup class must have an ArrayList of Users.</p> <p>Write a constructor for the UserGroup class. It should instantiate the ArrayList. </p> <p>In UserGroup write a method called .addSampleData() which creates 10 Users and using the ArrayList's add() method put the 10 new User objects into the ArrayList. </p> <p>In UserGroup write a getUser method which takes an int as a parameter and returns the User in that slot of the ArrayList. </p> <p>In UserGroup write a printUsernames() method in UserGroup:</p> <p>Using an enhanced for loop (see above), loop through the ArrayList and print the username and userType of each user in the ArrayList. </p> <p>What I have so far is: </p> <pre><code>package user; public class User{ public enum UserType{ ADMIN, EDITOR, USER; } private String id; private UserType userPermissions; private String actualName; public User(String username, UserType userType, String name){ id = username; userPermissions = userType; actualName= name; } public String getUsername(){ return id; } public UserType getUserType(){ return userPermissions; } public String getName(){ return actualName; } public void setUserType(UserType input){ userPermissions = input; } } </code></pre> <p>And my UserGroup class:</p> <pre><code>package user; import java.util.*; import user.User.UserType; public class UserGroup{ private ArrayList&lt;User&gt; people; public UserGroup(){ people = new Arraylist&lt;User&gt;(); } public static void addSampleData(String username, UserType userType, String name){ People.add(new User(username, userType,name)); } public String getUser(int list){ return User; } public void printUsernames(){ for (User user: groupArray){ System.out.printf("%s %s\n", user.getUsername(), user.getuserType); } } } </code></pre> <p>This is obviously far from being complete but I am completely stuck. My first problem is that "for (User user : groupArray)" is giving me the error illegal start of type. Please help me with this!! I think my User class is fine but my UserGroup class is nowhere enar completing all the objectives and I don't know how to do them!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload