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
  • ScannerExample.java
  • ScannerExample2.java
  • M1Assignment.java
  1. Module 1

Source Code

ScannerExample.java

// import all the classes and interfaces from the java.util package into your program.
import java.util.*;

public class ScannerExample {
    public static void main(String[] args) {
        System.out.println("Scanner Example Code");

        // 1. Print a message to the user
        

        // 2. Initialize the Scanner. Declare a variable named in
        // that reads from System.in
        

        // 3. Create a variable and assign it to the value returned by nextLine
        // The Scanner class provides a method called nextLine that reads a
        // line of input from the keyboard and returns a String.
        

        // 4. Print the value of the variable
        
        
        // 5. Close the Scanner
        

    }
}

ScannerExample2.java

import java.util.*;

public class ScannerExample2 {
    public static void main(String[] args) {
        System.out.println("Scanner Example 2 Code");

        Scanner in = new Scanner(System.in);
        System.out.print("What's your age? ");
        int age = in.nextInt();
        // add code to fix the "Scanner bug"

        System.out.print("What's your name? ");
        String line = in.nextLine();
        System.out.println("Name: " + line);
        System.out.println("Age: " + age);
        in.close();
    }
}

M1Assignment.java

import java.util.*;

public class M1Assignment {
    public static void main(String[] args) {
        System.out.println("Module 1 Assignment");
        Scanner in = new Scanner(System.in);
        
        
        
        
        
        
        in.close();
    }
}
PreviousLecture VideosNextAssignment

Last updated 1 year ago