Skip to the content.

variables

Student Teaching Lesson

Popcorn Hack 1

public class MyFavoriteThings {
    public static void main(String[] args) {
        // Try writing your own code here first!
        
        // Sample answer:
        String favoriteFood = "Sushi";
        int myAge = 16;
        double heightInFeet = 5.2;
        boolean likesPizza = true;
        char colorFirstLetter = 'R';  
        final int BIRTH_YEAR = 2009;
        
        System.out.println("Favorite food: " + favoriteFood);
        System.out.println("Age: " + myAge);
        System.out.println("Height: " + heightInFeet + " feet");
        System.out.println("Likes pizza: " + likesPizza);
        System.out.println("Favorite color starts with: " + colorFirstLetter);
        System.out.println("Born in: " + BIRTH_YEAR);
    }
}
//req to run main driver
MyFavoriteThings.main(null);
Favorite food: Sushi
Age: 16
Height: 5.2 feet
Likes pizza: true
Favorite color starts with: R
Born in: 2009

Popcorn Hack 2

public class PickTheType {
    public static void main(String[] args) {
        // 1. Number of siblings → int (counting, whole number)
        int siblings = 2;
        
        // 2. Your first name → String (text/words)
        String firstName = "Nora";
        
        // 3. Are you hungry? → boolean (yes/no, true/false)
        boolean isHungry = true;
        
        // 4. Your favorite letter → char (single letter)
        char favoriteLetter = 'N';
        
        // 5. Your height in inches → double (might be decimal like 65.5)
        // (Can also be int if your height is a whole number)
        double heightInches = 62.2;
        
        // 6. Days in a year → final int (never changes, whole number)
        final int DAYS_IN_YEAR = 365;
        
        System.out.println("Siblings: " + siblings);
        System.out.println("Name: " + firstName);
        System.out.println("Hungry: " + isHungry);
        System.out.println("Favorite letter: " + favoriteLetter);
        System.out.println("Height: " + heightInches + " inches");
        System.out.println("Days per year: " + DAYS_IN_YEAR);
    }
}

PickTheType.main(null);
Siblings: 2
Name: Nora
Hungry: true
Favorite letter: N
Height: 62.2 inches
Days per year: 365

Homework Hack

import java.util.Scanner;

public class GradeCalculator {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);

        // Final variables (cannot be changed later)
        final String studentName;
        final String className;

        // Get student info
        System.out.print("Enter student's name: ");
        studentName = input.nextLine();

        System.out.print("Enter class name: ");
        className = input.nextLine();

        // Get test scores
        System.out.print("Enter score 1 (0-100): ");
        int score1 = input.nextInt();

        System.out.print("Enter score 2 (0-100): ");
        int score2 = input.nextInt();

        System.out.print("Enter score 3 (0-100): ");
        int score3 = input.nextInt();

        // Calculate average
        double average = (score1 + score2 + score3) / 3.0;

        // Determine letter grade
        char letterGrade;
        if (average >= 90) {
            letterGrade = 'A';
        } else if (average >= 80) {
            letterGrade = 'B';
        } else if (average >= 70) {
            letterGrade = 'C';
        } else if (average >= 60) {
            letterGrade = 'D';
        } else {
            letterGrade = 'F';
        }

        // Display results
        System.out.println("\n--- Grade Report ---");
        System.out.println("Student: " + studentName);
        System.out.println("Class: " + className);
        System.out.println("Average Score: " + average);
        System.out.println("Letter Grade: " + letterGrade);

        input.close();
    }
}

GradeCalculator.main(null);
Enter student's name: Enter class name: Enter score 1 (0-100): Enter score 2 (0-100): Enter score 3 (0-100): 
--- Grade Report ---
Student: Nora
Class: Compsci
Average Score: 90.33333333333333
Letter Grade: A