联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2023-06-20 09:19

CS202 Assignment 2

File I/O, ArrayList, Classes and Interface (Comparable)

Due: 11:59pm 05/26/2023(Friday)

In this assignment, you are asked to read from a file “student_hobbies_JU.txt”

which contains your classmates’ names and their hobbies. You will then need to

find out, for each of your hobbies, how many people in your class share the same

hobby with you.

You are given a zipped project folder AS2_ArrayList_FileIO. You will need to

import (导入) this project into your workspace. The project folder includes the

following two important files:

1. “student_hobbies_JU.txt”

This file contains student names and their hobbies. The following example

shows the first several lines of this file.

Your program will be reading from this file and reporting how many of your

classmates share the same hobbies with you. See the following example running

results.

2. AppDriver.java,

This file contains the main() and includes the following four tasks.

• Task 1: create an ArrayList of strings representing a list of your hobbies,

• Task 2: read from a file “student_hobbies.txt” and store the information in the

file into an Arraylist of Student-type object. You will need to create a Student

class for this.

• Task 3: Sort the list of students by ascending order of names.

• Task 4: For each of your hobby, find out how many students in the student

Arraylist share that hobby with you. An example running result is given in

Figure 2.

This AppDriver.java file contains compile errors because of the missing

method definitions, for example, createHobbies(), readFile(), and

findSharedHobbies(). Do not change the main(). Just add definitions of the

above methods to your program. Specifically, create createHobbies() for Task

1, readFile() for Task 2, and findSharedHobbies() for Task 4. For the sorting

inTask 3 to work appropriately, you will need to have the Student class

implement the Comparable interface.

Example running results

Hints

1. Format output:

The following is an example illustrating formatting output. You will need it for task 2

and 3.

public class Main {

public static void main(String[] args) {

String string1 = "Hello";

String string2 = "World";

String string3 = "Java";

System.out.println(String.format("%-10s %-10s %-10s", string1, string2, string3));

}

}

Submission requirements:

1. Submit your zipped project folder. If you use Eclipse, zip up your project folder, for

example, C:\Download\CS202_workspace\FinalProject , not the workspace folder,

for example, C:\Download\CS202_workspace , and submit it to canvas.

2. A screenshot of your running result. (png, jpg, pdf, or docx)

3. Make sure your code is free of compile errors. A project with compile errors in it will earn

you a very low grade.

4. Follow the Java style guide (Files/ASSIGNMENTS/JavaStyleGuide.pdf) and comment

your code whenever necessary.

5. Refer to (Files/AQuickGuide2Eclipse.pdf) for how to import an existing project into

Eclipse, how to open a workspace, etc.

Academic Honesty:

Your code must be your own. Any format of sharing code is not allowed and is considered

plagiarism.


版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp