Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Assignemnets.java
- abstract public class Assignment {
- String assignmentName;
- int section , essay1 ,test1 , essay2 , test2 , finalGrade;
- System.outprintln("Program 7: Class Stats by Alexandra Ott.")
- public String getAssignmentName() {
- return assignmentName;
- }
- public void setAssignmentName(String assignmentName) {
- this.assignmentName = assignmentName;
- }
- public int getSection() {
- return section;
- }
- public void setSection(int section) {
- this.section = section;
- }
- public int getEssay1() {
- return essay1;
- }
- public void setEssay1(int essay1) {
- this.essay1 = essay1;
- }
- public int getTest1() {
- return test1;
- }
- public void setTest1(int test1) {
- this.test1 = test1;
- }
- public int getEssay2() {
- return essay2;
- }
- public void setEssay2(int essay2) {
- this.essay2 = essay2;
- }
- public int getTest2() {
- return test2;
- }
- public void setTest2(int test2) {
- this.test2 = test2;
- }
- public int getFinalGrade() {
- return finalGrade;
- }
- public void setFinalGrade(int finalGrade) {
- this.finalGrade = finalGrade;
- }
- }
- Student.java
- public class Student {
- private String firstName , lastName;
- private int essay1, test1 , essay2, test2 , finalGrade;
- public Student(String firstName, String lastName, int essay1, int test1, int essay2, int test2, int finalGrade) {
- super();
- this.firstName = firstName;
- this.lastName = lastName;
- this.essay1 = essay1;
- this.test1 = test1;
- this.essay2 = essay2;
- this.test2 = test2;
- this.finalGrade = finalGrade;
- }
- public String getFirstName() {
- return firstName;
- }
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- public int getEssay1() {
- return essay1;
- }
- public void setEssay1(int essay1) {
- this.essay1 = essay1;
- }
- public int getTest1() {
- return test1;
- }
- public void setTest1(int test1) {
- this.test1 = test1;
- }
- public int getEssay2() {
- return essay2;
- }
- public void setEssay2(int essay2) {
- this.essay2 = essay2;
- }
- public int getTest2() {
- return test2;
- }
- public void setTest2(int test2) {
- this.test2 = test2;
- }
- public int getFinalGrade() {
- return finalGrade;
- }
- public void setFinalGrade(int finalGrade) {
- this.finalGrade = finalGrade;
- }
- }
- Utilities.java
- import java.io.BufferedReader;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- public class Utilities extends Assignment{
- private String fileName;
- private StringBuilder builder = new StringBuilder();
- private String assignmentName;
- int section , essay1 ,test1 , essay2 , test2 , finalGrade;
- public List<Student> getAllStudent() throws IOException{
- builder.setLength(0);
- List<Student> list = new ArrayList<Student>();
- int counter = 0;
- for(String line: readFile(fileName).split("\n")){
- if((counter += 1) > 2)
- builder.append(line + ":");
- }
- for(String line : builder.toString().split(":")){
- String attribute[] = line.split(",");
- list.add(new Student(attribute[0] , attribute[1] , Integer.parseInt(attribute[2]) ,
- Integer.parseInt(attribute[3]) , Integer.parseInt(attribute[4]) , Integer.parseInt(attribute[5]) , Integer.parseInt(attribute[6])));
- }
- return list;
- }
- public void setAssigment() throws IOException{
- int counter = 0;
- builder.setLength(0);
- for(String line: readFile(fileName).split("\n")){
- if((counter += 1) == 2)
- builder.append(line);
- }
- String attribute[] = builder.toString().split(",");
- this.setAssignmentName(attribute[0]);
- this.setSection(Integer.parseInt(attribute[1]));
- this.setEssay1(Integer.parseInt(attribute[2]));
- this.setTest1(Integer.parseInt(attribute[3]));
- this.setEssay2(Integer.parseInt(attribute[4]));
- this.setTest2(Integer.parseInt(attribute[5]));
- this.setFinalGrade(Integer.parseInt(attribute[6]));
- }
- private String readFile(String file) throws IOException {
- BufferedReader reader = new BufferedReader( new FileReader (file));
- String line = null;
- StringBuilder stringBuilder = new StringBuilder();
- String ls = System.getProperty("line.separator");
- while( ( line = reader.readLine() ) != null ) {
- stringBuilder.append(line).toString();
- stringBuilder.append(ls);
- }
- reader.close();
- return stringBuilder.toString();
- }
- public void setFileName(String fileName){
- this.fileName = fileName;
- }
- public String getFileName(String fileName){
- return fileName;
- }
- public void help(){
- System.out.println("Accepted commands:");
- System.out.println("exit");
- System.out.println("help");
- System.out.println("load [filename");
- System.out.println("students");
- System.out.println("search [partial name");
- System.out.println("assignments");
- System.out.println("grades");
- System.out.println("student [student name");
- System.out.print("assignment [assignment name]");
- }
- public void grades(){
- }
- public char gradeRating(int points){
- if(points >= 90 && points <= 100)
- return 'A';
- else if(points >= 80 && points < 90)
- return 'B';
- else if(points >= 70 && points < 80)
- return 'C';
- else if(points >= 60 && points < 70)
- return 'D';
- else if(points >= 0 && points < 80)
- return 'F';
- else
- return '-';
- }
- public String setWordAllignment(String word){
- if(word.length() <= 8){
- int length = word.length();
- for(int ctr = 0; ctr < 9 - length ; ctr++){
- word += " ";
- }
- return word;
- }
- return word;
- }
- public Student searchStudent(List<Student> list , String studentName){
- for(Student student : list){
- if(student.getFirstName().contains(studentName) || student.getLastName().contains(studentName))
- return student;
- }
- return null;
- }
- public void studentGrade(List<Student> list){
- int grades[] = new int[5];
- for(Student student : list){
- int points = student.getEssay1() + student.getEssay2() + student.getTest1() + student.getTest2() + student.getFinalGrade();
- if(String.valueOf(this.gradeRating(points)).equals("A"))
- grades[0] += 1;
- else if(String.valueOf(this.gradeRating(points)).equals("B"))
- grades[1] += 1;
- else if(String.valueOf(this.gradeRating(points)).equals("C"))
- grades[2] += 1;
- else if(String.valueOf(this.gradeRating(points)).equals("D"))
- grades[3] += 1;
- else if(String.valueOf(this.gradeRating(points)).equals("F"))
- grades[4] += 1;
- }
- System.out.println("A: "+ grades[0]);
- System.out.println("B: "+ grades[1]);
- System.out.println("C: "+ grades[2]);
- System.out.println("D: "+ grades[3]);
- System.out.println("F: "+ grades[4]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement