Lecture 8 Instructor: Craig Duckett. Assignments TONIGHT Lecture 8 Assignment 2 Due TONIGHT Lecture 8 by midnight Monday, February 2 nd Lecture 10 Assignment.

Slides:



Advertisements
Similar presentations
Review pages for the AP CS Exam
Advertisements

Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Socratic seminar 13- end, collect SR, LL conference HW: quiz over Monday: Socratic seminar 13-end, collect SR, LL conference Wednesday: ACT day,
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Iterations for loop. Outcome Introduction to for loop The use of for loop instead of while loop Nested for loops.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Introduction to Programming Overview of Week 2 25 January Ping Brennan
Introduction to Programming
Introduction to Programming
Introduction to Programming Java Lab 2: Variables and Number Types 1 JavaLab2 lecture slides.ppt Ping Brennan
Introduction to Programming Java Lab 5: Boolean Operations 8 February JavaLab5 lecture slides.ppt Ping Brennan
Introduction to Programming
Lecture 5 Types, Expressions and Simple I/O COMP1681 / SE15 Introduction to Programming.
Lecture 10 Flow of Control: Loops (Part 2) COMP1681 / SE15 Introduction to Programming.
Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
Procedural Programming in C# Chapters Objectives You will be able to: Describe the most important data types available in C#. Read numeric values.
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
Programming Methodology (1). public class Hello { public static void main(String[] args) { System.out.println("Hello world"); } } Hello world.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Chapter 8: Arrays.
This is Java Jeopardy.
1.A computer game is an example of A.system software; B.a compiler; C.application software; D.hardware; E.none of the above. 2.JVM stands for: A.Java Virtual.
Chapter 5 Loops Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Computer Programming Lab(7).
Java Math Class. What is the Math Class? The Math Class is another class that is prepared by Java for us to use We use this class for mathematical operations.
Building Java Programs Interactive Programs w/ Scanner What is a class? What is an object? What is the difference between primitive and object variables?
Chapter 10 Ch 1 – Introduction to Computers and Java Streams and File IO 1.
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
L6:CSC © Dr. Basheer M. Nasef Lecture #6 By Dr. Basheer M. Nasef.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 3 Loops.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.1 Chapter 3 Selections.
Building Java Programs
Computer Programming Lab 8.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Lecture 17 Instructor: Craig Duckett Passing & Returning Arrays.
Lecture 6a Instructor: Craig Duckett. Upcoming Assignments & Mid-Term Assignment 1 Revision Assignment 1 Revision is due NEXT Wednesday, July 29 th, by.
Lecture 10 Instructor: Craig Duckett Lecture 10 is in Lecture 11 Folder.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Java Data Types Assignment and Simple Arithmetic.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Lesson 4 Input. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are using. The reason it is not.
Introduction to Computing Concepts Note Set 12. Writing a Program from Scratch public class SampleProgram1 { public static void main (String [] args)
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
CSC 1051 – Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Introduction to Programming Lecture 4. Key Words of C main main if if else else while while do do for for.
Lecture 11 Instructor: Craig Duckett. Announcements Assignment 1 Revision DUE TONIGHT February 10 th In StudentTracker by midnight If you have not yet.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to programming in java
Lecture 4.1: More on Scanner, Methods, and Codingbat Michael Hsu CSULA.
Lecture 4 – Scanner & Style
CompSci 230 S Programming Techniques
BIT 115: Introduction To Programming
Lecture 2 D&D Chapter 2 & Intro to Eclipse IDE Date.
BIT 115: Introduction To Programming
Introduction to programming in java
Chapter 2 Basic Computation
Chapter 2 More on Math More on Input
TemperatureConversion
2.5 Another Java Application: Adding Integers
BIT115: Introduction to Programming
Introduction to Classes and Methods
MSIS 655 Advanced Business Applications Programming
BIT115: Introduction to Programming
Presentation transcript:

Lecture 8 Instructor: Craig Duckett

Assignments TONIGHT Lecture 8 Assignment 2 Due TONIGHT Lecture 8 by midnight Monday, February 2 nd Lecture 10 Assignment 1 Revision due Lecture 10 by midnight Next Monday, February 9 th Lecture 12 Assignment 2 Revision Due Lecture 12 by midnight Wednesday, February 18 th We'll Have a Look at Assignment 3 at the End of Lecture

4 Assignment 2 (LECTURE 8) DUE TONIGHT Monday, February 2 Assignment 1 Revision (LECTURE 10) Monday, February 9 Assignment 2 Revision (LECTURE 12) Wednesday, February 18 Assignment 3 (LECTURE 13) Monday, February 23 Assignment 3 Revision (LECTURE 16) Wednesday, March 4 Assignment 4 (LECTURE 18) Wednesday, March 11 Assignment 4 Revision (LECTURE 19) Monday, March 16 Assignment Dates

MID-TERM Mid-Term is LECTURE 9, this Wednesday, February 4 th Please be prompt, and bring a pencil … don’t worry, I’ll supply the paper

Lecture 8 and Going Forward Lecture 8 ENDS THE FIRST PHASE OF THE QUARTER --- WHAT THIS MEANS, AFTER THE MID-TERM: Less Theory, More Hands-On Work (Less means Less, not No) Less Hand-Holding, More Trial-and-Error Less Explanation, More Research & Investigation, More Poking Around For Code, More “Googling It” and More (Occasionally) Aggravation Becker – Chapters 9.4, 9.5: Input System.in The Scanner Class

But First… The Quiz!

Chapter 9.4, 9.5: Input The Scanner Class To read input from the keyboard we can use the Scanner class. Like Random, the Scanner class is defined in java.util, so again we will use the following statement at the top of our programs: import java.util.*; or import java.util.Scanner;

The Scanner Class Scanner objects work with System.in To create a Scanner object: Scanner keyboard = new Scanner(System.in); NOTE: Like any other object, keyboard here is a name “made up” by the coder and can be called anything—input, feedIine, keyIn, data, stuffComingFromTheUser, etc.—although it should represent a word most apt to its purpose. In this case we are using keyboard since it seems most apt.

Example: ReadConsole.java import java.util.Scanner; // Or import java.util.*; public class ReadConsole { public static void main(String[] args) { Scanner cin = new Scanner(System.in); System.out.print("Enter an integer: "); int a = cin.nextInt(); System.out.print("Enter an integer: "); int b = cin.nextInt(); System.out.println(a + " * " + b + " = " + a * b); } } A NOTE about Integer Division

New Scanner Methods These are for ints (integers). There are also Scanner methods available for floats, etc, which we'll see later on in the quarter nextInt() Does something with the int hasNextInt() Checks to see if there is an int nextLine() Replaces the int in the keyboard buffer with a newline character so the program won't use the int again

Integer Division Division can be tricky. In a Java program, what is the value of X = 1 / 2? You might think the answer is 0.5… But, that’s wrong. The answer is simply 0. Integer division will truncate any decimal remainder. If you are going to divide and need a decimal, then your must use either the float or double types.

import java.util.Scanner; // Or import java.util.*; public class ReadConsoleChecked { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int a = 0; while (true) // <-- A new kind of while loop we haven’t talked about yet { System.out.print("Enter an integer: "); if (keyboard.hasNextInt()) // Checks to see whether an int has been typed in keyboard { a = keyboard.nextInt(); keyboard.nextLine(); // newline flush to “clear the buffer” break; // <-- We haven’t talked about break yet either } else { String next = keyboard.nextLine(); // newline flush System.out.println(next + " is not an integer such as 10 or -3."); } } int b = 0; while (true) // <-- A new kind of while loop { System.out.print("Enter an integer: "); if (keyboard.hasNextInt()) { b = keyboard.nextInt(); keyboard.nextLine(); // newline flush break; } else { String next = keyboard.nextLine(); // newline flush System.out.println(next + " is not an integer such as 10 or -3."); } } System.out.println(a + " * " + b + " = " + a * b); } }

New Scanner Methods These are for ints (integers). There are also Scanner methods available for floats, etc, which we'll see later on in the quarter nextInt() Does something with the int hasNextInt() Checks to see if there is an int nextLine() Replaces the int in the keyboard buffer with a newline character so the program won't use the int again

A Closer Look: Basic_Keyboard_IO.java

A Look at Assignment 3 "The Maze"

A Closer Look: The ICE Exercises else { System.out.println("You have not input a valid integer"); keyboard.nextLine(); }