# System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :

Save this PDF as:

Size: px
Start display at page:

Download "System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) :"

## Transcription

1 Benjamin Michael Java Homework 3 10/31/2012 1) Sales.java Code // Sales.java // Program calculates sales, based on an input of product // number and quantity sold import java.util.scanner; public class sales // calculates sales for 5 products public static void main( String args[] ) Scanner input = new Scanner( System.in ); int productnumber; double product1 = 0; // amount sold of first product double product2 = 0; // amount sold of second product double product3 = 0; // amount sold of third product double product4 = 0; // amount sold of fourth product double product5 = 0; // amount sold of fifth product double product1val = 2.98; double product2val = 4.50; double product3val = 9.98; double product4val = 4.49; double product5val = 6.87; /* Ask the user to enter product number */ "); System.out.println("\nEnter Product Number 1-5 (0 to stop and view summary) : productnumber = input.nextint(); /* Create while statement that loops until sentinel is entered */ while (productnumber!= 0) /* Determine whether user's product number is in 1-5 */ if (productnumber >= 1 && productnumber <= 5) /* If so, ask user to input the quantity sold */ /* Write a switch statement here that will compute the total for that product */ switch(productnumber) case 5: product5+=input.nextdouble();

2 case 4: product4+=input.nextdouble(); case 3: product3+=input.nextdouble(); case 2: product2+=input.nextdouble(); case 1: product1+=input.nextdouble(); /* If product number is not in 1-5, test if product number is not 0 */ productnumber = input.nextint(); if(productnumber < 0 productnumber > 5) /* Display error message for invalid product number */ System.out.println("Invalid product number!\nplease enter another product: "); /* Ask the user to enter another product number */ System.out.println("Enter product number (1-5), 0 to stop and view summary: "); productnumber = input.nextint(); /* end while loop */ // print summary System.out.printf( "Product 1: \$%.2f\n", product1 * product1val); System.out.printf( "Product 2: \$%.2f\n", product2 * product2val); System.out.printf( "Product 3: \$%.2f\n", product3 * product3val); System.out.printf( "Product 4: \$%.2f\n", product4 * product4val); System.out.printf( "Product 5: \$%.2f\n", product5 * product5val); /* write code here for the rest of the summary message it should contain the totals for the rest of the products, each on its own line */ // end main // end class body

3 1a. Sales.java Solution Product 1: \$8.94 Product 2: \$13.50 Product 3: \$0.00 Product 4: \$8.98 Product 5: \$ Triples.Java Code // Lab 3: Triples.java // Program calculates Pythagorean triples public class Triples public static void main( String args[] ) // declare the three sides of a triangle int side1; int side2; int hypotenuse; /* Write loop for side1 to try the values */ int max=500; for (side1 = 1; side1 <= max; side1++) /* Write loop for side2 to try the values */ for (side2 = 1; side2 <= max; side2++) /* Write loop for hypotenuse to try the values */ for (hypotenuse = 1; hypotenuse <= max; hypotenuse++) /* Write an if statement that determines whether the sum of the two sides squared equals the hypotenuse squared. If this condition is true display side1, side2 and hypotenuse. */ if ((side1*side1)+(side2*side2)==(hypotenuse*hypotenuse)) if(side1 < side2) hypotenuse); System.out.println("s1: " + side1 + " " + "s2: " + side2 + " " + "h: " + // end main // end class Triples

6 4. TrianglePrinting.Java public class TrianglePrinting public static void main(string args[]) int row, col, space; System.out.println("(a)"); // Triangle A Code for (row = 1; row <=10; row++) for(col=1; col <= row; col++) System.out.print('*'); System.out.println("\n(b)"); // Triangle B Code for (row=10; row >= 1; row--) for (col=1; col <= row; col++) System.out.print('*'); System.out.println("\n(c)"); // Triangle Code for (row=10; row >= 1; row--) for (space=10; space >= row ; space--) System.out.print(' '); for (col = 1; col < row; col++) System.out.print('*'); System.out.println("\n(d)"); // Triangle D Code for(row = 10; row >= 1; row--) for (space = 1; space < row; space++)

7 System.out.print(' '); for(col = 10; col >= row; col--); System.out.print('*'); // end TrianglePrinting class 4. TrianglePrinting Solution : (a) * ** *** **** ***** ****** ******* ******** ********* ********** (b) ********** ********* ******** ******* ****** ***** **** *** ** * (c) ********* ******** ******* ****** ***** **** *** ** * (d) * ** *** **** *****

8 ****** ******* ******** ********* ********** 5. RoundNumbers. Java import java.util.scanner; public class roundingnumbers public static void main (String[] args) double x; //Create Scanner to obtain input form user Scanner input=new Scanner(System.in); System.out.print("Enter a digit with at least four decimal places:"); x=input.nextdouble(); //create an output String with appropriate rounding System.out.println("The number: " +String.valueOf(x) + "\n This is your number rounded to Integer:\t\t" + String.valueOf(roundToInteger(x)) + "\n This is your number rounded to the Tenth:\t\t" + String.valueOf(roundToTenths(x)) + "\n This is your number rounded to Hundredth:\t\t" + String.valueOf(roundToThusandths(x))); public static double roundtointeger(double number) return(math.floor(number +.5)); public static double roundtotenths(double number) return(math.floor(number*10+.5)/10); public static double roundtohudredths(double number) return(math.floor(number*100+.5)/100); public static double roundtothusandths(double number)

9 return(math.floor(number* ) /1000); //end class round 5. RoundingNumbers.Java Solution Enter a digit with at least four decimal places:.4321 The number: This is your number rounded to Integer: 0.0 This is your number rounded to the Tenth: 0.4 This is your number rounded to Hundredth: ReversingDigits.Java Code import java.util.scanner; public class reversingdigits public static void main(string[] args) int number, reverse; Scanner input = new Scanner(System.in); System.out.print("Type Number:"); number = input.nextint(); reverse=reversingdigits(number); System.out.println("Reverse of typed number is: " + reverse); System.exit(0); public static int reversingdigits(int num) int reverse=0; while(num>0) reverse = (reverse*10)+num%10; num=num/10; return reverse; ReverseDigits.Java solutions: Number:123 Reversed Number is 321

### 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Programming Concepts Practice Test 1 1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius 2) Consider the following statement: System.out.println("1

### Building Java Programs

Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print

### Sample CSE8A midterm Multiple Choice (circle one)

Sample midterm Multiple Choice (circle one) (2 pts) Evaluate the following Boolean expressions and indicate whether short-circuiting happened during evaluation: Assume variables with the following names

1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays

### Q2: Which of the following are valid Java identifiers? If not explain why

Java Programming 1 (Revision) Name: Section#: ID: Q1: True/false 1. A Java identifier can start with a digit. (F) cannot 2. Hello, HELLO, and hello are considered as different identifiers. (T) 3. The name

### Building Java Programs

Building Java Programs Chapter 5 Lecture 5-2: Random Numbers reading: 5.1-5.2 self-check: #8-17 exercises: #3-6, 10, 12 videos: Ch. 5 #1-2 1 The Random class A Random object generates pseudo-random* numbers.

### Building Java Programs

Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: 3.3-3.4 self-check: #16-19 exercises: #11 videos: Ch. 3 #4 Interactive programs We have written programs that print

### CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)

### Topic 11 Scanner object, conditional execution

Topic 11 Scanner object, conditional execution "There are only two kinds of programming languages: those people always [complain] about and those nobody uses." Bjarne Stroustroup, creator of C++ Copyright

### COUNTING LOOPS AND ACCUMULATORS

COUNTING LOOPS AND ACCUMULATORS Two very important looping idioms are counting loops and accumulators. A counting loop uses a variable, called the loop control variable, to keep count of how many cycles

### Translating to Java. Translation. Input. Many Level Translations. read, get, input, ask, request. Requirements Design Algorithm Java Machine Language

Translation Translating to Java Introduction to Computer Programming The job of a programmer is to translate a problem description into a computer language. You need to be able to convert a problem description

### MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java

### Arrays in Java. Working with Arrays

Arrays in Java So far we have talked about variables as a storage location for a single value of a particular data type. We can also define a variable in such a way that it can store multiple values. Such

### MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION

MIDTERM 1 REVIEW WRITING CODE POSSIBLE SOLUTION 1. Write a loop that computes (No need to write a complete program) 100 1 99 2 98 3 97... 4 3 98 2 99 1 100 Note: this is not the only solution; double sum

### In this Chapter you ll learn:

Now go, write it before them in a table, and note it in a book. Isaiah 30:8 To go beyond is as wrong as to fall short. Confucius Begin at the beginning, and go on till you come to the end: then stop. Lewis

### Part I. Multiple Choice Questions (2 points each):

Part I. Multiple Choice Questions (2 points each): 1. Which of the following is NOT a key component of object oriented programming? (a) Inheritance (b) Encapsulation (c) Polymorphism (d) Parallelism ******

### Introduction to Java

Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high

### Building Java Programs

Building Java Programs Chapter 4 Lecture 4-1: Scanner; if/else reading: 3.3 3.4, 4.1 Interactive Programs with Scanner reading: 3.3-3.4 1 Interactive programs We have written programs that print console

### Introduction to Programming

Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems sjmaybank@dcs.bbk.ac.uk Spring 2015 Week 2b: Review of Week 1, Variables 16 January 2015 Birkbeck

### JAVA ARRAY EXAMPLE PDF

JAVA ARRAY EXAMPLE PDF Created By: Umar Farooque Khan 1 Java array example for interview pdf Program No: 01 Print Java Array Example using for loop package ptutorial; public class PrintArray { public static

### Basics of Java Programming Input and the Scanner class

Basics of Java Programming Input and the Scanner class CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

### Java iteration statements

Java iteration statements Iteration statements are statements which appear in the source code only once, but it execute many times. Such kind of statements are called loops. Almost all the programming

### CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void

### Fundamentals of Programming. Laboratory 3 Selection structures, designing selections, nested selection

Fundamentals of Programming Laboratory 3 Selection structures, designing selections, nested selection DECISION STRUCTURES allow programs to follow different courses of action or execute different tasks

### J a v a Quiz (Unit 3, Test 0 Practice)

Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points

### Chapter 2 Introduction to Java programming

Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break

### File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)

File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The

### AP Computer Science Java Mr. Clausen Program 9A, 9B

AP Computer Science Java Mr. Clausen Program 9A, 9B PROGRAM 9A I m_sort_of_searching (20 points now, 60 points when all parts are finished) The purpose of this project is to set up a program that will

### qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui

### Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.

Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command

### Program Elements. Notes. Exercises CHAPTER 3

CHAPTER 3 Program Elements Notes Chapter 3 introduces the program elements that are the underlying constructs used inside an object to define the services it contributes to a program. Without these constructs,

### Java 進 階 程 式 設 計 03/14~03/21

Java 進 階 程 式 設 計 03/14~03/21 Name: 邱 逸 夫 NO:942864 2.30 Write an application that inputs one number consisting of five digits from the user, separates the number into its individual digits and prints the

### Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output

Chapter 2 Console Input and Output System.out.println for console output System.out is an object that is part of the Java language println is a method invoked dby the System.out object that can be used

### int w = (x + x)*y - y; System.out.println("The value of w is " + w); z = w + 3; System.out.println("The value of z is now " + z);

MIT AITI Mobile Application Development in Java Lab 02: Java Basics Instructions on how to submit Lab 2 will be presented on the screen. Please follow instructions and if they are unclear, please feel

### Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014

German University in Cairo Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Ahmed Gamal Introduction to Computer Programming, Spring Term 2014 Practice Assignment 3 Discussion 15.3.2014-20.3.2014

### Introduction to Java. CS 3: Computer Programming in Java

Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods

### AP Computer Science Static Methods, Strings, User Input

AP Computer Science Static Methods, Strings, User Input Static Methods The Math class contains a special type of methods, called static methods. A static method DOES NOT operate on an object. This is because

### CS170 Lab 11 Abstract Data Types & Objects

CS170 Lab 11 Abstract Data Types & Objects Introduction: Abstract Data Type (ADT) An abstract data type is commonly known as a class of objects An abstract data type in a program is used to represent (the

### You are to simulate the process by making a record of the balls chosen, in the sequence in which they are chosen. Typical output for a run would be:

Lecture 7 Picking Balls From an Urn The problem: An urn has n (n = 10) balls numbered from 0 to 9 A ball is selected at random, its' is number noted, it is set aside, and another ball is selected from

### CompSci 125 Lecture 08. Chapter 5: Conditional Statements Chapter 4: return Statement

CompSci 125 Lecture 08 Chapter 5: Conditional Statements Chapter 4: return Statement Homework Update HW3 Due 9/20 HW4 Due 9/27 Exam-1 10/2 Programming Assignment Update p1: Traffic Applet due Sept 21 (Submit

### Lab 5: Bank Account. Defining objects & classes

Lab 5: Bank Account Defining objects & classes Review: Basic class structure public class ClassName Fields Constructors Methods Three major components of a class: Fields store data for the object to use

### THE JAVA API. Some of the Java API Packages Package Theme Some Classes Within It. Classes that provide helpful utilities

THE JAVA API The Java API which stands for Application Programming Interface is a repository of prewritten classes provided by the creators of Java to enhance its usefulness. There are classes for creating

### As activity directory at Lake LazyDays Resort, it is your job to suggest appropriate activities to guests based on the weather:

Chapter 5: Conditionals and Loops Lab Exercises Activities at Lake LazyDays As activity directory at Lake LazyDays Resort, it is your job to suggest appropriate activities to guests based on the weather:

### Software and Programming 1

Software and Programming 1 Lab 3: Strings & Conditional Statements 20 January 2016 SP1-Lab3.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Lab Objectives This session we are concentrating on Strings and conditional

### JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I

### Scanner sc = new Scanner(System.in); // scanner for the keyboard. Scanner sc = new Scanner(System.in); // scanner for the keyboard

INPUT & OUTPUT I/O Example Using keyboard input for characters import java.util.scanner; class Echo{ public static void main (String[] args) { Scanner sc = new Scanner(System.in); // scanner for the keyboard

### Homework/Program #5 Solutions

Homework/Program #5 Solutions Problem #1 (20 points) Using the standard Java Scanner class. Look at http://natch3z.blogspot.com/2008/11/read-text-file-using-javautilscanner.html as an exampleof using the

### Intro to Programming in Java Practice Midterm

600.107 Intro to Programming in Java Practice Midterm This test is closed book/notes. SHORT ANSWER SECTION [18 points total] 1) TRUE/FALSE - Please circle your choice: Tr for true, Fa for false. [1 point

### Fundamentals of Programming. Laboratory 5 Methods. General-purpose and user - defined methods

Fundamentals of Programming Laboratory 5 Methods. General-purpose and user - defined methods What is a method? Block of code that receives its own identifier - i.e. can be executed using its name Different

### Lecture 1 Introduction to Java

Programming Languages: Java Lecture 1 Introduction to Java Instructor: Omer Boyaci 1 2 Course Information History of Java Introduction First Program in Java: Printing a Line of Text Modifying Our First

### Preet raj Core Java and Databases CS4PR. Time Allotted: 3 Hours. Final Exam: Total Possible Points 75

Preet raj Core Java and Databases CS4PR Time Allotted: 3 Hours Final Exam: Total Possible Points 75 Q1. What is difference between overloading and overriding? 10 points a) In overloading, there is a relationship

### AP Computer Science Java Subset

APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall

### Using Files as Input/Output in Java 5.0 Applications

Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead

### Conditionals (with solutions)

Conditionals (with solutions) For exercises 1 to 27, indicate the output that will be produced. Assume the following declarations: final int MAX = 25, LIMIT = 100; int num1 = 12, num2 = 25, num3 = 87;

### Chapter 2: Elements of Java

Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

### First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science

First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca

### Java How to Program, 9/e

Java How to Program, 9/e Education, Inc. All Rights Reserved. 1 Any computing problem can be solved by executing a series of actions in a specific order. An algorithm is a procedure for solving a problem

### Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input

### java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources

### Comp 248 Introduction to Programming

Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been

### Chapter 3. Input and output. 3.1 The System class

Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use

### CS 121 Intro to Programming:Java - Lecture 11 Announcements

CS 121 Intro to Programming:Java - Lecture 11 Announcements Next Owl assignment up, due Friday (it s short!) Programming assignment due next Monday morning Preregistration advice: More computing? Take

### D06 PROGRAMMING with JAVA

Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch7 Iteration PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for accompanying

### Section 6 Spring 2013

Print Your Name You may use one page of hand written notes (both sides) and a dictionary. No i-phones, calculators or any other type of non-organic computer. Do not take this exam if you are sick. Once

### Chapter 2 Elementary Programming

Chapter 2 Elementary Programming 2.1 Introduction You will learn elementary programming using Java primitive data types and related subjects, such as variables, constants, operators, expressions, and input

### CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]

### Reading a Text File. Reading and Writing Text Files Exceptions. Testing for more input. Example: Count Words

Reading a Text File Reading and Writing Text Files Exceptions 15-121 Fall 2010 Margaret Reid-Miller A Scanner object can be connected to many input sources: keyboard, file, network, string To read a text

### CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section

### CSE 142, Spring 2009 Midterm Exam Answer Key

CSE 142, Spring 2009 Midterm Exam Answer Key 1 of 9 1. Expressions For each expression in the left-hand column, indicate its value in the right-hand column. Be sure to list a constant of appropriate type

### While and Do-While Loops. 15-110 Summer 2010 Margaret Reid-Miller

While and Do-While Loops 15-110 Margaret Reid-Miller Loops Within a method, we can alter the flow of control using either conditionals or loops. The loop statements while, do-while, and for allow us execute

### Object-Oriented Programming in Java

CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio

### IRA EXAMPLES. This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account).

IRA EXAMPLES This topic has two examples showing the calculation of the future value an IRA (Individual Retirement Account). Definite Counting Loop Example IRA After x Years This first example illustrates

### (Eng. Hayam Reda Seireg) Sheet Java

(Eng. Hayam Reda Seireg) Sheet Java 1. Write a program to compute the area and circumference of a rectangle 3 inche wide by 5 inches long. What changes must be made to the program so it works for a rectangle

### Flow of Control. Conditional Statements. Boolean Expressions. CMPT 125: Lecture 4 Conditionals and Loops

Flow of Control CMPT 125: Lecture 4 Conditionals and Loops Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 17, 2009 The order in which statements are executed

### Masters programmes in Computer Science and Information Systems. Object-Oriented Design and Programming. Sample module entry test xxth December 2013

Masters programmes in Computer Science and Information Systems Object-Oriented Design and Programming Sample module entry test xxth December 2013 This sample paper has more questions than the real paper

### CS 101: Practice Questions for Test 2 SOLUTIONS

CS 101: Practice Questions for Test 2 SOLUTIONS 1. Write a Java application which prompts the user to enter integers from the screen until the end of file character is entered, computes the sum of the

CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install

### Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6 Handout 3 Strings and String Class. Input/Output with JOptionPane. Strings In Java strings are represented with a class type String. Examples:

### Iteration CHAPTER 6. Topic Summary

CHAPTER 6 Iteration TOPIC OUTLINE 6.1 while Loops 6.2 for Loops 6.3 Nested Loops 6.4 Off-by-1 Errors 6.5 Random Numbers and Simulations 6.6 Loop Invariants (AB only) Topic Summary 6.1 while Loops Many

### TRUE / FALSE MULTIPLE CHOICE

CS 111 Exam 3 FORM A TRUE / FALSE 1. If you write a tostring method for a class, it can be invoked automatically to output the string generated by that method. T 2. You can change the contents of a String

### AP Computer Science File Input with Scanner

AP Computer Science File Input with Scanner Subset of the Supplement Lesson slides from: Building Java Programs, Chapter 6 by Stuart Reges and Marty Stepp (http://www.buildingjavaprograms.com/ ) Input/output

### Data Structures Lecture 1

Fall 2015 Fang Yu Software Security Lab. Dept. Management Information Systems, National Chengchi University Data Structures Lecture 1 A brief review of Java programming Popularity of Programming Languages

### COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005. Question Out of Mark A Total 16. B-1 7 B-2 4 B-3 4 B-4 4 B Total 19

Term Test #2 COSC 1020 3.0 Introduction to Computer Science I Section A, Summer 2005 Family Name: Given Name(s): Student Number: Question Out of Mark A Total 16 B-1 7 B-2 4 B-3 4 B-4 4 B Total 19 C-1 4

### Course Intro Instructor Intro Java Intro, Continued

Course Intro Instructor Intro Java Intro, Continued The syllabus Java etc. To submit your homework, do Team > Share Your repository name is csse220-200830-username Use your old SVN password. Note to assistants:

### Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java

### CS114: Introduction to Java

CS114: Introduction to Java Fall 2015, Mon/Wed, 5:30 PM - 6:45 PM Instructor: Pejman Ghorbanzade to Assignment 4 Release Date: Nov 04, 2015 at 5:30 PM Due Date: Nov 18, 2015 at 5:30 PM Question 1 An n

### Hello World. n Variables store information. n You can think of them like boxes. n They hold values. n The value of a variable is its current contents

Variables in a programming language Basic Computation (Savitch, Chapter 2) TOPICS Variables and Data Types Expressions and Operators Integers and Real Numbers Characters and Strings Input and Output Variables

### Lecture Set 2: Starting Java

Lecture Set 2: Starting Java 1. Java Concepts 2. Java Programming Basics 3. User output 4. Variables and types 5. Expressions 6. User input 7. Uninitialized Variables CMSC 131 - Lecture Outlines - set

### In Java, the symbol + can be used to add numbers or to concatenate strings. This exercise illustrates both uses.

Chapter 2: Data and Expressions Lab Exercises Two Meanings of Plus In Java, the symbol + can be used to add numbers or to concatenate strings. This exercise illustrates both uses. When using a string literal

### CSE 8B Midterm Fall 2015

Name Signature Tutor Student ID CSE 8B Midterm Fall 2015 Page 1 (XX points) Page 2 (XX points) Page 3 (XX points) Page 4 (XX points) Page 5 (XX points) Total (XX points) 1. What is the Big-O complexity

### Chapter 4 C Program Control

Chapter 4 C Program Control Objectives of this chapter: Repetitions will be considered in greater detail for.. repetition do while repetition Also multiple selection switch case statement will be learned.

### 5.2 Q2 The control variable of a counter-controlled loop should be declared as: a.int. b.float. c.double. d.any of the above. ANS: a. int.

Java How to Program, 5/e Test Item File 1 of 5 Chapter 5 Section 5.2 5.2 Q1 Counter-controlled repetition requires a.a control variable and initial value. b.a control variable increment (or decrement).

### Arrays. Introduction. Chapter 7

CH07 p375-436 1/30/07 1:02 PM Page 375 Chapter 7 Arrays Introduction The sequential nature of files severely limits the number of interesting things you can easily do with them.the algorithms we have examined

### Java Libraries and Methods

COMP-202 Java Libraries and Methods COMP-202 - Java Library and Methods, 2013 Jörg Kienzle and others Chapter Outline Using Library Methods Java.Math example Writing your own Methods Void Methods Methods

### CS 101: Practice Questions for Chapter 6 and 7 SOLUTIONS

CS 101: Practice Questions for Chapter 6 and 7 SOLUTIONS 1. Modify the class Student below to add a member num which counts the number of Student objects which have been instantiated. (Hint: should num

### Programming Fundamentals I CS 110, Central Washington University. November 2015

Programming Fundamentals I CS 110, Central Washington University November 2015 Next homework, #4, was due tonight! Lab 6 is due on the 4 th of November Final project description + pseudocode are due 4th

### Two-Dimensional Arrays. 15-110 Summer 2010 Margaret Reid-Miller

Two-Dimensional Arrays 15-110 Margaret Reid-Miller Two-Dimensional Arrays Arrays that we have consider up to now are onedimensional arrays, a single line of elements. Often data come naturally in the form

### LOOPS CHAPTER CHAPTER GOALS

jfe_ch04_7.fm Page 139 Friday, May 8, 2009 2:45 PM LOOPS CHAPTER 4 CHAPTER GOALS To learn about while, for, and do loops To become familiar with common loop algorithms To understand nested loops To implement