Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) space out the table and separate the columns using spaces, then add a header

ID: 3816008 • Letter: 1

Question

1) space out the table and separate the columns using spaces, then add a header "Name, HW1, HW2, HW3, HW5, HW5, Avg(lowest dropped)" at the beginning of the file. Please left align all the columns. You can check the sample screenshots of the output file to understand the output format at the end. Please note your data file might be different so the output might not be the exactly same.

2) "Ave(lowest dropped)" column contains the average grade of HW after dropping the lowest HW grade among all for each student.

3) At the end of the file, there should be a footer line to indicate number of the students, the average grades of each HW. Save your output as file average_grade

4) Print out all the student names whose average HW grade is below 66. Save it as file_names

5) Save your files using redirections.

Explanation / Answer

You have not specify the language in which I have to solve this problem. So I have solved this in JAVA.

import java.io.*;
import java.lang.*;
import java.util.ArrayList;
import java.util.Scanner;

public class Test{

   static Scanner scan;

public static void main(String []args){
  
       scan = new Scanner(System.in);
      
       System.out.println("Enter number of students : ");
       int total_students = scan.nextInt();
  
       ArrayList<Student> studs = readStudData(total_students);
      
       storeDataToFile(studs);
      
}

   static ArrayList<Student> readStudData(int total_students) {
  
       ArrayList<Student> studs = new ArrayList<Student>();
  
       for(int i=0; i<total_students; i++) {
           System.out.println("Enter student detail : " + (i+1));
           System.out.println("Name : ");
           String name = scan.next();
          
           System.out.println("HW1 : ");
           int hw1 = scan.nextInt();
          
           System.out.println("HW2 : ");
           int hw2 = scan.nextInt();
          
           System.out.println("HW3 : ");
           int hw3 = scan.nextInt();
          
           System.out.println("HW4 : ");
           int hw4 = scan.nextInt();
          
           System.out.println("HW5 : ");
           int hw5 = scan.nextInt();  

           float avg = ((float)(hw1 + hw2 + hw3 + hw4 + hw5)) / 5;
          
           studs.add(new Student(name, hw1, hw2, hw3, hw4, hw5, avg));
       }
      
       return studs;
}
  
   static void storeDataToFile(ArrayList<Student> studs) {
  
       try {
PrintWriter out_grade = new PrintWriter(new FileWriter("average_grade.txt", true));
           PrintWriter out_names = new PrintWriter(new FileWriter("file_names.txt", true));
  
           out_grade.println("Name, HW1, HW2, HW3, HW5, HW5, Avg(lowest dropped)");
          
           int total_hw1 = 0, total_hw2 = 0, total_hw3 = 0, total_hw4 = 0, total_hw5 = 0;
          
           for(int i=0; i<studs.size(); i++) {
          
               total_hw1 += studs.get(i).getHw1();
               total_hw2 += studs.get(i).getHw2();
               total_hw3 += studs.get(i).getHw3();
               total_hw4 += studs.get(i).getHw4();
               total_hw5 += studs.get(i).getHw5();
          
               out_grade.println(studs.get(i).getName() + " " + studs.get(i).getHw1() + " " + studs.get(i).getHw2() + " " + studs.get(i).getHw3() + " " +
                           studs.get(i).getHw4() + " " + studs.get(i).getHw5() + " " + studs.get(i).getAvg());
              
               if(studs.get(i).getAvg() < 66)
                   out_names.println(studs.get(i).getName());
           }
  
           out_grade.println("------------------------------");
           out_grade.println("Total Students : " + studs.size());
           out_grade.println("Avg of HW1 : " + ((float)total_hw1 / studs.size()));
           out_grade.println("Avg of HW2 : " + ((float)total_hw2 / studs.size()));
           out_grade.println("Avg of HW3 : " + ((float)total_hw3 / studs.size()));
           out_grade.println("Avg of HW4 : " + ((float)total_hw4 / studs.size()));
           out_grade.println("Avg of HW5 : " + ((float)total_hw5 / studs.size()));
          
           out_grade.close();
           out_names.close();
} catch (IOException e) {
System.out.print("Error: " + e);
System.exit(1);
}
      
   }
}

// Student model to store information of Student
class Student {

private String name;
   private int hw1, hw2, hw3, hw4, hw5;
   private float avg;
  
public Student() {
}

public Student(String name, int hw1, int hw2, int hw3, int hw4, int hw5, float avg) {
this.name = name;
this.hw1 = hw1;
       this.hw2 = hw2;
       this.hw3 = hw3;
       this.hw4 = hw4;
       this.hw5 = hw5;
this.avg = avg;
}

   public String getName() {
       return name;
   }
  
   public int getHw1() {
       return hw1;
   }
  
   public int getHw2() {
       return hw2;
   }
  
   public int getHw3() {
       return hw3;
   }
  
   public int getHw4() {
       return hw4;
   }
  
   public int getHw5() {
       return hw5;
   }
  
   public float getAvg() {
       return avg;
   }
}