Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program 3 which is to modify: package assignment1; import java.util.ArrayList; import java.util.Scanner; import java.text.DecimalFormat; /** * A class created to store the information about the

Program 3 which is to modify:

package assignment1; import java.util.ArrayList; import java.util.Scanner; import java.text.DecimalFormat; /** * A class created to store the information about the student: its first and last name and his test scores. * * @author Ahsan Shakeel */ public class Student { String firstName; //first name of the student String lastName; // last name of the student ArrayList testscores = new ArrayList(); // using ArrayList for storing the marks of the students /** Default Constructor for a Student object that sets the first and last name of the student to "unknown" */ Student() { this.firstName = "unknown"; this.lastName = "unknown"; } /** Constructor for a Student object that stores first and last name of the student. @param firstName the first name of the Student object @param lastName the last name of the Student object */ Student(String firstName, String lastName) { this.firstName = firstName; this.lastName = lastName; } /** * This method takes a {@code String} * and sets the first name of the Student object in the Student class * * @param firstName * first name of the Student object */ public void setFirstName(String firstName) { this.firstName = firstName; } /** * This method takes a {@code String} * and sets the last name of the Student object in the Student class * * @param lastName * last name of the Student object */ public void setlastName(String lastName) { this.lastName = lastName; } /** * This method combines the first and last of the Student object * * @return the full name of the Student object */ public String getFullName() { return firstName +","+ lastName; }

/** * This method calculates the average of the test scores of the students * * @return the average of the test scores */ public float getAverage() { float sum = 0; for(int i = 0; i

/** * This method calculates number of tests that a Student object has attempted * * @return the number of tests that a Student object has attempted */ public int getTestCount() { return testscores.size(); } public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a student's data on a single line and press return:"); String data = input.nextLine(); String[] pieces = data.split(" "); Student obj = new Student(pieces[0], pieces[1]); for (int i = 2; i

image text in transcribed

image text in transcribed

This is an individual homework grade. The assignment is to modify program 3 to read in a list of students. PROGRAM REQUIREMENTS Prompt the user for the name of an input text data file. Open the file and read one student's data per line. Store all of the students in an ArrayList of student objects. ADDITIONAL INFORMATION - An example execution is shown below. Your code should work for any number of test grades entered on the line. And any number of students in the data file. - An example file for the sample shown is given at the end of this assignment document. - I will enter the full path name for the input file. - You may assume all of the data in the input file is valid. There are no data errors. Example execution on command line window, user input is show in green. Enter a the name of the input data file: C:|temp|in1.txt The student list from the data file contains 3 student entries The students are: Allen, Beth has 3 grades and an average of 100.0 Smith, John has 2 grades and an average of 87.0 Jones, Bob has 5 grades and an average of 69.6 One Example Input File: Beth Allen 100100100 John Smith 9876 Bob Jones 65658974

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions