← Back to Midterms

Java Coding on Paper

Explanation & Learnings

During this seatwork, we coded a problem on paper. It was about a student payment system, handling discounts and typical balance checking. It was hard for me as the lesson is still fresh inside my mind, and I'm still processing everything. Though, I learned how to make programs using the Scanner class for user input. Writing the logic on paper helped me realize that increment/decrement operators become much trickier when combined with Switch-Break and If-Else statements but I managed. The most important part was tracing exactly when a variable updates before the next line of code executes. Below is some of the rough code/logic I used for this seatwork.

SeatworkScanner.java
import java.util.Scanner;

Scanner sc = new Scanner(System.in);
int a = sc.nextInt(); // Input: 10
int b = sc.nextInt(); // Input: 5

int choice = sc.nextInt();

switch (choice) {
    case 1:
        // Post-increment: uses 10, then a becomes 11
        int result = a++ + b; 
        break;
    case 2:
        // Pre-decrement: b becomes 4, then used
        int result = a + --b;
        break;
}

if (a > 10) {
    System.out.print("Incremented");
} else {
    System.out.print("Original");
}

Refining the code into scanner syntax made me realize how crucial the "break;" statement is to prevent "fall-through" logic, and how "if-else" helps in making logic or error handling.