3. More Loops Intro To Methods and String Type:

Weekly Overview of Programming Concepts

  • Date of Session: September 16, 2023

  • Overview of concepts covered in prior sessions using a division program as a context.

Completed Topics
  • Programming Fundamentals Using Division Program:

    • The division program will be used to cover several programming concepts essential to the course.

    • Objective: Explore foundational programming concepts while minimizing cognitive overhead related to problem complexity.

  • Subjects Covered:

    • Data Types: Introduction to front data types and explanation of how to use them.

    • Loops and Functions: Understanding loops and methods, their significance in creating reusable code (e.g., a function for division, data input, and report printing).

    • Arrays and Parallel Arrays:

    • Implementation in COP 1,000.

    • Storing results of multiple divisions in an array format, such as: - One array for student names

      • One array for division results

      • One array for calculated quotients

  • Input Validation:

    • Checking if denominators are zero and providing users with unlimited attempts to enter a non-zero denominator.

    • Implementation of logical conditions using various methods to validate user input (e.g., validating yes/no responses using binary).

  • Introduction to Compound Statements:

    • Use of compound statements with conditions using "and" and "or".

    • Required for structured programming and controlling program flow.

  • Practice Assignment:

    • Related to financial aid program criteria involving student eligibility based on income and family size.

    • Emphasis on avoiding the use of AI-generated outputs for graded assignments.

Current Session Objectives
  • New Topics To Be Covered: - Logic and its importance in programming.

    • Explanation of financial aid eligibility criteria and how to determine it programmatically.

Assignment Instructions and Structure of Financial Aid Evaluation Program
  • Inputs Required:

    • Annual income

    • Family size

  • Eligibility Logic:

    • A student is eligible if:

    • Annual income <= 15,000

    • AND family size >= 3

    • If a student is a veteran, they are automatically eligible regardless of income or family size.

Sample Implementation of the Program:

  • The following sample shows how to write the program to evaluate financial aid eligibility. Below is a step-by-step explanation for beginners, describing each part of the code as if highlighted in an IDE.

import java.util.Scanner;

public class FinancialAidV1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double annualIncome;
        int familySize;
        boolean isVet;

        System.out.println("Enter annual income:");
        annualIncome = scanner.nextDouble();

        System.out.println("Enter family size:");
        familySize = scanner.nextInt();

        System.out.println("Is the student a veteran? (true/false):");
        isVet = scanner.nextBoolean();

        if ((annualIncome <= 15000 && familySize >= 3) || isVet) {
            System.out.println("Student is eligible for financial aid.");
        } else {
            System.out.println("Student is not eligible for financial aid.");
        }

        scanner.close();
    }
}

Step-by-Step Code Explanation:

For a beginner, imagine the code elements are highlighted with different colors by an editor to make them easier to understand.

  1. import java.util.Scanner;

    • import (like a keyword): This tells Java that our program will use something special from Java's built-in libraries. Think of it as importing a tool from a toolbox.

    • java.util.Scanner (like a class/type): This specific tool is called Scanner, and it's used to read input from the user (like numbers or text typed on the keyboard).

  2. public class FinancialAidV1 { ... }

    • public (like a keyword): This means the class is accessible from anywhere. It's like saying this part of the code is public for anyone to use.

    • class (like a keyword): In Java, all code lives inside classes. A class is like a blueprint for creating objects, or a container for related code.

    • FinancialAidV1 (like a class name): This is the name given to our program's main class. It's customary to start class names with a capital letter.

    • { ... } (curly braces): These define the start and end of the class's code block.

  3. public static void main(String[] args) { ... }

    • public static void main (like a special method signature): This is the entry point of every Java application. When you run a Java program, it always looks for and starts executing code inside this method first.

      • static: Means this method belongs to the FinancialAidV1 class itself, not to a specific object created from the class. You can run it without creating an instance of FinancialAidV1.

      • void: Means this method does not return any value after it finishes its job.

      • main: The standard name for the method where program execution begins.

    • (String[] args): This is where command-line arguments (extra information you might give the program when you start it) would go. For this program, we don't use them, but it's required for the main method.

    • { ... } (curly braces): These define the start and end of the main method's code block.

  4. Scanner scanner = new Scanner(System.in);

    • Scanner (like a data type): We're declaring a variable that can hold a Scanner object.

    • scanner (like a variable name): This is the name we chose for our Scanner object. You'll use this name whenever you want to read input.

    • = (assignment operator): Assigns the value on the right to the variable on the left.

    • new Scanner(System.in) (creating an object): This creates a new Scanner object that's configured to read input from the standard input stream, which is typically your keyboard.

    • ; (semicolon): In Java, almost all statements must end with a semicolon. Think of it as the period at the end of a sentence.

  5. double annualIncome;, int familySize;, boolean isVet;

    • double, int, boolean (like data types): These are keywords that declare the type of data each variable will hold.

      • double: Used for numbers that might have decimal places (e.g., 15000.50).

      • int: Used for whole numbers (integers) without decimal places (e.g., 3, 15000).

      • boolean: Used for true/false values (e.g., true or false). These are crucial for logic.

    • annualIncome, familySize, isVet (like variable names): These are the names of our variables. They should be descriptive so you know what kind of information they store. Variable names usually start with a lowercase letter.

    • ;: Each variable declaration ends with a semicolon.

  6. System.out.println("Enter annual income:");

    • System.out.println (like a method call): This is a standard method in Java used to print text to the console (the screen where your program output appears). Think of it as