Question

In: Computer Science

Homework Assignment 4 Instructions: Class name must be: HW4_yourName For example: Michael will name the class...

Homework Assignment 4 Instructions: Class name must be: HW4_yourName For example: Michael will name the class of homework assignment 4 as HW4_Michael Grading Rubric: Code running and as per the required conditions and giving expected output = 10 points File named as per instructions = 1 point Comments in code = 4 points Problem: Average calculation for a list Write a program that reads a text file named test_scores.txt to read the name of the student and his/her scores for 3 tests. The program should display class average for first test (average of scores of test 1) and average (average of 3 tests) for each student. Expected Output: ['John', '25', '26', '27'] ['Michael', '24', '28', '29'] ['Adelle', '23', '24', '20'] [['John', '25', '26', '27'], ['Michael', '24', '28', '29'], ['Adelle', '23', '24', '20']] Class average for test 1 is: 24.0 Average for student John is 26.00 Average for student Michael is 27.00 Average for student Adelle is 22.33

Solutions

Expert Solution

Note : I saved text file in D drive , you gave to specify the right path for the text file in your PC.

I have used comments so that you can get , full marks

import java.util.*;

import java.io.*;

public class HW4_yourName {

    public static void main(String args[]){

         

        //Getting file from local drive

        File scores = new File("D:\\test_scores.txt");

        FileReader f = new FileReader(scores);

        BufferedReader br = new BufferedReader(f);

        String line;

        String[] test_scores;

        // This while loop reads each line as a string, then split string into words to get test score details

        ArrayList<String> list = new ArrayList<>();

        int test1 =0,test2=0,test3=0;

        int total_students = 0;

        while((line = br.readLine()) != null){

            //Splitting each line in file into words

            test_scores = line.split(" ");

            //storing marks of each test in a varibale for average

            test1 += Integer.parseInt(test_scores[1]);    

            float average = (tInteger.parseInt(est_scores[1])+Integer.parseInt(test_scores[2])+ Integer.parseInt(test_scores[3]))/3 ;

            // storing the string into the list for final printing

            list.add("Average of Student "+test_scores[0] +  "is" + average );

            total_students+=1;

        }

        System.out.println("Class average for test1 is "+test1/total_students);

        //Printing marks for each student

        for(String s: list){

            System.out.println(s);

        }

    }

    

}

HOPE i helped YOU.

Happy Learning.


Related Solutions

Create java class with name MyClass1 Instructions for MyClass1 For this portion of the assignment you...
Create java class with name MyClass1 Instructions for MyClass1 For this portion of the assignment you will need to create a java class of your own to model some objects in the real world or your own imagination. your classes should have at least three instances variables, accessor and mutator methods for each of those instance variables, one constructor method of any type, as well as an overridden toString method that will display every field value as part of a...
Math 473: R Homework #4 Name: Due: Thursday, November 7th at the beginning of class; if...
Math 473: R Homework #4 Name: Due: Thursday, November 7th at the beginning of class; if your homework is submitted at the end of class or later, it will be considered late. Please print this sheet and staple it to the front of your homework. You will not receive any credit for your program if it does not run, if you did not call the program from the R Console window, you call your program more than once from the...
Write a Java class. The class name must be ShapeMetrics, which means the file name must...
Write a Java class. The class name must be ShapeMetrics, which means the file name must be ShapeMetrics.java. Provide the following functions: 1. getAreaOfRectangle(), with two float arguments, width and height, in that order, returning a float value which is the area of the rectangle with that width and height. 2. getSpaceDiagonalOfRectangularCuboid (), with three float arguments, width, height, and depth, in that order, returning a float value which is the length of the diagonal line which bisects the cuboid....
Instructions for this homework assignment are as follows: write a short answer essay in other words,...
Instructions for this homework assignment are as follows: write a short answer essay in other words, please write your answers clearly and ensure that you are fully answering the question, but at the same time, your answers should be concise. A range of approximately 2-4 sentences per question is ideal until you have explained it all. There is no maximum, but again it should be concise. 1. What is an offer and the 7 Ps of the marketing mix? What...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after a Cat. You should have instance variables as follows: The Cat’s name The number of mice caught by the Cat. Whether or not the Cat is secretly plotting to kill you Note that you will need to choose both good types and meaningful identifiers for each of these instance variables. You may also assume that the Cat is not automatically always secretly plotting to...
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after...
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after a BaseballPlayer and will contain methods to calculate various statistics based on the stats of a player. For this class, you will want to use a static variable for storing a DecimalFormat object. See the API document for the BaseballPlayer class for a list of methods you will write. API Document Constructors: Identifier: BaseballPlayer(String name, int number, int singles, int doubles, int triples, int...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods...
Create java Class with name Conversion. Instructions for Conversion class: The Conversion class will contain methods designed to perform simple conversions. Specifically, you will be writing methods to convert temperature between Fahrenheit and Celsius and length between meters and inches and practicing overloading methods. See the API document for the Conversion class for a list of the methods you will write. Also, because all of the methods of the Conversion class will be static, you should ensure that it is...
           Homework: Polynomial Using Array Description: Implement a polynomial class (1) Name your class...
           Homework: Polynomial Using Array Description: Implement a polynomial class (1) Name your class Polynomial (2) Use array of doubles to store the coefficients so that the coefficient for x^k is stored in the location [k] of the array. (3) define the following methods: a. public Polynomial()    POSTCONDITION: Creates a polynomial represents 0 b. public Polynomial(double a0)    POSTCONDITION: Creates a polynomial has a single x^0 term with coefficient a0 c. public Polynomial(Polynomial p)    POSTCONDITION: Creates...
THIS ASSIGNMENT MUST BE DONE IN C++ 17 AND MUST FOLLOW EACH GUIDELINE LISTED BELOW. INSTRUCTIONS...
THIS ASSIGNMENT MUST BE DONE IN C++ 17 AND MUST FOLLOW EACH GUIDELINE LISTED BELOW. INSTRUCTIONS START HERE: Our satisfied clients are back to ask us to implement another interactive dictionary. Our dictionary takes input from users and uses the input as search key to look up values associated with the key. Requirements: - Coding: No hard coding - Data Source: a text file, Data.CS.SFSU.txt - Data Structure: Use existing data structure(s) or create new data structure(s) to store our...
Create a class and name it MyArray. This class must have an internal array of integers...
Create a class and name it MyArray. This class must have an internal array of integers and the consumer should specify the maximum capacity when instantiating. MyArray class must provide following functions: 1- insert: This method receives and integer and inserts into the array. For simplicity you can assume the array is large enough and never overflows. 2- display: This method displays all integers stored in the array in the same order as they are inserted (first in first out)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT