所以我想要做的是:
写一个User类
用户:
我的代码到目前为止:
public class User{
public String id;
public String userPermissions;
public String actualName;
public User(String username, String userType, String name){
id = username;
userPermissions = userType;
actualName= name;
}
public String getUsername(){
return id;
}
public String getUserType(){
return userPermissions;
}
public String getName(){
return actualName;
}
public enum UserType{
admin, editor, user;
}
public void setUserType(String input){
userPermissions = input;
}
}
Run Code Online (Sandbox Code Playgroud)
我需要做些什么才能让它发挥作用?我不知道如何制作它所以可以选择的唯一用户类型是管理员,编辑者或用户.
我的代码是这样的:
public class Main{
public static void main(String[] args){
WordGroup wordgroupOne= new WordGroup ("You can discover more about a person in an hour of play than in a year of conversation");
WordGroup wordgroupTwo= new WordGroup ( "When you play play hard when you work dont play at all");
String[] quoteOne = wordgroupOne.getWordArray();
String[] quoteTwo = wordgroupTwo.getWordArray();
for (String word : quoteOne){
System.out.println(word);
}
for (String word : quoteTwo){
System.out.println(word);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Wordgroup类:
public class WordGroup {
public String words; …Run Code Online (Sandbox Code Playgroud) public Bee anotherDay(){
flower = garden.findFlower();
int pol = 5;
bool=flower.extractPollen(pol);
if(bool=true){
hive.addPollen(pol);
}else{
++pol;
bool=flower.extractPollen(pol);
if(bool=true){
hive.addPollen(pol);
}else{
++pol; //etc.
}
}
Run Code Online (Sandbox Code Playgroud)
该代码的重点是:
1)use the findFlower() method on garden ot return a flower
2)use the extract pollen method on the flower with 5 as the initial paramater
3)If there isn't 5 pollen in the flower, the method returns false so try again with 4
4)If there isn't 4 try with 3 etc. until 0.
Run Code Online (Sandbox Code Playgroud)
我正在考虑使用for循环,但我不知道如果方法成功并且返回true,如何突破它,所以我不会继续从花中获得5 + 4 + 3 …