COMP 110 More Loops and Strings Tabitha Peck M.S. February 18, 2008 MWF 3-3:50 pm Philips 367 1.

Slides:



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

Using factors to find the prime factorization of a number
Hand Crafting your own program By Eric Davis for CS103.
Review Question What kind error is it when I try to multiply a number in a program by 1000 and store in a variable, but the variable is too small for the.
Introduction to working with Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
COMP 110 Introduction to Programming Tabitha Peck M.S. January 9, 2008 MWF 3-3:50 pm Philips 367.
1 COMP 110 Inheritance Tabitha Peck M.S. April 16, 2008 MWF 3-3:50 pm Philips 367.
Introduction to Computers and Programming Lecture 7:
1 COMP 110 Static Methods and Variables Tabitha Peck M.S. March 24, 2008 MWF 3-3:50 pm Philips 367.
Chapter 4 - Control Structures: Part 1 Outline 4.4Control Structures 4.5The if Selection Structure 4.6The if/else Selection Structure 4.7The while Repetition.
COMP 110 Loops Tabitha Peck M.S. February 11, 2008 MWF 3-3:50 pm Philips
1 COMP 110 Arrays Tabitha Peck M.S. March 31, 2008 MWF 3-3:50 pm Philips 367.
COMP 110 Objects and References Tabitha Peck M.S. February 27, 2008 MWF 3-3:50 pm Philips
1 COMP 110 More Arrays Tabitha Peck M.S. April 2, 2008 MWF 3-3:50 pm Philips 367.
COMP 110 Classes Tabitha Peck M.S. February 20, 2008 MWF 3-3:50 pm Philips
 2002 Prentice Hall. All rights reserved. 1 Intro: Java/Python Differences JavaPython Compiled: javac MyClass.java java MyClass Interpreted: python MyProgram.py.
1 COMP 110 Designing and Overloading Methods Tabitha Peck M.S. March 26, 2008 MWF 3-3:50 pm Philips 367.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
COMP 14 Introduction to Programming Mr. Joshua Stough March 30, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
COMP 110 Designing Programs Tabitha Peck M.S. January 16, 2008 MWF 3-3:50 pm Philips
COMP 110 Primitive Types, Strings, and Console I/O Tabitha Peck M.S. January 23, 2008 MWF 3-3:50 pm Philips
Review. By the end of today you should be able to- Know how to use args Know how to use the JOptionPane Know how to convert a String to a number.
COMP 110 If / Else and Case Statements Tabitha Peck M.S. February 4, 2008 MWF 3-3:50 pm Philips
COMP 110 Errors, Strings, and Review Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
COMP 110 Branching Statements and Boolean Expressions Tabitha Peck M.S. January 28, 2008 MWF 3-3:50 pm Philips
COMP 110 Switch Statements and Loops Tabitha Peck M.S. February 6, 2008 MWF 3-3:50 pm Philips
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Tutorial 7 – Class Average Application: Introducing.
COMP 110 Classes Tabitha Peck M.S. March 3, 2008 MWF 3-3:50 pm Philips
Lecture 7. Review Homework 1 (sample solution) Project 1 will be assigned next week –Draw a picture (whatever you want) in the world by using turtles.
COMP 110 Information Hiding and Encapsulation Tabitha Peck M.S. February 25, 2008 MWF 3-3:50 pm Philips
Computer Programming Lab(5).
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
Lecture 10 Instructor: Craig Duckett Lecture 10 is in Lecture 11 Folder.
Getting Started with Java Recitation – 1/23/2009 CS 180 Department of Computer Science, Purdue University.
Computer Programming TCP1224 Chapter 4 Variables, Constants, and Arithmetic Operators.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Math class services (functions) Primitive vs reference data types Scanner class Math class services (functions) Primitive vs reference data types Scanner.
Agenda Review C++ Library Functions Review User Input Making your own functions Exam #1 Next Week Reading: Chapter 3.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Homework 3 Due ( MT sections ) ( WTh sections ) at midnight Sun., 9/21 Mon., 9/22 Problems
1 CSC 110AA Introduction to Computer Science for Majors - Spring 2003 Class 5 Chapter 2 Type Casting, Characters, and Arithmetic Operators.
The String Class A String is an object. An object is defined by a class. In general, we instantiate a class like this: String myString = new String(“Crazy.
COMP 110 switch statements and while loops Luv Kohli September 10, 2008 MWF 2-2:50 pm Sitterson
02 Variables1November Variables CE : Fundamental Programming Techniques.
COMP Flow of Control: Branching 1 Yi Hong May 19, 2015.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
Mathematical Calculations in Java Mrs. C. Furman.
Catie Welsh February 2,  Program 1 Due Today by 11:59pm today  Program 2 Assigned Today  Lab 2 Due Friday by 1:00pm 2.
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
1 10/3/05CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 Class Chapter Objectives Use a while loop to repeat a series of statements Get data from user through an input dialog box Add error checking.
Introduction to Computers and Programming Lecture 7:
COMP 110 Branching Statements and Boolean Expressions Luv Kohli September 8, 2008 MWF 2-2:50 pm Sitterson
COMP 110 Designing and overloading methods Luv Kohli November 3, 2008 MWF 2-2:50 pm Sitterson 014.
Casting, Wrapper Classes, Static Methods, JOptionPane Class.
Catie Welsh February 14,  Program 2 Due Tonight by 11:59pm  Program 3 Assigned 2.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
Instructor: Kelley Edds.  Everything is due by 11:59pm (EST)  Please communicate to me if something comes up and you can not turn your assignment in.
Unit 1 Seminar Welcome to MM150! To resize your pods:
UMBC CMSC 104 – Section 01, Fall 2016
using System; namespace Demo01 { class Program
Dialogues and Wrapper Classes
Michele Weigle - COMP 14 - Spr 04
COMP 110 Loops, loops, loops, loops, loops, loops…
Chapter 2: Java Fundamentals cont’d
Python Creating a calculator.
Presentation transcript:

COMP 110 More Loops and Strings Tabitha Peck M.S. February 18, 2008 MWF 3-3:50 pm Philips 367 1

Announcements Programs START EARLY!!!! Should take hours Should NOT take 20+ hours Get help if you are stumped Office hours are helpful Read Instructions 2

Announcements Program 2 Format to 2 decimal places Convert floating point numbers to integers for modular arithmetic String parsing Comments and pseudocode 3

Program 2 Grades 101% - 110%9 90% - 100%13 80% - 89%5 70% - 79%2 0% - 69%2

Formatting Decimals (Jan 30) import java.text.*; DecimalFormat df = new DecimalFormat("0.00"); df.format(myVariable); Example code on class website 5

import java.text.DecimalFormat; public class DecFormat { public static void main(String[] args) { DecimalFormat df = new DecimalFormat("0.00"); DecimalFormat df2 = new DecimalFormat("0.0000"); double d = ; System.out.println("my double with two decimal places: " + df.format(d)); System.out.println("my double with four decimal places: " + df2.format(d)); } 6

Converting to Integers “You must convert floating-point numbers to integers to perform modular arithmetic.” Modular arithmetic is defined for integers!!! Type Casting (Jan 23) myInt = (int)myFoat; answer = (int)operand1 % (int) operand2; 7

String parsing Lab 2 Requests for more practice Today == More Practice

Comments double answer = op1 + op2; answer = 100*answer; int ans = (int)answer; answer = (double)ans; answer = answer/100; JOptionPane.showMessageDialog(null, inputString + " = " + answer);

Comments /*For every calculation here on out, once the original operation is done, the answer is multiplied by 100, changed to an integer, then divided by 100 in order to give it the two decimal places required by the assignment. This comment will not be repeated for these operations again.*/

Pseudocode Figure out how to solve the problem BEFORE you start coding Who had a hard time parsing the input string? What if you spent an hour before coding thinking about how to solve it?

“I originally had a little trouble trying to figure out how to start (program2) as well. But on the way home Friday, it hit me that the user was inputting a string and that string had to be converted to the parts needed. Since the user was required to input a string with spaces, I figured using the spaces to convert the needed information would be the easiest way.”

Pseudocode Input a string (“num operator num”) Hmm? There is a space between everything. Find index of first space Get substring from beginning to first space Convert to double

Pseudocode Once you think about how to solve the problem… Then you start coding

Announcements (continued) Project 3 Assigned today Due March 4 If you have problems come see me (soon) Coming to class late…

You should… NOT spend > 10 hours per week on this class (on average) start assignments early get help if you are stumped (before you get frustrated) Read the assignment carefully

Questions? Suggestions / concerns / comments Please send them to me 17

Today in COMP 110 Practice String Parsing Practice loops - code on web Worksheet hand in for class participation Answers posted on website tonight 18

Wednesday Classes you will need this for program 3 19