Some problems for your consideration

Slides:



Advertisements
Similar presentations
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Advertisements

1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Money Coin Game By Joe Hart Click here to begin Click here to enter your name.
USING MONEY: COUNTING, ADDING AND SUBTRACTING COUNTING MONEY AND USING IT TO ADD AND SUBTRACT.
COMP 14 Introduction to Programming Miguel A. Otaduy May 19, 2004.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
CS 112 Intro to Computer Science II Sami Rollins Fall 2006.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
1 Session-I & II CSIT-121 Spring 2006 Session Targets Introducing the VC++.NET Solving problems on computer Programming in C++ Writing and Running Programs.
1 September 6, 2005CS150 Introduction to Computer Science I What Actions Do We Have Part 1 CS150 Introduction to Computer Science I.
Variables, Data Types, & Arithmetic Expressions CSC 1401: Introduction to Programming with Java Lecture 3 Wanda M. Kunkle.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
COMP 110 Introduction to Programming Mr. Joshua Stough September 10, 2007.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Control Structures II. Why is Repetition Needed? There are many situations in which the same statements need to be executed several times. Example: Formulas.
I wonder who has more money…. 1 dollar, 3 nickels, 5 dimes 6 dimes, 3 pennies, 5 quarters 8 pennies, 6 nickels, 3 dimes 2 half dollars, 5 pennies, 8 nickels.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.
© Copyright 1992–2005 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Looping Exercises Deciding Which Loop to Use At this.
Problem Solving and Program Design in C (5th Edition) by Jeri R. Hanly and Elliot B. Koffman CPCS 202 Chapter 2 – Input/Output
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Primitive Types, Strings, and Console I/O Chapter 2.1 Variables and Values Declaration of Variables Primitive Types Assignment Statement Arithmetic Operators.
Basic Computation Module 2. Objectives Describe the Java data types used for simple data Write Java statements to declare variables, define named constants.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Click for the next screen. Money Content Standard: Find a combination of coins that equals a given value Click for the next screen.
Chapter 2: Java Fundamentals
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 3: Numerical Data Manipulating Numbers Variables.
CSE 201 – Elementary Computer Programming 1 Extra Exercises Source: Suggested but not selected midterm questions.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
A First Look at Java Chapter 2 1/29 & 2/2 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Counting Coins. The Basics Quarter 25 cents Dime 10 cents.
Canadian Money. Coins Penny 1 cent 1¢ Nickel 5 cents 5¢
Chapter 4: Control Structures II
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 4 Practice cont.. Practice with nested loops 1.What will be the output of the following program segment: 1.for (int i = 1; i
More about Java Chapter 2 9/8 & 9/9 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
CONTROL STATEMENTS LOOPS. WHY IS REPETITION NEEDED?  There are many situations in which the same statements need to be executed several times.  Example:
Martin T. Press.  Main Method and Class Name  Printing To Screen  Scanner.
Keyboard and Screen I/O (Input/Output). Screen Output  System.out is an object that is part of the Java language. (Don’t worry yet about why there is.
Copyright © Curt Hill Simple I/O Input and Output using the System and Scanner Objects.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank M. Carrano. ISBN © 2008 Pearson Education, Inc.,
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
For Friday Read No quiz Program 6 due. Program 6 Any questions?
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
Counting by Fives with Nickels. 5 cents 5, 10 cents.
CSC111 Quick Revision.
Introduction to Computer Science / Procedural – 67130
Chapter 6 More Conditionals and Loops
Type Conversion, Constants, and the String Object
Chapter 5: Control Structures II
Java Programming: From Problem Analysis to Program Design, 4e
SELECTION STATEMENTS (1)
OPERATORS (1) CSC 111.
Chapter 2: Basic Elements of Java
Chapter 2 Part 2 Edited by JJ Shepherd
Statements and expressions - java
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
CS150 Introduction to Computer Science 1
The keyboard is the standard input device.
CSC 111 Exam 3 Review Fall 2005.
Unit 3: Variables in Java
Unit 1: Intro Lesson 4: Output.
Presentation transcript:

Some problems for your consideration

Variable names Which of the following may be used as variable names in Java? rate1 1stPlayer myprogram switch long TimeLimit numberOfWindows

Variable names Can a Java program have two different variables named number and Number?

Variables Give the declaration for two variables called count and distance. count is of type int and is initialized to zero. distance is of type double and is initialized to 1.5.

Expressions What is the output of the following program lines: double number = (1/3) * 3; System.out.println( "(1/3) * 3 is equal to " + number );

Expressions What is the output produced by the following code: int result = 11; result = result / 2; System.out.println( "result is " + result );

Output What is the output produced by the following: String verbPhrase = "is money"; System.out.println( "Time" + verbPhrase );

Output What is the output of the following: System.out.println( "2 + 2 = " + (2 + 2) ); System.out.println( "2 + 2 = " + 2 + 2 );

Comments What are the two kinds of comments in Java?

Comments What is the output produced by the following Java code? System.out.println( "Hello" ); //System.out.print( "Mr. or Ms. " ); System.out.println( "Student" );

Coupons The skeeball machines on the boardwalk in Wildwood output coupons according to how well you play the game. You can redeem 10 coupons for a candy bar or 3 coupons for a gumball. You prefer candy bars to gumballs. Write a program that defines a variable initially assigned to the number of coupons you win. Next, the program should output how many candy bars and gumballs you can get if you spend all of your coupons on candy bars first, and any remaining coupons on gumballs.

Strings What output is produced by the following: String s = "Hello" + "Joe"; System.out.println( s );

Strings Write Java statements that will cause the following to be written to the screen: One two buckle your shoe. Three four shut the door.

Strings What is the difference between System.out.println and System.out.print?

Strings What is the output produced by the following: System.out.println( 2 + " " + 2 ); System.out.println( 2 + 2 );

Sum, difference, and product Write a program that reads in two integers (typed from the keyboard) and outputs their sum, difference, and product.

The cost of gas A car is used for commuting. Write a program that takes as input the distance of the commute in miles, the car’s fuel consumption rate in miles per gallon, and the price of a gallon of gas. The program should then output the cost of the commute.

Make change Write a program that determines the change to be dispensed from a vending machine. An item in the machine can cost between 25 cents and a dollar, in 5-cent increments, and the machine accepts only a single dollar bill to pay for the item. For example, a possible sample dialog might be: Enter price of an item: 45 You bought an item for 45 cents and gave me a dollar so your change is: 2 quarters 0 dimes, and 1 nickel