CS 2421 Object Oriented Programming in Java
  • CS 2421 Object Oriented Programming in Java
  • Module 1
    • Presentations
    • Lecture Videos
    • Source Code
    • Assignment
  • Module 2
    • Presentations
    • Lecture Videos
    • Source Code
    • Assignment
  • Module 3
    • Presentations
    • Lecture Videos
    • Source Code
    • Assignment
  • Module 4
    • Presentations
    • Lecture Videos
    • Source Code
    • Assignment
  • Module 5
    • Presentations
    • Videos
    • Source Code
    • Assignment
  • Module 6
    • Presentations
    • Videos
    • Source Code
    • Assignment
Powered by GitBook
On this page
  • Conditionals.java
  • Menu.java
  • IncrementOperators.java
  • LoopExamples.java
  • FileExamples.java
  • MenuLoop.java
  1. Module 2

Source Code

Conditionals.java

public class Conditionals {
    public static void main(String[] args) {
        System.out.println("Conditionals Examples");
        // Example 1

        // Example 2

        // Example 3
 
        // Example 4

        // Example 5

        // Example 6
        
        // Example 7
        
        // Example 8

        // Example 9

        // Example 10
 

        // version 1


        // version 2


        // Example 11


    }
}

Menu.java

import java.util.*;

public class Menu {
    public static void main(String[] args) {
    System.out.println("Menu Examples");
        // Menu


        // setup Scanner


        // switch choices


    }
}

IncrementOperators.java

import java.util.*;

public class IncrementOperators {
    public static void main(String[] args) {
        // Menu
        System.out.println("Menu");
        System.out.println("E1 - Example 1");
        System.out.println("E2 - Example 2");
        System.out.println("Q  - Quit");

        // setup Scanner
        Scanner in = new Scanner(System.in);
        System.out.print("Choice: ");
        String choice = in.nextLine();

        // switch choices
        switch (choice) {
            case "E1":
                System.out.println("Example 1");

                break;
            case "E2":
                System.out.println("Example 2");
 
                break;
            case "Q":
                System.out.println("Quit");
                break;
            default:
                System.out.println("Invalid Choice");
                break;
        }
    }
}

LoopExamples.java

import java.util.*;

public class LoopExamples {
    public static void main(String[] args) {
        // Menu
        System.out.println("Menu");
        System.out.println("E1 - Example 1");
        System.out.println("E2 - Example 2");
        System.out.println("E3 - Example 3");
        System.out.println("E4 - Example 4");
        System.out.println("E5 - Example 5");
        System.out.println("E6 - Example 6");
        System.out.println("E7 - Example 7");
        System.out.println("E8 - Example 8");
        System.out.println("Q  - Quit");

        // setup Scanner
        Scanner in = new Scanner(System.in);
        System.out.print("Choice: ");
        String choice = in.nextLine();

        // switch choices
        switch (choice) {
            case "E1":
                System.out.println("Example 1");

                break;
            case "E2":
                System.out.println("Example 2");

                break;
            case "E3":
                System.out.println("Example 3");

                break;
            case "E4":
                System.out.println("Example 4");

                break;
            case "E5":
                System.out.println("Example 5");

                break;
            case "E6":
                System.out.println("Example 6");

            case "E7":
                System.out.println("Example 7");

                break;
            case "E8":
                System.out.println("Example 8");

                break;
            case "Q":
                System.out.println("Quit");
                break;
            default:
                System.out.println("Invalid Choice");
                break;
        }
    }
}

FileExamples.java

import java.util.*;
import java.io.*;

public class FileExamples {
    public static void main(String[] args) throws FileNotFoundException, IOException {
        // Menu
        System.out.println("Menu");
        System.out.println("E1 - Example 1");
        System.out.println("E2 - Example 2");
        System.out.println("E3 - Example 3");
        System.out.println("Q  - Quit");

        // setup Scanner
        Scanner in = new Scanner(System.in);
        System.out.print("Choice: ");
        String choice = in.nextLine();

        // switch choices
        switch (choice) {
            case "E1":
                System.out.println("Example 1");
                // setup PrintWriter

                // Writing lines to the file
                
                // Flushing and closing the writer
                
                break;
            case "E2":
                System.out.println("Example 2");
                // Open the file
                
                // Read lines from the file until no more are left
               
                break;
            case "E3":
                System.out.println("Example 3");
                // Open the file
                
                // Writing lines to the file
                
                // Flushing and closing the writer
                
                break;
            case "Q":
                System.out.println("Quit");
                break;
            default:
                System.out.println("Invalid Choice");
                break;
        }
    }
}

MenuLoop.java

import java.util.*;

public class MenuLoop {
    public static void main(String[] args) {
        System.out.println("Menu Loop");
        // Create new Scanner object (don't delete!)
        Scanner in = new Scanner(System.in);
        // menu variables
        boolean done = false;
        String choice;
        // do while menu loop
        do {
            System.out.println("E1 - Example 1");
            System.out.println("E2 - Example 2");
            System.out.println("E3 - Example 3");
            System.out.println("Q - Quit");
            System.out.print("Choice: ");
            choice = in.nextLine();
            switch (choice) {
                case "E1":
                    System.out.println("Example 1");
                    
                    break;
                case "E2":
                    System.out.println("Example 2");
                    
                    break;
                case "E3":
                    System.out.println("Example 3");
                    // Create a random object to generate random numbers
                    

                    break;
                // quit and default cases
                case "Q":
                    System.out.println("Quit");
                    done = true;
                    break;
                default:
                    System.out.println("Invalid Choice");
                    break;
            }
        } while (!done);

        // close the Scanner (don't delete!)
        in.close();
    }
}
PreviousLecture VideosNextAssignment

Last updated 1 year ago