Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA programming help Does my JAVA code below meet these coding standards? CODING STANDARDS All classes should be public Every class should have a print

JAVA programming help

Does my JAVA code below meet these coding standards?

CODING STANDARDS

All classes should be public

Every class should have a print method

Every class must have a default constructor

Use packages for every lab staring lab 5

all properties (instance or static) should be declared private

class name must start with uppercase

must have public instance methods

main() should be in its own class and can have method for input or for automating testing

one class per .java file

must add a default constructor in each class that is used for creating objects

structure of class

o Instance and static variables

o Constructors

o Instance methods

o Static methods

_________________________________________________________________________________________________________

public class Driver

{

public static void main(String[] args)

{

Student arrStudent[] = new Student[40];

int studentCount=0;

arrStudent = Util.readFile("C:\\Users\\JamesJr\\OneDrive\\Documents\\School\\CURRENT QUARTER\\Winter 2018\\Java 35A\\Assignments\\Assignment 5\\StudentScores.txt", arrStudent);

// find number of lines from file. which will show number of students in array.

studentCount= Util.studentCount;

Statistics s = new Statistics();

// print student data fetched from file

for(int i = 0; i

{

arrStudent[i].printData();

}

// print statistics of students

s.printStatistics(arrStudent,studentCount);

}

}

______________________________________________________________________________________________________________

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.StringTokenizer;

public class Util

{

static int studentCount;

static Student[] readFile(String filename, Student[] stu)

{

int i = 0;

try

{

FileReader file = new FileReader(filename);

BufferedReader buff = new BufferedReader(file);

boolean eof = false;

boolean firstLineSkipped = false;

while (!eof)

{

String line = buff.readLine();

if (line == null)

{

eof = true;

}

else

{

if (!firstLineSkipped)

{

firstLineSkipped = true;

continue;

}

stu[i] = new Student();

StringTokenizer st = new StringTokenizer(line);

while (st.hasMoreTokens())

{

stu[i].setSID(Integer.parseInt(st.nextToken()));

int[] arr = new int[5];

for (int j = 0; j < 5; j++)

{

arr[j] = Integer.parseInt(st.nextToken());

}

stu[i].setScores(arr);

}

}

i++;

}

buff.close();

}

catch (IOException e)

{

System.out.printf("Error -- " + e.toString());

}

studentCount = i-1;

return stu;

}

}

_____________________________________________________________________________________________________

public class Statistics

{

private int[] lowscores= new int[5];

private int[] highscores= new int[5];

private float[] avgscores= new float[5];

void findlow(Student[] a, int c)

{

// finds low score.

int i=0;

for(i=0;i<5; i++)

{

int[] temp= a[0].getScores();

int min = temp[i];

for(int j=0; j< c; j++)

{

int[] s= a[j].getScores();

if(min > s[i])

{

min = s[i];

}

}

lowscores[i]= min;

}

}

//find high score

void findhigh(Student[] a, int c)

{

int i=0;

for(i=0;i<5; i++)

{

int[] temp= a[0].getScores();

int max = temp[i];

for(int j=0; j< c; j++)

{

int[] s= a[j].getScores();

if(max < s[i])

{

max = s[i];

}

}

highscores[i]= max;

}

}

//find average score.

void findavg(Student[] a, int c)

{

int i=0;

for(i=0;i<5; i++)

{

int sum =0;

for(int j=0; j

{

int[] s= a[j].getScores();

sum= sum + s[i];

}

avgscores[i]= sum/c;

}

}

//print statistics for all students and all quizes

public void printStatistics(Student[] a, int c)

{

findlow(a,c);

findhigh(a,c);

findavg(a,c);

System.out.printf("\t\t\tLowest score :\t" + lowscores[0] + "\t" + lowscores[1] + "\t" + lowscores[2] + "\t" + lowscores[3] + "\t" + lowscores[4] + " ");

System.out.printf("\t\t\tHigh score :\t" + highscores[0] + "\t" + highscores[1] + "\t" + highscores[2] + "\t" + highscores[3] + "\t" + highscores[4] + " ");

System.out.printf("\t\t\tAverage score :\t" + avgscores[0] + "\t" + avgscores[1] + "\t" + avgscores[2] + "\t" + avgscores[3] + "\t" + avgscores[4] + " ");

}

}

____________________________________________________________________________________________________

public class Student

{

private int SID;

private int scores[] = new int[5];

//get and set functions for scores and ID

public int getSID()

{

return this.SID;

}

public void setSID(int id)

{

this.SID= id;

}

public int[] getScores()

{

return this.scores;

}

public void setScores(int[] s)

{

this.scores= s;

}

//print all data of a student

public void printData()

{

System.out.printf("\t\t\t\t"+ SID +"\t"+ scores[0] +"\t"+ scores[1] +"\t"+ scores[2] + "\t"+ scores[3] +"\t"+ scores[4] +" ");

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions

Question

1. What are your creative strengths?

Answered: 1 week ago

Question

What metaphors might describe how we work together?

Answered: 1 week ago