Homework 3 Due ( MT sections ) ( WTh sections ) at midnight Sun., 9/21 Mon., 9/22 Problems

Slides:



Advertisements
Similar presentations
Today’s lecture Review of Chapter 1 Go over homework exercises for chapter 1.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
Notes from HW3 / Lab3 Program documentation – At the top of every class: //************************************************************ // seu01.java Author:
Computer and Programming
Building Java Programs
Computer Programming Lab 8.
Homework 6 Due ( MT sections ) ( WTh sections ) about midnight Sun., 10/12 Mon., 10/13 Problems
Hand Crafting your own program By Eric Davis for CS103.
Homework 14 Due ( MT sections ) ( WTh sections ) at midnight Sun., 12/7 Mon., 12/8 Problems
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
COMP 110 More Loops and Strings Tabitha Peck M.S. February 18, 2008 MWF 3-3:50 pm Philips
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
CS 106 Introduction to Computer Science I 02 / 22 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 09 / 2006 Instructor: Michael Eckmann.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Homework 4 Due ( MT sections ) ( WTh sections ) at midnight Sun., 9/29 Mon., 9/30 Problems
CS 106 Introduction to Computer Science I 02 / 19 / 2007 Instructor: Michael Eckmann.
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
CS 5 Reminders Hw 3 - (3 problems) Take advantage of the tutors. Friday 8:00 am recitation section: HW hints and Q&A - their schedule is linked from the.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Introduction to Objects A way to create our own types.
DATE: ______/_______/_______NAME: ________________________________________________________________________________ Assignment: As part of our preparation.
Tutoring Dos and Donts Unofficial alien of CS 5 Gold Unofficial alien of CS 5 Black Unofficial turtle of CS 5 Green Unofficial alien of CS 42 Official.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
While Loops Indefinite Iteration. Last lesson we looked at definite loops using the ‘For’ statement. The while loop keeps going while some condition is.
More on Input Output Input Stream : A sequence of characters from an input device (like the keyboard) to the computer (the program running). Output Stream.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/23/2012 and 10/24/2012 -Using Exceptions -Homework 4.
1 CS 1430: Programming in C++. 2 Literal Values Literal values of int Literal values of float
Week 2 - Wednesday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Homework 11 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/14 Mon., 11/15 Problems
Chapter 5 Case Study. Chapter 5 The RPS Flowchart.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
This week in CS 5 HW 9 (2 problems) M/T sections W/Th sections due Sunday, 11/4 at midnight due Monday, 11/5 at midnight Recitation for HW9 -- Friday 11/2.
Homework 5 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/6 Mon., 10/7 Problems
Fundamental Programming: Fundamental Programming Introduction to C++
Making Decisions uCode: October Review What are the differences between: o BlueJ o Java Computer objects represent some thing or idea in the real.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
CMP-MX21: Lecture 4 Selections Steve Hordley. Overview 1. The if-else selection in JAVA 2. More useful JAVA operators 4. Other selection constructs in.
Logic Our programs will have to make decisions on what to do next –we refer to the decision making aspect as logic Logic goes beyond simple if and if-else.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Classes. Student class We are tasked with creating a class for objects that store data about students. We first want to consider what is needed for the.
Nelson Series Talk Wed, 9/15 7:00 pm in Galileo Macalister Transforming Mice into Men Despite some differences in appearance and habits, men and mice are.
Copyright Curt Hill The C/C++ switch Statement A multi-path decision statement.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Homework 8 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/28 Mon., 10/29 Problems Reading is under week 7, however.
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
Code Compression the benefits of looping... Today in CS 5 HW 4 - (3 problems) M/T sections W/Th sections due Sunday, 9/26 at midnight due Monday, 9/27.
Written by: Dr. JJ Shepherd
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
Chapter 7 Conditional Statements. 7.1 Conditional Expressions Condition – any expression that evaluates to true/false value Relational operators are BINARY.
Homework 10 Due ( MT sections ) ( WTh sections ) at midnight Sun., 11/10 Mon., 11/11 Problems
Information and Computer Sciences University of Hawaii, Manoa
Basic concepts of C++ Presented by Prof. Satyajit De
Lecture 3: Operators, Expressions and Type Conversion
User input We’ve seen how to use the standard output buffer
Control Statement Examples
Homework 2 Sun., 9/12 Due Mon., 9/13 Problems available on-line
CSC 113 Tutorial QUIZ I.
CMSC 202 Java Primer 2.
CISC124 Labs start this week in JEFF 155. Fall 2018
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
CSC 1051 – Data Structures and Algorithms I
Unit 3: Variables in Java
CSCE 206 Lab Structured Programming in C
Presentation transcript:

Homework 3 Due ( MT sections ) ( WTh sections ) at midnight Sun., 9/21 Mon., 9/22 Problems CS 5 website come see me or me at Submission problems? Grade Concerns?

Tutors available -- contact information

Tutors available -- lab places and times You may also seek out tutors away from the labs, by phone, in the dorms, etc. Available in the LAC Lab (Linde Activities Center) Available in Parsons PC Labs (the CIS classrooms)

Problem 3: Rock-Paper-Scissors overall structure first… you might want to use the “Evens and Odds” code available at as a starting point

Problem 3 choosing rock, paper, or scissors... class CS5App { public static void main(String[] args) { H.pl(“Welcome to RPS!”); H.p(“Be prepared for my”); H.pl(“AVALANCHE strategy!”); String cc = “”; // cc is computer’s choice How do we make the real choice? Why is this value here?

Problem 3 Let the user choose rock, paper, or scissors H.pl(“What do you show -- ”); H.p(“rock, paper, or scissors? ”); String uc = H.nl(); Three things are going on here !?!

Problem 3 Let the user choose rock, paper, or scissors Both players have chosen -- what happens next ? H.pl(“What do you show -- ”); H.p(“rock, paper, or scissors? ”); String uc = H.nl(); if ( ) { } Lots of Cases! computer chose “rock”user chose “paper” Three things are going on here !?!

Problem 2 -- Math Menu Menu of 6 options: Please choose one of these options: (0) A friendly (and random) message (1) Power computing! (2) Prof Saeta’s physics function (!*?%!) (3) Convert from seconds (4) Convert to seconds (5) Find the max and min of 4 different ints Choose an option (0-5): computer scientists tend to start counting from 0, instead of 1… There are really seven cases to consider -- why?

Problem 2 -- getting started create the general structure of the program then fill in details Outline of code: problem decomposition… you might want to use the “Moth Menu” code available at as a starting point

Different ways of making choices if … if … if … not necessarily mutually exclusive if … else if … else if … else mutually exclusive blocks of code if … else if (choice == 0) { } if (choice == 1) { } if (choice == 2) { } else { } if (choice == 0) { } else if (choice == 1) { } else if (choice == 2) { } else { }

Different ways of making choices switch mutually exclusive blocks of code as long as you use break ! switch (choice) { case 0: { break; } case 1: { break; } default: { } Why is there no need for a break in this last case?

Problem 2 -- option 0 creating a random message… (create the structure first, then details) Math.random(); recurring theme produces a double between 0 and 1 (excluding 1) but, you need to store this random number somewhere! produces a double between 0 and 3 (excluding 3) produces an int between 0 and 2 (inclusive) 0123 produces an int between 1 and 3 (inclusive) 0123

Problem 2 -- option 2 Period of a pendulum (almost!) What variables will we need?

Problem 2 -- option 2 Period of a pendulum (almost!) How to compose these operations and functions together?

Problem 2 -- option 3 from seconds years, days, hours, minutes, and seconds How many years are in 1,000,000,000 seconds? sec/year sec/day 3600 sec/hour 60 sec/min

Problem 2 -- option 4 from years, days, hours, minutes, and seconds seconds How many seconds are in 42 years?

problem outline: Problem 2 -- option 5 Finding the max and min of four different int s.

/* * Be sure to fill in this comment... */ import HMC.*; class CS5App { public static void main(String[] args) { int a, b, c, d; H.out.println(“Input four integers:”); a = H.in.nextInt(); b = H.in.nextInt(); c = H.in.nextInt(); d = H.in.nextInt(); Input Problem 2 -- option 5

// is a the smallest among them ? if ( ) { H.out.println(“The smallest integer is ” + a); } // is b the smallest among them ? if ( ) { H.out.println(“The smallest integer is ” + b); } // and so on… // with a similar construction for the max Min Problem 2 -- option 5 How many comparisons will this take (in the worst case)?

Problem 1 The Virtual Lyricist or, perhaps, conversationalist class CS5App { public static void main(String[] args) { H.p(“Enter your favorite mascot: ”); String mascot = H.nl(); H.pl(“Here we go, ” + mascot); H.pl(“Here we go!”); } Use at least 4 variables What’s the effect of this H.p ?

Problem 1 class CS5App { public static void main(String[] args) { H.p(“Enter your favorite mascot: ”); String mascot = H.nl(); H.pl(“Here we go, ” + mascot); H.pl(“Here we go!”); H.p(“Enter an enemy mascot: ”); String mascot = H.nl(); H.pl(“Here we go, ” + mascot); H.pl(“Here we go!”); } What’s wrong here?!

Problem 1 class CS5App { public static void main(String[] args) { H.p(“Enter your favorite mascot: ”); String mascot = H.nl(); H.pl(“Here we go, ” + mascot); H.pl(“Here we go!”); H.p(“Enter an enemy mascot: ”); mascot = H.nl(); H.pl(“Here we go, ” + mascot); H.pl(“Here we go!”); } declaring the variable -- can be done once! assigning the variable -- can be done any time... using the variable -- done any time...

Input: Know your type! H.in.nextWord(); H.in.nextLine(); H.in.nextInt(); H.in.nextLong(); H.in.nextChar(); H.in.nextDouble(); H.in.nextAnyChar(); H.nw(); H.nl(); H.nc(); H.nanyc(); H.ni(); H.nlong(); H.nd(); shortcuts ! return a String return a char returns an int returns a long returns a double including whitespace

Style /* * Author: me! * Date: 9/20/03 * Homework 3 * Problem 2 * Comment: I spent 10 hours on this problem * (in binary) */ class CS5App { public static void main(String[] args) { H.p(“Enter your favorite mascot: ”); String mascot = H.in.nextWord(); … more code here … } leave space before blocks of code leave space between parts of code that do different things introductory comment indent code evenly within the surrounding braces align curly braces that correspond use reasonable variable names