坚持创建java接口
我创建了一个Registry类,用于将学生添加和删除到注册表中,还合并了一个学生类。现在我必须构建一个带有主菜单的界面,其中有4个选项可供选择,包括:;添加学生、删除学生、打印注册表,然后退出。其中,扫描仪将用于解密用户选择的选项 我真的不知道如何去创造这个,我已经给了一个模板来填写,但不能得到我的头周围。此外,由于我的RegistryInterface没有main方法,因此我必须创建一个RegistryApp,我还为它创建了一个模板 任何关于如何创建此界面的帮助/建议都将不胜感激,对不起,我对界面构建完全陌生 注册表接口代码模板:坚持创建java接口,java,interface,Java,Interface,我创建了一个Registry类,用于将学生添加和删除到注册表中,还合并了一个学生类。现在我必须构建一个带有主菜单的界面,其中有4个选项可供选择,包括:;添加学生、删除学生、打印注册表,然后退出。其中,扫描仪将用于解密用户选择的选项 我真的不知道如何去创造这个,我已经给了一个模板来填写,但不能得到我的头周围。此外,由于我的RegistryInterface没有main方法,因此我必须创建一个RegistryApp,我还为它创建了一个模板 任何关于如何创建此界面的帮助/建议都将不胜感激,对不起,我对
import java.util.*;
public class RegistryInterface {
private Registry theRegistry = null;
public RegistryInterface(Registry theRegistry){}
//Displays the main menu and gets valid option from user
public void doMenu()
{
System.out.println("Registry Main Menu");
System.out.println("****************** \n");
System.out.println("1. Add a Student");
System.out.println("2. Delete a Student");
System.out.println("3. Print Registry");
System.out.println("4. Quit");
System.out.println("Select option [1, 2, 3, 4] :>");
}
private void doAddStudent() {}
private void doDeleteStudent() {}
private void doPrintRegistry() {}
}
public class RegistryApp {
public static void main (String[] args)
{
//Create the registry object
Registry theRegistry = new Registry();
//Create an interface
RegistryInterface aRegistryInterface
= new RegistryInterface (theRegistry);
//Display the menu
aRegistryInterface.doMenu();
}
}
RegistryApp代码模板:
import java.util.*;
public class RegistryInterface {
private Registry theRegistry = null;
public RegistryInterface(Registry theRegistry){}
//Displays the main menu and gets valid option from user
public void doMenu()
{
System.out.println("Registry Main Menu");
System.out.println("****************** \n");
System.out.println("1. Add a Student");
System.out.println("2. Delete a Student");
System.out.println("3. Print Registry");
System.out.println("4. Quit");
System.out.println("Select option [1, 2, 3, 4] :>");
}
private void doAddStudent() {}
private void doDeleteStudent() {}
private void doPrintRegistry() {}
}
public class RegistryApp {
public static void main (String[] args)
{
//Create the registry object
Registry theRegistry = new Registry();
//Create an interface
RegistryInterface aRegistryInterface
= new RegistryInterface (theRegistry);
//Display the menu
aRegistryInterface.doMenu();
}
}
您的
RegistryInterface
是一个类,而不是一个接口
- 一个接口必须像这样声明
公共接口
- 它应该只包含要使用的属性和方法的声明,而不应该包含任何实现
- 您必须创建一个类(如
)来实现此接口及其方法RegistryImpl
- 要使用它,您只需要创建接口的实例(如
)RegistryInterface RI=newregistryinterface(R);
public interface RegistryInterface {
//Displays the main menu and gets valid option from user
public void doMenu();
public void doAddStudent();
public void doDeleteStudent();
public void doPrintRegistry();
}
注册处:
public class Registy implements RegistryInterface {
//java will force you to write methods the same as the ones declared in
//RegistryInterface...
}
主要类别:
public static void main (String[] args)
{
//Create the registry object
RegistryInterface theRegistry = new Registry();
//Display the menu
theRegistry.doMenu();
//etc...
}类与接口不是一回事。你确定它不应该是
公共界面注册表界面
?我们的讲师通过界面为我们提供了这个模板,你是说GUI吗?只要有System.out.println()
语句以及您想要提供的不同选项就可以了。好像你已经有了。使用Scanner
对象进行用户输入。我很确定他指的是GUI,因为他谈论的是菜单和菜单选项。是的,我想你可能是对的,在我的作业中,它只是指一个界面。好的,当我将其更改为公共界面时,在我将方法设置为private的每一行中都会抛出错误消息,这是为什么?@JoePerkins接口就是要实现的。你不能也不应该在那里有一个私有方法。看看输出,他正在那里打印命令行内容。Swing与命令行用户界面无关。