158    CMPG 211 1-1 V 2021     Expand All Next Week 6Practical: Objects, Arrays & Text files Main page content           Objects, Arrays and Text files - Week 6                 Resources   Textbook: Laing, Chapter 10 & 12               Understand Java   Read Par 10.6 on Array as instance field (p. 376) Read Par 12.10 and Par 12.11 on the File class (pp. 473 - 476) Read Par 10.10 on the String class and using the split method (p. 387) Read Par 12.1 - 12.6 on Exception handling (pp. 450 - 467) Task 1Click to expand Task 2 - AssignmentClick to collapse             Task 2 - Assignment   Write a Java program called Process marks (using files).  The program must read the marks of students from a text file and process the marks.  The results must be saved in a text file called result. 2.1  Write a Student class with the following instance fields: Name of student arrMarks (integer) // 4 marks out of 100 The class must contain a parameterised constructor and get methods for the two instance fields.  Write a method called calcAve() to calculate and return the average mark.  Write a method called didPass() to determine whether the student passes the module with an average of at least 50%.  Return the word Pass or Fail.  Write a toString() method to construct and return the following string of student data:      Name of student             4 marks      Peter Sampson               40  50  40  30 2.2  Create a text file called marks.  Save the text file in the project folder. Example of the content:       Peter Sampson#40#50#40#30       Diane Wilson#78#89#66#55       James Dube#87#98#78#88 2.3  Create a class called FileMethods. Write a readFile method to read the data from the marks text file into an array of Student objects. Write a writeFile method to write the name of the student, the student's average mark, and whether they pass the module or not to the text file called result. Example of text file content:                           Peter Samson        40       Fail Write get methods (accessors) for the array of objects and the counter variable.  2.4  Write a test class to call the methods.  Write a static displayData() method to display the content of the array. Example of output:       List of students       Name                  Marks              Ave        Result       Peter Sampson        40  50  40  30      40         Fail

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

.

158 
  •  
CMPG 211 1-1 V 2021

 

 
Expand All Next
Week 6Practical: Objects, Arrays & Text files

Main page content

 

 
 
 

 

Objects, Arrays and Text files - Week 6

 

 

 
 
 
     

Resources

 

Textbook: Laing, Chapter 10 & 12

 

 
 
 
     

Understand Java

 
  • Read Par 10.6 on Array as instance field (p. 376)
  • Read Par 12.10 and Par 12.11 on the File class (pp. 473 - 476)
  • Read Par 10.10 on the String class and using the split method (p. 387)
  • Read Par 12.1 - 12.6 on Exception handling (pp. 450 - 467)

Task 1Click to expand

Task 2 - AssignmentClick to collapse

 
 
 
     

Task 2 - Assignment

 

Write a Java program called Process marks (using files).  The program must read the marks of students from a text file and process the marks.  The results must be saved in a text file called result.

2.1  Write a Student class with the following instance fields:

  • Name of student
  • arrMarks (integer) // 4 marks out of 100

The class must contain a parameterised constructor and get methods for the two instance fields. 

Write a method called calcAve() to calculate and return the average mark. 

Write a method called didPass() to determine whether the student passes the module with an average of at least 50%.  Return the word Pass or Fail. 

Write a toString() method to construct and return the following string of student data:

     Name of student             4 marks

     Peter Sampson               40  50  40  30

2.2  Create a text file called marks.  Save the text file in the project folder.

  • Example of the content:

      Peter Sampson#40#50#40#30

      Diane Wilson#78#89#66#55

      James Dube#87#98#78#88

2.3  Create a class called FileMethods.

  • Write a readFile method to read the data from the marks text file into an array of Student objects.
  • Write a writeFile method to write the name of the student, the student's average mark, and whether they pass the module or not to the text file called result.
    • Example of text file content:

                          Peter Samson        40       Fail

  • Write get methods (accessors) for the array of objects and the counter variable. 

2.4  Write a test class to call the methods.  Write a static displayData() method to display the content of the array.

  • Example of output:

      List of students

      Name                  Marks              Ave        Result

      Peter Sampson        40  50  40  30      40         Fail

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education