我希望制作一个学生姓名和科目的板子,每个学生在每个科目上都有一个等级(或者没有……他可以放弃考试不写,那么他的情况就会是空的)。我想只使用HashMap。我的意思是,它将是这样的:
HashMap<String,HashMap<String,String>> bigBoard =
new HashMap<String,HashMap<String,String>>();
但我认为我没有正确的想法,因为对于每个学科,都会有许多分数(值),所以这是不可能的。我需要为每个学生制作一个地图吗?在他的学科中?但输出的表格将无法排列。你有什么建议吗?
例如,我想要一个类似于以下样式的表格。
Column-Key →
Rowkey↓ Mathematics Physics Finance
Daniel Dolter 1.3 3.7
Micky Mouse 5
Minnie Mouse 1.7 n/a
Dagobert Duck 4.0 1.0
我建议将所有的键和值都作为字符串使用,这样会更简单。
在实现我们的类之后(例如,类名为String2D),我们应该像这样使用它。
public static void main(String[] args) {
String2D map2D = new String2D();
map2D.put("Daniel Doster", "Practical Mathematics", "1.3");
map2D.put("Daniel Doster", "IT Systeme", "3.7");
map2D.put("Micky Mouse", "Finance", "5");
map2D.put("Minnie Mouse", "IT Systeme", "1.7");
map2D.put("Minnie Mouse", "Finance", "n/a");
map2D.put("Dagobert Duck", "Practical Mathematics", "4.0");
map2D.put("Dagobert Duck", "Finance", "1.0");
System.out.println(map2D);
}
将不会出现"HashMap",也不允许使用Arrays。