notes / updates | ap computer science a
December 4, 2025 | About the final exam
We'll write the final exam in two parts: coded and handwritten. The focus should be on chapters 1 through 6.1 (up to arrays of objects) and 6.6.
Below is a list of of some of the key concepts:
number systems
primitive data types
the String class and its methods
logic operators
the Math Class, including random numbers
the Scanner class
if-else statements
loops: for and while
nested loops
static fields
static methods
class design: fields, constructors, methods
classes as fields of a class
interfaces
arrays of primitive data types
arrays of objects (section 6.1)
2d arrays (section 6.6)
October 3, 2025 | GPA Calculuator (a possible solution)
import java.util.*;
public class GPACalculator {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int input; //grade (0 to 100)
double totalWeight = 0.0;
double courseWeight;
double sum = 0.0;
//Record numerical grade and weight for course 1
System.out.println("Enter the credits (double) for course 1: ");
courseWeight = kb.nextDouble();
totalWeight = totalWeight + courseWeight;
System.out.println("Enter a grade (0 to 100) for course 1:");
input = kb.nextInt();
if (input >=93) {
sum = sum + courseWeight*4.0;
} else if (input >=90) {
sum = sum + courseWeight*3.7;
} else if (input >=87) {
sum = sum + courseWeight*3.3;
} else if (input >=83) {
sum = sum + courseWeight*3.0;
} else if (input >=80) {
sum = sum + courseWeight*2.7;
} else if (input >=77) {
sum = sum + courseWeight*2.3;
} else if (input >=73) {
sum = sum + courseWeight*2.0;
} else if (input >=70) {
sum = sum + courseWeight*1.7;
} else if (input >=67) {
sum = sum + courseWeight*1.3;
} else if (input >=63) {
sum = sum + courseWeight;
} else if (input >=60) {
sum = sum + courseWeight*0.7;
} else {
sum = sum + courseWeight*0.0;
}
//reset courseWeight
courseWeight = 0.0;
//Record numerical grade and weight for course 2
System.out.println("Enter the credits (double) for course 2: ");
courseWeight = kb.nextDouble();
totalWeight = totalWeight + courseWeight;
System.out.println("Enter a grade (0 to 100) for course 2:");
input = kb.nextInt();
if (input >=93) {
sum = sum + courseWeight*4.0;
} else if (input >=90) {
sum = sum + courseWeight*3.7;
} else if (input >=87) {
sum = sum + courseWeight*3.3;
} else if (input >=83) {
sum = sum + courseWeight*3.0;
} else if (input >=80) {
sum = sum + courseWeight*2.7;
} else if (input >=77) {
sum = sum + courseWeight*2.3;
} else if (input >=73) {
sum = sum + courseWeight*2.0;
} else if (input >=70) {
sum = sum + courseWeight*1.7;
} else if (input >=67) {
sum = sum + courseWeight*1.3;
} else if (input >=63) {
sum = sum + courseWeight;
} else if (input >=60) {
sum = sum + courseWeight*0.7;
} else {
sum = sum + courseWeight*0.0;
}
//reset courseWeight
courseWeight = 0.0;
//Record numerical grade and weight for course 3
System.out.println("Enter the credits (double) for course 3: ");
courseWeight = kb.nextDouble();
totalWeight = totalWeight + courseWeight;
System.out.println("Enter a grade (0 to 100) for course 3:");
input = kb.nextInt();
if (input >=93) {
sum = sum + courseWeight*4.0;
} else if (input >=90) {
sum = sum + courseWeight*3.7;
} else if (input >=87) {
sum = sum + courseWeight*3.3;
} else if (input >=83) {
sum = sum + courseWeight*3.0;
} else if (input >=80) {
sum = sum + courseWeight*2.7;
} else if (input >=77) {
sum = sum + courseWeight*2.3;
} else if (input >=73) {
sum = sum + courseWeight*2.0;
} else if (input >=70) {
sum = sum + courseWeight*1.7;
} else if (input >=67) {
sum = sum + courseWeight*1.3;
} else if (input >=63) {
sum = sum + courseWeight;
} else if (input >=60) {
sum = sum + courseWeight*0.7;
} else {
sum = sum + courseWeight*0.0;
}
//reset courseWeight
courseWeight = 0.0;
//Record numerical grade and weight for course 4
System.out.println("Enter the credits (double) for course 4: ");
courseWeight = kb.nextDouble();
totalWeight = totalWeight + courseWeight;
System.out.println("Enter a grade (0 to 100) for course 4:");
input = kb.nextInt();
if (input >=93) {
sum = sum + courseWeight*4.0;
} else if (input >=90) {
sum = sum + courseWeight*3.7;
} else if (input >=87) {
sum = sum + courseWeight*3.3;
} else if (input >=83) {
sum = sum + courseWeight*3.0;
} else if (input >=80) {
sum = sum + courseWeight*2.7;
} else if (input >=77) {
sum = sum + courseWeight*2.3;
} else if (input >=73) {
sum = sum + courseWeight*2.0;
} else if (input >=70) {
sum = sum + courseWeight*1.7;
} else if (input >=67) {
sum = sum + courseWeight*1.3;
} else if (input >=63) {
sum = sum + courseWeight;
} else if (input >=60) {
sum = sum + courseWeight*0.7;
} else {
sum = sum + courseWeight*0.0;
}
//reset courseWeight
courseWeight = 0.0;
//Record numerical grade and weight for course 5
System.out.println("Enter the credits (double) for course 5: ");
courseWeight = kb.nextDouble();
totalWeight = totalWeight + courseWeight;
System.out.println("Enter a grade (0 to 100) for course 5:");
input = kb.nextInt();
if (input >=93) {
sum = sum + courseWeight*4.0;
} else if (input >=90) {
sum = sum + courseWeight*3.7;
} else if (input >=87) {
sum = sum + courseWeight*3.3;
} else if (input >=83) {
sum = sum + courseWeight*3.0;
} else if (input >=80) {
sum = sum + courseWeight*2.7;
} else if (input >=77) {
sum = sum + courseWeight*2.3;
} else if (input >=73) {
sum = sum + courseWeight*2.0;
} else if (input >=70) {
sum = sum + courseWeight*1.7;
} else if (input >=67) {
sum = sum + courseWeight*1.3;
} else if (input >=63) {
sum = sum + courseWeight;
} else if (input >=60) {
sum = sum + courseWeight*0.7;
} else {
sum = sum + courseWeight*0.0;
}
//reset courseWeight
courseWeight = 0.0;
System.out.println("The GPA is: " + sum /totalWeight);
}
}
September 23, 2025 | The String class (official documentation)
At the following url find more information about the String class and its features:
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html
September 23, 2025 | Solution to tonight's homework
/*
Working with Scanner, String to build a message for the user.
*/
import java.util.*;
public class Interaction {
public static void main(String[] args) {
//variables
String firstName, lastName, country, favMovie, output;
int age, siblings;
Scanner kb = new Scanner(System.in);
System.out.println("Hi there. What's your first name?");
firstName = kb.nextLine();
System.out.println("And your last name?");
lastName = kb.nextLine();
System.out.println("Next, enter your country of origin.");
country = kb.nextLine();
System.out.println("Next, enter your favorite movie.");
favMovie = kb.nextLine();
System.out.println("Just two more questions. Next, enter your age.");
age = kb.nextInt();
System.out.println("And finally, how many siblings do you have?");
siblings = kb.nextInt();
output = "Hello " + firstName +" "+ lastName +". Nice to meet you.\nYou are from "
+ country +" and your favorite movie is " + favMovie +".\nYou are "+ age +
" years old, and you indicated that you have " + siblings +" siblings.";
System.out.println(output);
System.out.println();
System.out.println("The message I printed for you in the preceding step contains "
+ output.length() +" characters.");
}//end main
} //end class