Question

I need to change the following code so that it results in the sample output below but also imports and utilizes the code from the GradeCalculator, MaxMin, and Student classes in the com.csc123 package. If you need to change anything in the any of the classes that's fine but there needs to be all 4 classes. I've included the sample input and what I've done so far:

How many students are in your class - 3 Enter the first name of student #1 - Mike Enter Mikes last name - Graz How many grad

package lab03;


import java.util.ArrayList;
import java.util.Scanner;
import com.csc241.*;


public class Lab03 {
public String toString() {
return this.fName+" "+this.lName+" (average-"+this.avg()+" ; max/min-"+this.max()+"/"+this.min()+")";
}
public static void main(String args[]) {
do {
double max=0,min=100,total=0;
Scanner sc = new Scanner(System.in);
System.out.print("How many students are in your class - ");
int n = sc.nextInt();
sc.nextLine();
ArrayList s = new ArrayList();
for(int i=0;i System.out.print("\nEnter the first name of the student #"+(i+1)+" - ");
String fName = sc.nextLine();
System.out.print("\nEnter "+fName+"\'s last name - ");
String lName = sc.nextLine();
System.out.print("\nHow many grades will you be entering for "+fName+" "+lName+"? - ");
int m = sc.nextInt();
double grades[] = new double[m];
System.out.println("\nPlz enter the grades for "+fName+" "+lName);
for(int j=0;j grades[j]= sc.nextDouble();
}
Student std = new Student(fName,lName,grades);
s.add(std);
System.out.println("Grade Statistics for "+std);
total += std.avg();
if(std.max()>max)
max = std.max();
if(std.min() min = std.min();
sc.nextLine();
}
double average = total/n;
System.out.println("\nEnsemble statistics - Average-"+average+" ; max/min-"+max+"/"+min);
System.out.print("\nDo you wish to continue(y/n):");
char ch = sc.nextLine().charAt(0);
if(ch=='n'||ch=='N')
break;
}while(true);
}
}

-----------------------------------------------------------------------------------------------------------------------------------------

package com.csc123;
public class GradeCalculator {
public static double avg(final double[] array)
{
double a;
int i;
for(a = array[0], i=1; i < array.length; i++)
{
a += array[i];
}
return a / array.length;
}
public static MaxMin maxMin(final double[] array)
{
double max, min;
int i;
MaxMin mM = new MaxMin();
for(max = min = array[0], i=1; i < array.length; i++)
{
if(array[i] < min)
{
min = array[i];
}
else if(array[i] > max)
{
max = array[i];
}
}
mM.setMax(max);
mM.setMin(min);
return mM;
}
}

------------------------------------------------------------------------------------------

package com.csc123;

public class MaxMin {
private double max;
private double min;
  
public void setMax(final double max)
{
this.max = max;
}
public void setMin(final double min)
{
this.min = min;
}
public double getMax()
{
return max;
}
public double getMin()
{
return min;
}
}

-----------------------------------------------------------------

package com.csc123;

public class Student{
private String fName;
private String lName;
private double grades;

public void setfName(final String fName)
{
this.fName = fName;
}
public void setlName(final String lName)
{
this.lName = lName;
}
public void setgrades(final double grades)
{
this.grades = grades;
}
public String getfName()
{
return fName;
}
public String getlName()
{
return lName;
}
public double getgrades()
{
return grades;
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

Student.java

package com.csc123;

public class Student {

    private String fName;

    private String lName;

    private int grades[];

    public Student(String fName, String lName, int grades[]){

        this.fName = fName;

        this.lName = lName;

        this.grades = grades;

    }

    public void setfName(final String fName) {

        this.fName = fName;

    }

    public void setlName(final String lName) {

        this.lName = lName;

    }

    public void setgrades(final int grades[]) {

        this.grades = grades;

    }

    public String getfName() {

        return fName;

    }

    public String getlName() {

        return lName;

    }

    public int[] getgrades() {

        return grades;

    }

    public String toString(){

        return fName+" "+lName;

    }

}

MaxMin.java

package com.csc123;

public class MaxMin {

    private int max;

    private int min;

    public void setMax(final int max) {

        this.max = max;

    }

    public void setMin(final int min) {

        this.min = min;

    }

    public int getMax() {

        return max;

    }

    public int getMin() {

        return min;

    }

}

GradeCalculator.java

package com.csc123;

public class GradeCalculator {

    public static double avg(final int[] array) {

        double a;

        int i;

        for (a = array[0], i = 1; i < array.length; i++) {

            a += array[i];

        }

        return a / array.length;

    }

    public static MaxMin maxMin(final int[] array) {

        int max, min;

        int i;

        MaxMin mM = new MaxMin();

        for (max = min = array[0], i = 1; i < array.length; i++) {

            if (array[i] < min) {

                min = array[i];

            } else if (array[i] > max) {

                max = array[i];

            }

        }

        mM.setMax(max);

        mM.setMin(min);

        return mM;

    }

}

Lab03.java

import java.util.ArrayList;

import java.util.Scanner;

import com.csc241.*;

public class Lab03 {

    // public String toString() {

    //     return fName + " " + lName + " (average-" + avg() + " ; max/min-" + max() + "/" + min()+ ")";

    // }

    public static void main(String args[]) {

        do {

            double max = 0, min = 100, total = 0, avg;

            Scanner sc = new Scanner(System.in);

            System.out.print("How many students are in your class - ");

            int n = sc.nextInt();

            sc.nextLine();

            ArrayList<Student> s = new ArrayList<Student>();

            for (int i = 0; i < n; i++) {

                System.out.print("\nEnter the first name of the student #" + (i + 1) + " - ");

                String fName = sc.nextLine();

                System.out.print("\nEnter " + fName + "\'s last name - ");

                String lName = sc.nextLine();

                System.out.print("\nHow many grades will you be entering for " + fName + " " + lName + "? - ");

                int m = sc.nextInt();

                int grades[] = new int[m];

                System.out.println("\nPlz enter the grades for " + fName + " " + lName);

                for (int j = 0; j < m; j++) {

                    grades[j] = sc.nextInt();

                }

                Student std = new Student(fName, lName, grades);

                s.add(std);

                System.out.print("Grade Statistics for " + std);

                avg = GradeCalculator.avg(grades);

                total += avg;

                MaxMin maxMin = GradeCalculator.maxMin(grades);

                System.out.printf("(average=%.1f ; max/min=%d/%d)\n", avg, maxMin.getMax(), maxMin.getMin());

                sc.nextLine();

            }

            double average = total / n;

            System.out.println("\nEnsemble statistics - Average-" + average + " ; max/min-" + max + "/" + min);

            System.out.print("\nDo you wish to continue(y/n):");

            char ch = sc.nextLine().charAt(0);

            if (ch == 'n' || ch == 'N')

                break;

        } while (true);

    }

}

Add a comment
Know the answer?
Add Answer to:
I need to change the following code so that it results in the sample output below...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have this program that works but not for the correct input file. I need the...

    I have this program that works but not for the correct input file. I need the program to detect the commas Input looks like: first_name,last_name,grade1,grade2,grade3,grade4,grade5 Dylan,Kelly,97,99,95,88,94 Tom,Brady,100,90,54,91,77 Adam,Sandler,90,87,78,66,55 Michael,Jordan,80,95,100,89,79 Elon,Musk,80,58,76,100,95 output needs to look like: Tom Brady -------------------------- Assignment 1: A Assignment 2: A Assignment 3: E Assignment 4: A Assignment 5: C Final Grade: 82.4 = B The current program: import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class main {    public static void main(String[]...

  • There is a problem in the update code. I need to be able to update one...

    There is a problem in the update code. I need to be able to update one attribute of the students without updating the other attributes (keeping them empty). package dbaccessinjava; import java.sql.DriverManager; import java.sql.Connection; import java.sql.SQLException; import java.sql.*; import java.io.*; import java.util.Scanner; public class DBAccessInJava { public static void main(String[] argv) {    System.out.println("-------- Oracle JDBC Connection Testing ------"); Connection connection = null; try{ Class.forName("oracle.jdbc.driver.OracleDriver"); Connection con= DriverManager.getConnection("jdbc:oracle:thin:@MF057PC16:1521:ORCL", "u201303908","pmu"); String sql="select * from student"; Statement st; PreparedStatement ps; ResultSet rs;...

  • Hi, I want to creat a file by the name osa_list that i can type 3...

    Hi, I want to creat a file by the name osa_list that i can type 3 things and store there ( first name, last name, email). then i want to know how to recal them by modifying the code below. the names and contact information i want to store are 200. #include <iostream> #include <fstream> #include <cstdlib> #include <iomanip> using namespace std; class Student { private: string fname; string lname; string email;       public: Student(); Student(string fname, string lname,...

  • Please help. I need a very simple code. For a CS 1 class. Write a program...

    Please help. I need a very simple code. For a CS 1 class. Write a program in Java and run it in BlueJ according to the following specifications: The program reads a text file with student records (first name, last name and grade). Then it prompts the user to enter a command, executes the command and loops. The commands are the following: "printall" - prints all student records (first name, last name, grade). "firstname name" - prints all students with...

  • I have a program that reads a file and then creates objects from the contents of...

    I have a program that reads a file and then creates objects from the contents of the file. How can I create a linked list of objects and use it with the package class instead of creating and using an array of objects? I am not allowed to use any arrays of objects or any java.util. lists in this program. Runner class: import java.util.Scanner; import java.io.*; class Runner { public static Package[] readFile() { try { File f = new...

  • Hello, I am continuously receiving errors in the code below. Can you please show me what...

    Hello, I am continuously receiving errors in the code below. Can you please show me what I am doing wrong? import java.util.*; public class ShowTax { { public static void main(String [] args) {        Tax myTax = new Tax();        String ssn, maritalStatus, lname, fname,zipcode;        double income;        int numberOfVehicles;        Scanner s = new Scanner(System.in);        String regex = "[0-9]{3}-[0-9]{2}-[0-9]{4}";        do {            System.out.print("Enter the Social Security...

  • So i need help with this program, This program is supposed to ask the user to...

    So i need help with this program, This program is supposed to ask the user to input their weight on earth so I would put "140" then it would ask "enter planet name, Min, Max or all" and if the user typed in all it would display all the planets and your weight on them. Right now Im suck on the part where im required to do a switch statement with a linear search. Below this im going to put...

  • Below, you can find the description of your labwork for today. You can also find the...

    Below, you can find the description of your labwork for today. You can also find the expected output of this code in the Application Walkthrough section. You are going to improve your existing Money & Stock Trading Platform on previous week’s labwork by incorporating Collections. In previous labworks, you have used arrays for holding Customer and Item objects. For this labwork you need to use ArrayList for holding these objects. So, rather than defining Customer[] array, you need to define...

  • I need to update the code listed below to meet the criteria listed on the bottom....

    I need to update the code listed below to meet the criteria listed on the bottom. I worked on it a little bit but I could still use some help/corrections! import java.util.Scanner; public class BankAccount { private int accountNo; private double balance; private String lastName; private String firstName; public BankAccount(String lname, String fname, int acctNo) { lastName = lname; firstName = fname; accountNo = acctNo; balance = 0.0; } public void deposit(int acctNo, double amount) { // This method is...

  • I need to create a code for this prompt: In this project we will build a...

    I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT