java - How to change the value of a user within an array list whilst using an if statement? -


so stuck on 1 final part of assignment, have created 2 array lists. 1 array list lists users within user group , other lists administrators within user group. have been asked change value of last administrator within second array list , set usertype user instead of administrator. i've tried using if statement i'm not sure on how structure it. post have tried date:

mian class

package test;  public class main{      public static void main(string[] args) {          usergroup2 usergroupobject2 = new usergroup2();          //once method complete, should called here.         }           }          } 

usergroup2 class

    package main;     import java.util.arraylist;     import java.util.iterator;        public class usergroup2 {      private arraylist<user> administrators = new arraylist<>();      public usergroup2() {       adduser(new user("hpf1g17", "admin", "harry"));       adduser(new user("bdh1285", "admin", "bob"));     }      public void adduser(user inuser) {       this.administrators.add(inuser);     }      public arraylist<user> getuseriterator() {         return administrators;     }  //this have tried far isn't workng     public void setusertype()  {         iterator<user> = administrators.iterator();             while (it.hasnext()) {             user xxx = it.next();              if (xxx.getusername().equals("bdh1285")) {                 xxx.usertype = "student";             }         }     }     }      

user class

package main;  public class user {    private string username;   private string usertype;   private string name;    user(string username, string usertype, string name) {     this.username = username;     this.usertype = usertype;     this.name = name;   }    public string getusername() {     return username;   }    public string getusertype() {     return usertype;   }    public string getname() {     return name;   }     public string setusertype(string admin) {     return usertype = admin;   }    @override   public string tostring() {     return username + " " + usertype;   }     }   

any appreciated.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -