我正在尝试为在线购物中心系统创建一个管理功能,该功能允许管理员管理经理个人资料。
package onlineshopping;
/**
*
* @author mammo
*/
public class Admin {
private String adminName;
public Admin(String adminName) {
this.adminName = adminName;
}
public String getAdminName() {
return adminName;
}
public void setAdminName(String adminName) {
this.adminName = adminName;
}
}
public String srhMgr(char mgrid, String mgrname)
{
public class Admin extends public class
{
private String mgrName = "";
}
}
但是,我似乎无法将其与搜索管理器(srhMgr)功能连接。是我使用的方法不正确吗?
答案 0 :(得分:0)
在没有更多关于如何实现搜索管理器(srhMgr)功能的信息或细节的情况下,使用Admin
对象数组的幼稚实现可能有助于说明将Admin
类连接到您的srhMgr
函数。
package onlineshopping;
class Admin {
private String adminName;
private char mgrid;
public Admin(String adminName, char mgrid) {
this.adminName = adminName;
this.mgrid = mgrid;
}
public String getAdminName() {
return adminName;
}
public void setAdminName(String adminName) {
this.adminName = adminName;
}
public char getMgrId() {
return this.mgrid;
}
}
public class AdminTest{
public static Admin[] managers;
public static void main(String args[]){
Admin boss = new Admin("Carl Cracker", 'a');
managers = new Admin[3];
// fill the managers array with Admin objects
managers[0] = boss;
managers[1] = new Admin("Harry Hacker", 'b');
managers[2] = new Admin("Tommy Tester", 'c');
String srh1 = srhMgr('x', "Cautious Clay");
System.out.println(srh1);
String srh2 = srhMgr('a', "Carl Cracker");
System.out.println(srh2);
}
public static String srhMgr(char mgrid, String mgrname)
{
String SearchResult = "";
for (Admin a : managers){
if ((a.getMgrId() == mgrid) && a.getAdminName().equals(mgrname)) {
SearchResult = a.getAdminName() + " IS FOUND in Search";
break;
}
else{
SearchResult = mgrname + " NOT found in search";
}
}
return SearchResult;
}
}
输出:
Cautious Clay NOT found in search
Carl Cracker IS FOUND in Search
还有许多其他更好的方法,但这有望帮助您前进。