- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做我的第一个 Java 编程作业,我还有另一个问题。我将 Course[] 放在 Student[] 内,但现在似乎遇到 NullPointerException 错误,我不明白为什么。
public Student[] analyzeData() {
Scanner inputStream = null;
try {
inputStream = new Scanner(new FileInputStream("Programming Assignment 1 Data.txt"));
} catch (FileNotFoundException e) {
System.out.println("File Programming Assignment 1 Data.txt could not be found or opened.");
System.exit(0);
}
int numberOfStudents = inputStream.nextInt();
int tuitionPerHour = inputStream.nextInt();
Student[] students = new Student[numberOfStudents];
for (int i = 0; i < numberOfStudents; i++) {
String firstName = inputStream.next();
String lastName = inputStream.next();
int studentID = inputStream.nextInt();
String isTuitionPaid = inputStream.next();
int numberOfCourses = inputStream.nextInt();
Course[] courses = new Course[numberOfCourses];
for (i = 0; i < numberOfCourses; i++) {
String courseName = inputStream.next();
String courseNumber = inputStream.next();
int creditHours = inputStream.nextInt();
String grade = inputStream.next();
Course currentCourse = new Course(courseName, courseNumber, creditHours, grade);
courses[i] = currentCourse;
}
Student currentStudent = new Student(firstName, lastName, studentID, isTuitionPaid, numberOfCourses, courses);
students[i] = currentStudent;
}
return students;
}
输入文件的格式为:
3 345
Lisa Miller 890238 Y 2
Mathematics MTH345 4 A
Physics PHY357 3 B
Bill Wilton 798324 N 2
English ENG378 3 B
Philosophy PHL534 3 A
其中courses 包含有关类(class)的信息,students 包含有关学生的信息。
最佳答案
文件的自然对象映射将是一个 Student
对象列表,每个对象都包含一个 Course
对象列表。 courses
数组应存储在学生对象内。
关于java - 是否可以通过此方法返回或以某种方式访问 "courses"中的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10987042/
我正在尝试编写查询来建议学生注册哪些类(class)。该查询将选择合适的类(class)并验证 1) 他们已完成的类(class)。以及他们还需要参加哪些类(class) 2) 要完成的先决类(cla
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 9 年前。 Improve th
我的问题与我已经提交的作业有关 - 但我想根据我编码的内容(满足一些要求)找出我失败的地方、我做对的地方以及是否有更好的方法。严重新手要说清楚。 我已经阅读了多个先前提出的问题,并尝试将其中的信息汇总
题目地址: https://leetcode.com/problems/course-schedule/description/ 题目描述: There are a total of n cour
去年我完成了 Spring 的核心类(class)。在那门类(class)中,我收到了一本非常好的书,名为“Core Spring 学生讲座手册”+ 练习册。问题是,经过数小时的痛苦,我仍然无法使示例
我正在做我的第一个 Java 编程作业,我还有另一个问题。我将 Course[] 放在 Student[] 内,但现在似乎遇到 NullPointerException 错误,我不明白为什么。 pub
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我想在 iTunes U 上学习斯坦福大学的 Swift 类(class),但在创建回车键时遇到了困难。只要我在模拟器中按下 enter 键,应用程序就会崩溃,并且没有说明原因。这是代码: impor
如何在不切换程序中提问顺序的情况下做到这一点?在询问类(class)之前,我想了解他们的年龄。但是,一旦输入年龄,程序就会自动继续打印 while/if 语句。 #include #include u
在 C# 中,我填充了一个二进制缓冲区(1.5 到 2 kB),我在 C DLL 中引用了该缓冲区。一切都很顺利(逐步执行 C 是这么说的),直到我必须返回到 C#。在最后一刻,程序崩溃了(没有抛出异
我正在开发一个 ASP.NET MVC5 Web 应用程序。我正在使用 Entity Framework 6 来满足我的数据存储需求。我在启用迁移的情况下使用它的代码优先功能。自动迁移设置为 fals
我需要学习 C 来帮助我的一位教授完成一些实验室工作。我只有大约 2 周的时间来准备。任何人都可以推荐一门好的类(class)/书籍,但最好是厚实而体面的视频类(class)(如麻省理工学院的开放类(
题目地址:https://leetcode-cn.com/problems/course-schedule-iv/ 题目描述 你总共需要上 n 门课,课程编号依次为 0 到 n-1 。 有的课会
题目地址:https://leetcode.com/problems/course-schedule-ii/description/ 题目描述 There are a total of n cou
grok 学习 python 类(class)的一个问题是,“编写一个程序,读取一行文本并向后打印出该行文本。”我写道: word = input('Line: ') for i in range(l
对于我的 java 编程类(class),我正在尝试编写一个程序来判断类是否冲突。到目前为止,我有一个名为 Course 的对象。 public void init将初始化上述所有成员的类(class
我正在使用xcode 11 beta 5开发iPhone应用程序。 但是我发现了类似“类型为[[Course]”的值没有成员'identified”之类的错误 这是我的源代码。 struct Cont
我正在尝试计算每门类(class)的学生数量,但所需的 JOIN 数量让我有点困惑。 表:学生、组和类(class) 学生数量取自group表 SELECT id, SUM(`students qua
我创建了下表。 CREATE TABLE `test` ( `name` VARCHAR(50) NOT NULL, `id` INT(10) NOT NULL AUTO_INCREMENT, PRI
我想在 Django 中为一所在线私立学校设计一个模型。它着重于Students、Tutors 和Courses 之间的关系。 应该考虑的最重要的因素是Students可以添加和Tutors可以创建类
我是一名优秀的程序员,十分优秀!