【发布时间】:2018-08-14 02:44:38
【问题描述】:
class newPlanner{
private newAppointment[] Appoint = new newAppointment[20];
newPlanner(){
newAppointment obj1 = new newAppointment("Mar",4,17,30,"Quiz 1");
newAppointment obj2 = new newAppointment("Apr",1,17,30,"Midterm");
newAppointment obj3 = new newAppointment("May",6,17,30,"Quiz 2");
newAppointment obj4 = new newAppointment("Jun",3,17,30,"Final");
Appoint [0] = obj4;
Appoint [1] = obj3;
Appoint [2] = obj2;
Appoint [3] = obj1;
}
public void runMethod(){
boolean answer = true;
while (answer) {
System.out.println("Select an Option. ");
System.out.println(" 1. Add Appointment ");
System.out.println(" 2. List Appointment ");
System.out.println(" 3. Delete Appointment ");
System.out.println(" 4. Exit ");
这是我的代码,我需要创建一个方法来移动数组元素以插入新约会并删除约会。该数组需要按日期排序,我似乎无法得到它请帮助
【问题讨论】:
-
这是什么语言?爪哇?不要使用数组,使用List,然后对其进行Collections.sort。
-
是的 java 我会,但我们必须明确使用数组
-
如果您最终确实需要一个数组,请使用
List.toArray将其转换回来。这看起来像是某种学术编码问题,在现实世界中,没有人会为这种事情使用数组,这就是发明集合 API 的目的。
标签: java arrays object methods