Question

In java run through eclipse /**    * Adds a team.    *    * You...

In java run through eclipse

/**
   * Adds a team.
   *
   * You can assume the student team name is unique.
   *
   * (for individual assignment): the student names should be students
   * that have been already added
   *
   * PAIR ASSIGNMENT: implicitly create students if they don't exist
   *
   * @param teamName name of new team
   * @param memberNames a list of student names that belong to the team
   * @return "ok" if success
   */
   private String handleAddTeam(String teamName, ArrayList<String> memberNames) {
      
       // HINT: you'll want to pass Team an array of Students,
       // not an array of student names
      
       // BONUS HINT: you'll probably want to implement the getStudentByNameMethod
       // and use it in this function
      
       //TODO: Your code here
       return null;
   }

   /**
   * Returns the student from students with the particular name,
   * null otherwise (e.g., if the student does not exist).
   *
   * You'll find this method handy when writing addTeam and getAverage.
   *
   * @param name the name of the student for whom to search
   * @return student object with the name or null
   */
   public Student getStudentByName(String name) {

       //TODO: Your code here      
       return null;
   }

   /**
   * Adds a grade to all the students on the given team.
   *
   * You can assume the team has already been created.
   *
   * @param teamName the team to add the grade to
   * @param grade the grade to add
   * @return "ok" if successful
   */
   private String handleAddGrade(String teamName, double grade) {
       //TODO: Your code here
       return null;
   }
  
  
   /**
   * Returns the average for a particular student as a string.
   *
   * NOTE the result should be ROUNDED to the nearest whole number
   * Check out Long.toString and Math.round
   *
   * NOTE if a student has no grades, the student's average should be 0
   *
   * @param studentName name of student
   * @return average grade as string, rounded to nearest whole number
   */
   private String handleGetAverage(String studentName) {
       //TODO: Your code here
       return null;
   }
  
   /**
   * Returns the team name with the best average on all grades for that team
   *
   * PAIR ASSIGNMENT
   *
   * THIS PART OF THE ASSIGNMENT MAY BE done in pairs with another student.
   * Be sure to note who you paired with in a comment. You don't have to
   * pair if you don't want to.
   *
   * NOTE that "best team" is different from the team with the best students.
   * The average is for the grades FOR THAT TEAM - not including
   * other grades that students on that team might have.
   *
   * Say, for example, there is a team that had one grade of 100. Then
   * that TEAM's average should be 100, even if each of the members of the
   * team got grades with other groups. You'll have to keep track of
   * additional info to determine each team's average grades.
   *
   * If a team has no grades, it's average should be considered to be 0.
   *
   * If several teams have exactly the same average, any one of them may be
   * returned as the best group.
   *
   * If no teams exist, you can return an error.
   *
   * @return the name of the team with the best overall average
   */
   private String handleGetBestTeam() {
       //TODO: Your code here
       return null;
   }

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

Student.java

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package team;

import java.util.LinkedList;
import java.util.List;

/**
*
* @author owner
*/
public class Student {
String name;
List <Double> gradeList=new LinkedList<>();
double average=0;

public Student() {
}

  
public Student(String name) {
this.name = name;
}
public void addGrade(double grade){
gradeList.add(grade);
}

public double getAverage(){
double sum=0;
for(Double a:gradeList){
sum+=a;
}
return sum/(gradeList.size());
  
}
public String getName() {
return name;
}
  
  
  
}

Team.java


package team;

import java.text.DecimalFormat;
import java.util.*;

public class Team {
  
static ArrayList <Student> Students=new ArrayList<>();
static ArrayList<Team> teamList=new ArrayList<>();
String teamName;
ArrayList<Student> members=new ArrayList<>();
  
  
  
  
/**
* Adds a team.
*
* You can assume the student team name is unique.
*
* (for individual assignment): the student names should be students
* that have been already added
*
* PAIR ASSIGNMENT: implicitly create students if they don't exist
*
* @param teamName name of new team
* @param memberNames a list of student names that belong to the team
* @return "ok" if success
*/
private String handleAddTeam(String teamName, ArrayList<String> memberNames) {

// HINT: you'll want to pass Team an array of Students,
// not an array of student names

// BONUS HINT: you'll probably want to implement the getStudentByNameMethod
// and use it in this function

//TODO: Your code here

this.teamName=teamName;

for(String member:memberNames){
///get student object from name
Student obj=this.getStudentByName(member);
if(obj!=null){
//if not null then add it to memberlist which is list od students
members.add(obj);
}   
}   

teamList.add(this);
// System.out.println("*"+this.teamName);

return null;
}

/**
* Returns the student from students with the particular name,
* null otherwise (e.g., if the student does not exist).
*
* You'll find this method handy when writing addTeam and getAverage.
*
* @param name the name of the student for whom to search
* @return student object with the name or null
*/
public Student getStudentByName(String name) {
  
for(Student s:Students){
if(s.getName().equals(name)){
return s;
}
}

return null;
}

/**
* Adds a grade to all the students on the given team.
*
* You can assume the team has already been created.
*
* @param teamName the team to add the grade to
* @param grade the grade to add
* @return "ok" if successful
*/
private String handleAddGrade(String teamName, double grade) {
//TODO: Your code here

//get Team with teamName
Team myTeam=null;
for(Team obj:teamList){
if(obj.teamName.equals(teamName)){
myTeam=obj;
break;
}
}
  
if(myTeam==null)
return null;

//for every student of team   
for(Student obj:myTeam.members){
//add grade
obj.addGrade(grade);
}
return "ok";

}

/**
* Returns the average for a particular student as a string.
*
* NOTE the result should be ROUNDED to the nearest whole number
* Check out Long.toString and Math.round
*
* NOTE if a student has no grades, the student's average should be 0
*
* @param studentName name of student
* @return average grade as string, rounded to nearest whole number
*/
private String handleGetAverage(String studentName) {
//TODO: Your code here

/// get student obj
Student myStudent=null;
for(Student obj: Students){
if(studentName.equals(obj.getName())){
myStudent=obj;
break;
}
}
if(myStudent==null)
return null;

///find avg
double grade=myStudent.getAverage();
///rounding
double newgrade = Math.round(grade*100.0)/100.0;
return Double.toString(newgrade);

}

/**
* Returns the team name with the best average on all grades for that team
*
* PAIR ASSIGNMENT
*
* THIS PART OF THE ASSIGNMENT MAY BE done in pairs with another student.
* Be sure to note who you paired with in a comment. You don't have to
* pair if you don't want to.
*
* NOTE that "best team" is different from the team with the best students.
* The average is for the grades FOR THAT TEAM - not including
* other grades that students on that team might have.
*
* Say, for example, there is a team that had one grade of 100. Then
* that TEAM's average should be 100, even if each of the members of the
* team got grades with other groups. You'll have to keep track of
* additional info to determine each team's average grades.
*
* If a team has no grades, it's average should be considered to be 0.
*
* If several teams have exactly the same average, any one of them may be
* returned as the best group.
*
* If no teams exist, you can return an error.
*
* @return the name of the team with the best overall average
*/
private String handleGetBestTeam() {

return null;
}



public static void main(String[] args) {
  
  
Student s1=new Student("a");
Student s2=new Student("b");
Student s3=new Student("c");
Student s4=new Student("d");
  
//add studets here
Students.add(s1);
Students.add(s2);
Students.add(s3);
Students.add(s4);
  
//add team
  
Team object=new Team();
ArrayList<String> temp=new ArrayList<>();
temp.add("b");
temp.add("d");
  
object.handleAddTeam("Team1", temp);
object.handleAddGrade("Team1", 2);

Team object2=new Team();
  
temp.clear();
  
temp.add("a");
temp.add("d");
temp.add("c");
object2.handleAddTeam("Team2", temp);
object2.handleAddGrade("Team2", 3);
  
for(Team t:teamList){
System.out.println("Team == "+t.teamName);
  
for(Student s:t.members){
System.out.println(s.getName()+"\t"+s.getAverage());
}
  
}
  
}
  
}

    private String handleGetBestTeam() method have not clearaly stated as it does not specify how to calculate best team Other 3 methods implementation has been provided I hope that might help you...

Add a comment
Know the answer?
Add Answer to:
In java run through eclipse /**    * Adds a team.    *    * You...
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
  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

  • Writing 3 Java Classes for Student registration /** * A class which maintains basic information about...

    Writing 3 Java Classes for Student registration /** * A class which maintains basic information about an academic course. */ public class Course {    /** * Attributes. */ private String code; private String title; private String dept; // name of department offering the course private int credits; /** * Constructor. */ public Course(String code, String title, int credits) { // TODO : initialize instance variables, use the static method defined in // Registrar to initialize the dept name variable...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • A teacher wants to create a list of students in her class. Using the existing Student...

    A teacher wants to create a list of students in her class. Using the existing Student class in this exercise. Create a static ArrayList called classList that adds a student to the classList whenever a new Student is created. In the constructor, you will have to add that Student to the ArrayList. Coding below was given to edit and use public class ClassListTester { public static void main(String[] args) { //You don't need to change anything here, but feel free...

  • JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** *...

    JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** * Write a description of class UniversityTester here. * * @author (your name) * @version (a version number or a date) */ public class ClassroomTester { public static void main(String[] args) { ArrayList<Double> grades1 = new ArrayList<>(); grades1.add(82.0); grades1.add(91.5); grades1.add(85.0); Student student1 = new Student("Srivani", grades1); ArrayList<Double> grades2 = new ArrayList<>(); grades2.add(95.0); grades2.add(87.0); grades2.add(99.0); grades2.add(100.0); Student student2 = new Student("Carlos", grades2); ArrayList<Double> grades3 = new...

  • Your assignment is to write a grade book for a teacher. The teacher has a text file, which includ...

    Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...

  • Write a program in Java that prompts a user for Name and id number. and then...

    Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA MAIN import java.util.StringTokenizer; import javax.swing.JOptionPane; public class Main {    public static void main(String[] args) {                       String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);        String name = thedata;        Student pupil = new Student(name);                   //add code here       ...

  • Design and code a JAVA program called ‘Grades’. ? Your system should store student’s name, and...

    Design and code a JAVA program called ‘Grades’. ? Your system should store student’s name, and his/her course names with grades. ? Your system should allow the user to input, update, delete, list and search students’ grades. ? Each student has a name (assuming no students share the same name) and some course/grade pairs. If an existing name detected, user can choose to quit or to add new courses to that student. ? Each student has 1 to 5 courses,...

  • Using Java coding, complete the following: This program should implement a LinkedList data structure to handle...

    Using Java coding, complete the following: This program should implement a LinkedList data structure to handle the management of student records. It will need to be able to store any number of students, using a Linked List. LinearNode.java can be used to aid creating this program Student should be a class defined with the following:    • String name    • int year    • A linked list of college classes (college classes are represented using strings)    • An...

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