/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package gradebooktest; import java.util.Random; /** * * @author jcmt */ public class Gradebook { private String courseName; private Integer day; // must be valid private Integer month;//must be valid private Integer year; //between 2000 and 2014 private Double grade1; private long grSeed = 7635; private Double[] grades = new Double[42]; private String[] names = new String[42]; private int[] n = {10,20,30}; private Double[][] eachGrade = new Double[42][12]; // eachGrade[0] = new Double[12]; // eachGrade[1] = new Double[3]; // write get and set functions for day object // Quiz 1 Jan. 21 //getDay //setDay -- error checking not required public Gradebook() { Random randomNumbers = new Random(); courseName = "Basketweaving"; day = 20; month = 8; year = 2013; randomNumbers.setSeed(grSeed); grade1 = (double) randomNumbers.nextInt(101); grades[0] = grade1; names[0] = courseName; for (int j=0; j < grades.length; j++) { grades[j] = (double) randomNumbers.nextInt(); } for (int k=0;k < eachGrade.length ;k++) { for(int l=0; l < eachGrade[k].length ;l++) { eachGrade[k][l] = (double) randomNumbers.nextInt(); } } } public Double[][] getEachGrade() { return eachGrade; } public void setEachGrade(Double[][] eachGrade) { this.eachGrade = eachGrade; } public Gradebook(String s, Integer i) { setCourseName(s); setDay(i); month = 1; year = 2014; } public Gradebook(Integer i, String s) { setCourseName(s); setDay(i); month = 1; year = 2014; } public Gradebook(String courseName, Integer day, Integer month, Integer year) { setCourseName(courseName); setDay(day); setMonth(month); setYear(year); } public Integer getMonth() { return month; } public boolean setMonth(Integer month) { if ((month < 13) && (month > 0)) { this.month = month; return true; } else { return false; } } public double checkAvg(Double... numbers) { } public void checkFreq(Double[] grades) { int[] responses = {1,9, 2,5,4,3,2,4,0,3,1, 4, 7, 3, 4,2,3,3,2,1,1,5,4,-2,5}; int[][] b = {{1,2},{3,4,5}}; int[][] c = new int[3][4]; int[][] d = new int[2][]; d[0] = new int[5]; d[1] = new int[3]; int[] freq = new int[6]; System.out.println("In freq"); //for (int ans=0; ans < responses.length; ans++) for (int resp: responses) { try { if (resp != 0) { ++freq[resp]; } /* if (responses[ans] != 0) { ++freq[responses[ans]]; } * */ } catch( ArrayIndexOutOfBoundsException e) { System.out.println(e); System.out.printf(" The response = %d\n\n", resp); } } for (int res=0; res < freq.length; res++) { System.out.printf("freq[%d] is %d\n",res,freq[res]); } } public Integer getYear() { return year; } public boolean setYear(Integer year) { if ((year >= 2000)&&(year <=2014)) { this.year = year; return true; } else { return false; } } public Integer getDay() { return day; } public void setDay(Integer day) { if ((day > 0)&&(day < 31)) { this.day = day; } } public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; //courseName = cName; } public boolean setDate(Integer day, Integer month, Integer year) { if (setYear(year)) { if (setMonth(month)) { setDay(day); return true; } } return false; } public Double[] getGrades() { return grades; } public void setGrades(Double[] grades) { this.grades = grades; } public void displayNameMessage() { System.out.printf("Welcome to the Gradebook for %s\n", courseName); } public void displayEachGrade() { System.out.println("The values in eachGrade are:"); for (int k=0;k < eachGrade.length ;k++) { for(int l=0; l < eachGrade[k].length ;l++) { System.out.printf("%f\t",eachGrade[k][l] ); } System.out.println(); } } }