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

Specification When your program starts, it should print the program title and yo

ID: 3834093 • Letter: S

Question

Specification When your program starts, it should print the program title and your name, then load the file given as a command line argument (similar to the sorting assignment). If no file is given, or if the file does not exist, the program should print a usage message and exit. After loading the input file, the program should go into "command" mode, which allows the user to type in various commands and get results from the system. This is similar to the calculator assignment. You should show some kind of a prompt, such as to the user, and wait for commands. The commands that your system must process are as follows: l. exit Causes the program to exit. 2. help Causes the program to print a list of commands accepted by the system. This same message should be printed if the user types an unrecognized command. The program must not crash in this case. 3. roll Prints out a list of students from the class (first and last name), along with total points, and final grades (A, B, C, D, F) for each student. These should be properly aligned in columns, so that the grades line up above one another, and the student first name and student last name are left aligned. 4. search [partial named

Explanation / Answer

Executable Code:-

package chegg1;

import java.awt.List;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class ProgramSeven {
   public static ArrayList<student> students = new ArrayList<student>();
   public static HashMap<String, Double> assignments = new HashMap<String, Double>();
   public static Scanner keyboard = new Scanner(System.in);

   public static String course = "", section = "";
   public static double total;

   public static void main(String[] args) throws IOException {
       System.out.println("--------------------------------" + " " + "| Grade Stats, by Tanner Heape |" + " "
               + "--------------------------------");
      
       String file = "";

      
       if (args.length > 0) {
           file = args[0];
       }

      
       while (true) {
           File fileI = new File("./" + file);
           if (fileI.exists() && fileI.isFile()) {
               toList(fileI);
               break;
           }
           System.out.print("Enter the file name: ");
           file = keyboard.nextLine();
       }

       while (true) {
           System.out.print(" > ");

          
           ArrayList<String> input = new ArrayList<String>(Arrays.asList(keyboard.nextLine().split(" ")));

           if (input.get(0).equalsIgnoreCase("exit"))
           {
               System.exit(0);
           } else if (input.get(0).equalsIgnoreCase("help"))
           {
               System.out.println(" Accepted commands: " + " exit " + " help " + " students "
                       + " search [partial name] " + " assignments " + " report "
                       + " student [student name] " + " assignment [assignment name]");
           } else if (input.get(0).equalsIgnoreCase("students"))
                                                                  
           {
               System.out.println(" Student Grades for " + course + ", " + section + " "
                       + " Total points possible: " + total + " ");

               System.out.printf(" %-10s %-10s %6s %5s%n ---------- --------- ------ -----%n",
                       "First Name", "Last Name", "Points", "Grade");

               for (student st : students) {
                   System.out.printf(" %-10s %-10s %6.0f %s%n", st.getFirstName(), st.getLastName(),
                           st.getPoints(), st.getLetterGrade());
               }
           } else if (input.get(0).equalsIgnoreCase("search"))
                                                              
           {
               if (input.size() > 1) {
                   String subString = input.get(1);

                   System.out.printf(" %-10s %-10s %6s %5s%n ---------- --------- ------ -----%n",
                           "First Name", "Last Name", "Points", "Grade");

                   for (student st : students) {
                       if (st.getFirstName().toLowerCase().contains(subString.toLowerCase())
                               || st.getLastName().toLowerCase().contains(subString.toLowerCase())) {
                           System.out.printf(" %-10s %-10s %6.0f %s%n", st.getFirstName(), st.getLastName(),
                                   st.getPoints(), st.getLetterGrade());
                       }
                   }
               } else {
                   System.out.println(" Invalid input");
               }
           } else if (input.get(0).equalsIgnoreCase("assignments"))
                                                                      
           {
               System.out.println(" Assignments for " + course + ", " + section + " ");

               System.out.printf(" %-12s %6s%n %-12s %6s%n", "Assignment", "Points", "----------",
                       "------");
               for (String key : assignments.keySet()) {
                   System.out.printf(" %-12s %6.0f%n", key, assignments.get(key));
               }
           } else if (input.get(0).equalsIgnoreCase("student"))
                                                                  
                                                                  
           {
               if (input.size() > 2) {
                   String first = input.get(1);
                   String last = input.get(2);

                   for (student st : students) {
                       if (st.getFirstName().equalsIgnoreCase(first) && st.getLastName().equalsIgnoreCase(last)) {
                           System.out.println(" Grades for " + st.getFirstName() + " " + st.getLastName() + " ");
                           System.out.printf(" %-12s %6s %8s%n %-12s %6s %8s%n", "Assignment", "Points",
                                   "Possible", "----------", "------", "--------");

                           for (String key : assignments.keySet()) {
                               System.out.printf(" %-12s %6.0f %8.0f%n", key, st.getAssignment(key),
                                       assignments.get(key));
                           }
                           System.out.printf(" %-12s %6.0f %8.0f%n%n", "total", st.getNumberGrade(), total);
                           System.out.println(" Final Grade: " + st.getLetterGrade());
                       }
                   }
               } else {
                   System.out.println(" Invalid input");
               }
           } else if (input.get(0).equalsIgnoreCase("assignment"))
                                                                  
                                                                  
                                                                  
           {
               if (input.size() > 1) {
                   String search = "";
                   for (int i = 1; i < input.size(); i++) {
                       if (i == input.size() - 1) {
                           search += input.get(i);
                       } else {
                           search += input.get(i) + " ";
                       }
                   }

                   if (assignments.containsKey(search)) {
                       System.out.println(
                               " " + search + ": " + assignments.get(search) + " points grade breakdown");

                       int a = 0, b = 0, c = 0, d = 0, f = 0;
                       double points = assignments.get(search);
                       for (student st : students) {
                           if (st.getAssignment(search) / points >= 0.90) {
                               a++;
                           } else if (st.getAssignment(search) / points >= 0.80) {
                               b++;
                           } else if (st.getAssignment(search) / points >= 0.70) {
                               c++;
                           } else if (st.getAssignment(search) / points >= 0.60) {
                               d++;
                           } else if (st.getAssignment(search) / points < 0.60) {
                               f++;
                           }
                       }
                       System.out.println(" A: " + a);
                       System.out.println(" B: " + b);
                       System.out.println(" C: " + c);
                       System.out.println(" D: " + d);
                       System.out.println(" F: " + f);

                   } else {
                       System.out.println(" Invalid input");
                   }
               } else {
                   System.out.println(" Invalid input");
               }
           } else if (input.get(0).equalsIgnoreCase("report"))
           {
               System.out.println(" Grade breakdown for " + course + ", " + section);

               int a = 0, b = 0, c = 0, d = 0, f = 0;
               double high = 0, low = 100, average = 0, i = 0;
               for (student st : students) {
                   if (st.getLetterGrade().equals("A")) {
                       a++;
                   } else if (st.getLetterGrade().equals("B")) {
                       b++;
                   } else if (st.getLetterGrade().equals("C")) {
                       c++;
                   } else if (st.getLetterGrade().equals("D")) {
                       d++;
                   } else if (st.getLetterGrade().equals("F")) {
                       f++;
                   }

                   if (st.getNumberGrade() > high) {
                       high = st.getNumberGrade();
                   }
                   if (st.getNumberGrade() < low) {
                       low = st.getNumberGrade();
                   }
                   average += st.getNumberGrade();
                   i++;
               }
               average /= i;

               System.out.println(" Low: " + low + "% High: " + high + "% Avg: " + average + "% ");
               System.out.println(" A: " + a);
               System.out.println(" B: " + b);
               System.out.println(" C: " + c);
               System.out.println(" D: " + d);
               System.out.println(" F: " + f);
           }
       }
   }

  
   public static void toList(File fileI) throws IOException {
      
       Scanner textI = new Scanner(fileI);
       boolean setup = true;
       String[] titles = new String[10];

      
       while (textI.hasNext()) {
           String[] ln = textI.nextLine().split(",");

           if (setup) {
               String[] ln2 = textI.nextLine().split(",");

               course = ln[0];
               section = ln[1];

               for (int i = 2; i < ln2.length; i++) {
                   titles[i] = ln[i];
                   assignments.put(titles[i], Double.parseDouble(ln2[i]));
               }

               for (String key : assignments.keySet()) {
                   total += assignments.get(key);
               }

               setup = false;
           } else {
               HashMap<String, Double> temp = new HashMap<String, Double>();

               for (int i = 2; i <= ln.length - 1; i++) {
                   temp.put(titles[i], Double.parseDouble(ln[i]));
               }

               students.add(new student(ln[0], ln[1], temp, total));
           }
       }
   }
}

package chegg1;

import java.util.HashMap;

public class student {
   private String firstName, lastName, letterGrade;
   private double numberGrade, points;
   private HashMap<String, Double> assignments = new HashMap<String, Double>();

  
   public student(String firstName, String lastName, HashMap<String, Double> assignments, double total) {
       this.firstName = firstName;
       this.lastName = lastName;

       this.assignments = assignments;

       for (String key : this.assignments.keySet()) {
           this.points += this.assignments.get(key);
       }

       this.numberGrade = 100 * (this.points / total);

       if (numberGrade >= 90.0) {
           this.letterGrade = "A";
       } else if (numberGrade >= 80.0) {
           this.letterGrade = "B";
       } else if (numberGrade >= 70.0) {
           this.letterGrade = "C";
       } else if (numberGrade >= 60) {
           this.letterGrade = "D";
       } else {
           this.letterGrade = "F";
       }
   }

  
   public void setFirstName(String firstName) {
       this.firstName = firstName;
   }

   public String getFirstName() {
       return this.firstName;
   }

  
   public void setLastName(String lastName) {
       this.lastName = lastName;
   }

   public String getLastName() {
       return this.lastName;
   }

  
   public void setAssignment(String assignment, double score) {
       assignments.put(assignment, score);
   }

   public Double getAssignment(String assignment) {
       return this.assignments.get(assignment);
   }

  
   public double getNumberGrade() {
       return this.numberGrade;
   }

  
   public String getLetterGrade() {
       return this.letterGrade;
   }

   public double getPoints() {
       return this.points;
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote