Week 14
Source Code
import java.util.*;
public class Week14 {
public static void main(String[] args) {
String myName = ""; // add your name
System.out.println("Week 14" + " - " + myName);
// Menu
System.out.println("Menu");
System.out.println("E1 - Example 1");
// setup Scanner
Scanner in = new Scanner(System.in);
System.out.print("Choice: ");
String choice = in.nextLine();
// switch choices
switch (choice) {
case "E1":
System.out.println("Example 1");
example1();
break;
case "E2":
System.out.println("Example 2");
example2();
break;
case "E3":
System.out.println("Example 3");
example3();
break;
case "E4":
System.out.println("Example 4");
example4();
break;
}
}
// example1 method
public static void example1() {
// create CollegeStudent object
// call methods
}
// example2 method
public static void example2() {
// create CollegeStudent object
}
// example3 method
public static void example3() {
// create CollegeStudent object
}
// example4 method
public static void example4() {
// create two high school students
// call printStudentCounter method
}
}
CollegeStudent.java
/**
* Class CollegeStudent keeps track of the name, email, and ID of a college student.
*/
public class CollegeStudent
{
// private instance variables
/**
* Constructor for CollegeStudent.
* @param name the initial name of the student
* @param email the initial email of the student
* @param ID the initial ID of the student
*/
/**
* Gets the name of the student.
* @return the name of the student
*/
/**
* Gets the email of the student.
* @return the email of the student
*/
/**
* Gets the ID of the student.
* @return the ID of the student
*/
/**
* Returns a string representation of the CollegeStudent object.
* @return a string representation of the CollegeStudent object
*/
// Accessor methods (getters)
/**
* Sets the name of the college student.
* @param name the new name of the student
*/
/**
* Sets the email of the college student.
* @param email the new email of the student
*/
/**
* Sets the ID of the college student.
* @param id the new ID of the student
*/
}
Athlete.java
import java.util.*;
/**
* Represents an athlete in the high school's sports team management system.
*/
public class Athlete {
// Private instance variables
/**
* Constructs an Athlete with specified attributes.
*
* @param name The name of the athlete.
* @param grade The grade level (9th, 10th, 11th, 12th).
* @param sport The sport the athlete participates in.
* @param position The position in the sport (e.g., forward, goalkeeper).
* @param height The height of the athlete in inches.
* @param weight The weight of the athlete in pounds.
*/
// Accessor (getter) methods
/**
* Gets the athlete's name.
*
* @return The name of the athlete.
*/
/**
* Gets the athlete's grade level.
*
* @return The grade level of the athlete.
*/
/**
* Gets the sport the athlete participates in.
*
* @return The sport of the athlete.
*/
/**
* Gets the athlete's position in the sport.
*
* @return The position of the athlete.
*/
/**
* Gets the height of the athlete.
*
* @return The height in inches.
*/
/**
* Gets the weight of the athlete.
*
* @return The weight in pounds.
*/
// Mutator (setter) methods
/**
* Sets the athlete's name.
*
* @param name The new name of the athlete.
*/
/**
* Sets the athlete's grade level.
*
* @param grade The new grade level.
*/
/**
* Sets the sport the athlete participates in.
*
* @param sport The new sport.
*/
/**
* Sets the athlete's position.
*
* @param position The new position.
*/
/**
* Sets the height of the athlete.
*
* @param height The new height in inches.
*/
/**
* Sets the weight of the athlete.
*
* @param weight The new weight in pounds.
*/
/**
* Returns a string representation of the athlete.
*
* @return A string containing all attributes of the athlete.
*/
@Override
public String toString() {
}
/**
* The main method tests the Athlete class by creating instances and using
* its methods.
*
* @param args Command-line arguments (not used).
*/
public static void main(String[] args) {
// Creating athlete objects
// Displaying initial details
// Modifying attributes using setters
// Displaying updated details
}
}
HighSchoolStudent.java
/**
* The HighSchoolStudent class represents a high school student with a name.
* It includes a static counter to track the number of students created.
*/
public class HighSchoolStudent {
// instance variable
// static instance variable
/**
* Constructs a new HighSchoolStudent with the given name.
* Increments the student counter upon creation.
*
* @param name The name of the student.
*/
/**
* Returns the total number of students created.
*
* @return the total number of students created.
*/
/**
* Returns a string representation of the student.
*
* @return A string containing the student's name.
*/
public String toString() {
return "Student Name: " + name;
}
}
SchoolMember.java
/**
* The SchoolMember class represents a student in a school with a name and grade level.
*/
public class SchoolMember {
/** The name of the student. */
private String name;
/** The grade level of the student (9, 10, 11, or 12). */
private int gradeLevel;
/** A static counter to track the total number of students. */
public static int memberCounter = 0;
// TODO: Declare additional static variables to track students in each grade level.
/**
* Constructs a SchoolMember object with a name and grade level.
* Increments the total member counter and the respective grade counter.
*
* @param name The name of the student.
* @param gradeLevel The grade level of the student (9-12).
*/
public SchoolMember(String name, int gradeLevel) {
this.name = name;
this.gradeLevel = gradeLevel;
memberCounter++;
// TODO: Update the appropriate grade level counter.
}
/**
* Returns the grade level of the student.
*
* @return The grade level of the student.
*/
public int getGradeLevel() {
// TODO: Implement this method
return 0; // Placeholder
}
/**
* Prints the total number of school members and breakdown by grade.
*/
public static void printMemberCounter() {
System.out.println("Total members: " + memberCounter);
// TODO: Print the number of students in each grade level.
}
/**
* Returns a string representation of the student.
*
* @return A string containing the student's name and grade level.
*/
public String toString() {
return "Student Name: " + name + ", Grade Level: " + gradeLevel;
}
/**
* The main method for testing.
*
* @param args Command-line arguments (not used).
*/
public static void main(String[] args) {
// TODO: Create at least 3 students with different grade levels
// TODO: Call printMemberCounter() to display the counts
}
}
Scoreboard.java
/**
* The Scoreboard class keeps track of scores in a two-team game where teams alternate turns.
* During a turn, a team makes one or more plays. Each play can score points and the team's
* turn continues, or the play can fail (score 0 points) and the team's turn ends.
*/
public class Scoreboard {
// TODO: Instance variables
/**
* Constructs a new Scoreboard object for tracking scores between two teams.
* The game always begins with team 1 as the active team.
*
* @param team1 the name of team 1
* @param team2 the name of team 2
*/
// TODO: Implement Constructor
/**
* Records a play in the game. If points are scored (parameter > 0), the active team's
* score is updated and that team remains active. If the play fails (parameter = 0),
* the active team's turn ends and the inactive team becomes active.
*
* @param points the number of points scored on this play (0 if the play failed)
* Precondition: points ≥ 0
*/
// Implement this method
/**
* Returns a string containing the current state of the game in the format:
* "team1Score-team2Score-activeTeamName"
* For example: "0-0-Red" or "1-3-Blue"
*
* @return a string representing the current game state
*/
// TODO: Implemenent this method
}
Last updated
Was this helpful?