These projects were created by Leigh Anne Fitz and Lisa Ferran to provide engaging, standards-aligned learning experiences for AP Computer Science A students. The autograding tests were designed by Kate McDonnell.
Now that youβve mastered the fundamentals of Java programming, itβs time to begin building your own classes. In these projects, youβll learn how to design classes that model real-world objects by creating instance variables, writing constructors, and implementing methods that define an objectβs behavior.
Each project is designed to reinforce object-oriented programming through authentic programming tasks. As you complete them, focus on designing classes with clear responsibilities, choosing meaningful names for variables and methods, and testing your classes thoroughly. Well-designed classes are the foundation of organized, reusable, and maintainable programs.
public class Student {
// Instance variables
private String name;
private int grade;
// Constructor
public Student(String n, int g) {
name = n;
grade = g;
}
// Method
public String introduce() {
return "My name is " + name
+ " and I am in grade " + grade;
}
}
An online game tracks information about each playerβs performance. A GamePlayer object stores a playerβs username, the number of games played, the total number of points earned, and whether the player is currently active.
Complete a game where it adds the given number of points to totalPoints, increases gamesPlayed by 1, and if the player has completed 20 or more games, set active to false.