问题描述
我想制作一个Task and Todo程序。我已经在单独的类中编写了代码。 class Task
将代表一个需要完成的项目。
public class Task {
private String task;
private int priority;
private int workload;
public Task(String task,int priority,int workload) {
this.task = task; // Description of the task
this.priority = priority; // 1 = very important,2 = important,3 = unimportant,4 = after learn
// Portuguese
this.workload = workload; // amount of time to complete the task
}
public String getPriority(String translation) {
if (priority == 1) {
translation = "very important";
}
if (priority == 2) {
translation = " important";
}
if (priority == 3) {
translation = "unimportant";
}
if (priority == 4) {
translation = " after learn German";
}
return translation;
}
public String toString() {
String translation = "";
return task + " takes " + workload + " minutes and has priority " + getPriority(translation);
}
}
class Todo
将组织所有任务。
public class Todo {
ArrayList<String> Todo = new ArrayList<>();
public void addTask(String description,int minutes) {
if (priority > 4 || priority < 1) {
System.out.println(description + " has invalid priority ");
}
if (minutes < 0) {
System.out.println(description + " has invalid workload ");
}
Todo.add(Task.class.getName());
}
public void getTodoList() {
Todo.forEach(item->System.out.println(Task.class.getName().toString()));
}
public void print() {
System.out.println("Todo:");
System.out.println("-----");
getTodoList();
if (Todo == null) {
System.out.println("You're all done for today! #TodoZero");
}
}
public static void main(String[] args) {
Task task;
Todo todo;
todo = new Todo();
todo.addTask("Go to gym",2,60);
todo.addTask("Read book",1,45);
todo.print();
System.out.print("");
}
}
输出:
Todo:
-----
Task
Task
但是问题是Todo.print() method
无法打印已添加到Todo中的任务列表。预期的输出应如下所示:
Go to gym takes 60 minutes and has priority important
Read book takes 45 minutes and has priority very important
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)