The correct syntax for the expression is ((x <= 10) && (x >= 1)).
|
|
- Annabella Page
- 5 years ago
- Views:
Transcription
1 R5.2b. Find the errors in the following if statements: if (x = 1) y++; else if (x = 2) y = y + 2; The relational operator equal is not =, the relational operator equal is == R5.4b. Find the errors in the following if statements: if (1 <= x <= 10) System.out.println(x); The correct syntax for the expression is ((x <= 10) && (x >= 1)). R5.4d. Find the errors in the following if statements: if (input.equalsignorecase("n") "NO") return; NO is not a valid Boolean expression. May be the correct expression is: if (input.equalsignorecase("n") input.equalsignorecase("no")) return; R5.11. Give a set of four test cases for the algorithm of Exercise R5.10 that covers all branches. 1. if((letter=='a') (letter=='c') (letter=='e') (letter=='g')) if((number % 2) == 1) color = "black"; else color="white"; else if((number % 2)==0) color="black"; else color="white"; 2. if((letter=='a') (letter=='c') (letter=='e') (letter=='g')) color= ((number % 2) == 1)? "black" : "white"; else color= ((number % 2) == 0)? "black" : "white";
2 3. 4. color= ((number % 2) == 1)? "black" : "white"; color= ((number % 2)!= 1)? "white" : "black"; R5.14. True or false? A && B is the same as B && A for any Boolean conditions A and B. When & is used it will evaluate both the expressions regardless of the fact that it finds first expression as FALSE and only then will it give an answer. Whereas if && was used in place of &, after it had evaluated first expression and had found result of first expression as FALSE, it would not have evaluated second expression. Thus saving time. FALSE. R5.19. Explain the difference between the tests r == s and r.equals(s) where both r and s are of type Rectangle. If you compare two object references with the == operator, you test whether the references refer to the same object. Here is an example: Rectangle r = new Rectangle(5, 10, 20, 30); Rectangle s = r; Rectangle t = new Rectangle(5, 10, 20, 30); The comparison r == s is true. Both object variables refer to the same object. But the comparison r == t is false. The two object variables refer to different objects. It does not matter that the objects have identical contents. You can use the equals method to test whether two rectangles have the same contents, that is, whether they have the same upper-left corner and the same width and height. For example, the test r.equals(t) is true. R5.26. Give a set of test cases for the earthquake program in Section Ensure coverage of all branches. public static void main(string[] args) Earthquake quake1 = new Earthquake(9.0); System.out.println(quake1.getDescription()=="Most structures fall"?
3 Earthquake quake1 = new Earthquake(7.5); System.out.println(quake1.getDescription()=="Many buildings destroyed"? Earthquake quake1 = new Earthquake(6.5); System.out.println(quake1.getDescription()=="Many buildings considerably damaged, some collapse"? Earthquake quake1 = new Earthquake(5.5); System.out.println(quake1.getDescription()=="Damage to poorly constructed buildings"? Earthquake quake1 = new Earthquake(4.0); System.out.println(quake1.getDescription()=="Felt by many people, no destruction"? Earthquake quake1 = new Earthquake(1.0); System.out.println(quake1.getDescription()=="Generally not felt by people"? Earthquake quake1 = new Earthquake(-1.0); System.out.println(quake1.getDescription()=="Negative numbers are not valid"? P5.4. Write a program that translates a letter grade into a number grade. Letter grades are A B C D F, possibly followed by + or -. Their numeric values are 4, 3, 2, 1, and 0. There is no F+ or F-. A + increases the numeric value by 0.3, a - decreases it by 0.3. However, an A+ has the value 4.0. All other inputs have value 1. Use a class Grade with a method getnumericgrade. public class Grade double getnumericgrade(string lettergrade) double numericgrade=0.0; if((lettergrade=="a") (lettergrade=="a+")) numericgrade = 4.0; else if(lettergrade=="a-") numericgrade = 3.7; else if(lettergrade=="b+") numericgrade = 3.3; else if(lettergrade=="b") numericgrade = 3.0; else if(lettergrade=="b-") numericgrade = 2.7; else if(lettergrade=="c+") numericgrade = 2.3; else if(lettergrade=="c") numericgrade = 2.0; else if(lettergrade=="c-") numericgrade = 1.7; else if(lettergrade=="d+") numericgrade = 1.3; else if(lettergrade=="d") numericgrade = 1.0; else if(lettergrade=="d-") numericgrade = 0.7; else if(lettergrade=="f") numericgrade = 0.0; else numericgrade=-1; return numericgrade;
4 P5.8. The original U.S. income tax of 1913 was quite simple. The tax was 1 percent on the first $50, percent on the amount over $50,000 up to $75, percent on the amount over $75,000 up to $100, percent on the amount over $100,000 up to $250, percent on the amount over $250,000 up to $500, percent on the amount over $500,000. There was no separate schedule for single or married taxpayers. Write a program that computes the income tax according to this schedule. import java.util.scanner; public class TaxCalculator private double income=0.0; public TaxCalculator(double income)this.income=income; public double gettax() double Tax=0.0; if(income<=50000) Tax = income*0.01; else if(income<=75000) Tax = income*0.02; else if(income<=100000) Tax = income*0.03; else if(income<=250000) Tax = income*0.04; else if(income<=500000) Tax = income*0.05; else Tax = income*0.06; return Tax; public static void main(string[] args) Scanner in = new Scanner(System.in); System.out.print("Please enter your income: "); double income = in.nextdouble(); TaxCalculator T = new TaxCalculator(income); System.out.println("Tax: " + T.getTax());
5 P5.12. A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (for example, 1980). However, since the introduction of the Gregorian calendar on October 15, 1582, a year is not a leap year if it is divisible by 100 (for example, 1900); however, it is a leap year if it is divisible by 400 (for example, 2000). Write a program that asks the user for a year and computes whether that year is a leap year. Implement a class Year with a predicate method boolean isleapyear(). import java.util.scanner; public class LeapYear private int year=0; public LeapYear(int year)this.year=year; public boolean isleapyear() return (year%4==0 (year%400==0 && year%100!=0)); public static void main(string[] args) Scanner in = new Scanner(System.in); System.out.print("Please enter a year: "); double year = in.nextinteger(); LeapYear T = new LeapYear(year); System.out.println("Is leap: " + T.isLeapYear());
6 P5.17. Write a unit conversion program that asks users to identify the unit from which they want to convert and the unit to which they want to convert. Legal units are in, ft, mi, mm, cm, m, and km. Declare two objects of a class UnitConverter that convert between s and a given unit. Convert from: in Convert to: mm Value: in = 254 mm import java.util.scanner; public class UnitConverter private String from="m"; private String to="cm"; double amount = 0.0; UnitConverter(String from, String to, double amount) this.amount=amount; this.from=from; this.to=to; public double Convert() double convert=0.0; double Factor=1; //s in 1 double inchfactor= ; //inches in 1 double feetfactor= ; //foots in 1 double milefactor= e-4; //miles in 1 double millifactor=1000; //millis in 1 double centfactor=100; //centis in a ; double kilofactor=1e-3; //kilos in 1 ; double fromfactor=1; double tofactor=1; if(from.equals("m")) fromfactor=factor; if(from.equals("in"))fromfactor=inchfactor; if(from.equals("ft"))fromfactor=feetfactor; if(from.equals("mi"))fromfactor=milefactor; if(from.equals("mm"))fromfactor=millifactor; if(from.equals("cm"))fromfactor=centfactor; if(from.equals("km"))fromfactor=kilofactor; if(to.equals("m")) tofactor=factor; if(to.equals("in"))tofactor=inchfactor; if(to.equals("ft"))tofactor=feetfactor; if(to.equals("mi"))tofactor=milefactor;
7 if(to.equals("mm"))tofactor=millifactor; if(to.equals("cm"))tofactor=centfactor; if(to.equals("km"))tofactor=kilofactor; convert=amount*tofactor/fromfactor; return convert; /** args */ public static void main(string[] args) // TODO Auto-generated method stub Scanner in = new Scanner(System.in); System.out.print("Please enter your amount in s: "); double amount = in.nextdouble(); System.out.print("Please enter your target unit: "); String unit = in.next(); UnitConverter U = new UnitConverter("m",unit,amount); System.out.println("Is equivalent to " + U.Convert() + " " + unit); P5.18. P5.18 A line in the plane can be specified in various ways: by giving a point (x, y) and a slope m by giving two points (x1, y1), (x2, y2) as an equation in slope-intercept form y = mx + b as an equation x = a if the line is vertical Implement a class Line with four constructors, corresponding to the four cases above. Implement methods boolean intersects(line other) boolean equals(line other) boolean isparallel(line other) public class Line private double m=0; private double intercepty=0; private double interceptx=0; private boolean infscope=false; public Line(double x,double y, double m) // y0-y1 y0-y1 // m= ==> y0 = m.(x0-x1) + y1 ==> x0 = x1 // x0-x1 m this.m=m; this.intercepty=this.m*(0-x)+y; this.infscope=false; this.interceptx=(0-y)/m + x; ;
8 public Line(double x1,double y1, double x2, double y2) // y0-y1 // m= ==> y0 = m.(x0-x1) + y1 // x0-x1 this.infscope=(x1==x2); if(!this.infscope) this.m=(y1-y2)/(x1-x2); this.intercepty=this.m*(0-x1)+y1; this.interceptx=(0-y1)/m + x1; ; public Line(double m,double intercepty) // y0-y1 // m= ==> y0 = m.(x0-x1) + y1 // x0-x1 // y = m x + b ==> x = (y/m) - b/m this.infscope=false; this.m=0; this.intercepty=intercepty; this.interceptx=-this.intercepty/this.m; ; public Line(double a) this.m=0; this.intercepty=0; this.interceptx=a; this.infscope=true; ; public boolean getinfscope()return infscope;; public double getm()return m;; public double getintercepty()return intercepty;; public double getinterceptx()return interceptx;; public boolean intersects(line l) return (this.getm()!=l.getm()); public boolean equals(line l) boolean e=false; if(this.getinfscope() &&!l.getinfscope()!this.getinfscope() && l.getinfscope())e=false;else if(!this.getinfscope())e=this.getm()==l.getm() && this.getintercepty()==l.getintercepty();else e=this.getinterceptx()==l.getinterceptx(); return e; public boolean isparallel(line l) return this.getinfscope() && l.getinfscope() this.getm() == l.getm(); ;
9
Chapter 5 Decisions. Big Java by Cay Horstmann Copyright 2009 by John Wiley & Sons. All rights reserved.
Chapter 5 Decisions Chapter Goals To be able to implement decisions using if statements To understand how to group statements into blocks To learn how to compare integers, floating-point numbers, strings,
More informationThe if/else Statement
Chapter Goals To be able to implement decisions using if statements To understand how to group statements into blocks To learn how to compare integers, floating-point numbers, strings, and objects To recognize
More informationJava Coding 2. Decisions, decisions!
Java Coding 2 Decisions, decisions! The if Statement An if statement is like a fork in the road. Depending upon a decision, different parts of the program are executed. The if Statement The if statement
More informationMotivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018
Motivating Examples (1.1) Selections EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG 1 import java.util.scanner; 2 public class ComputeArea { 3 public static void main(string[] args)
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 2 Data and expressions reading: 2.1 3 The computer s view Internally, computers store everything as 1 s and 0
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements
WIT COMP1000 Simple Control Flow: if-else statements Control Flow Control flow is the order in which program statements are executed So far, all of our programs have been executed straight-through from
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 Data and expressions reading: 2.1 self-check: 1-4 videos: Ch. 2 #1 2 Data types type: A category or set of data
More informationRyerson University Vers HAL6891A-05 School of Computer Science CPS109 Midterm Test Fall 05 page 1 of 6
CPS109 Midterm Test Fall 05 page 1 of 6 Last Name First Name Student Number Circle Your Instructor Your last name here Your first name here Your student number here Ferworn Harley Instructions: (a) There
More informationH212 Introduction to Software Systems Honors
Introduction to Software Systems Honors Lecture #04: Fall 2015 1/20 Office hours Monday, Wednesday: 10:15 am to 12:00 noon Tuesday, Thursday: 2:00 to 3:45 pm Office: Lindley Hall, Room 401C 2/20 Printing
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 Copyright 2009 by Pearson Education Data and expressions reading: 2.1 self-check: 1-4 videos: Ch. 2 #1 Copyright
More informationTopic 4 Expressions and variables
Topic 4 Expressions and variables "Once a person has understood the way variables are used in programming, he has understood the quintessence of programming." -Professor Edsger W. Dijkstra Based on slides
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 001 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationwhile (/* array size less than 1*/){ System.out.print("Number of students is invalid. Enter" + "number of students: "); /* read array size again */
import java.util.scanner; public class CourseManager1 { public static void main(string[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter number of students: "); /* read the number
More informationMcGill University School of Computer Science COMP-202A Introduction to Computing 1
McGill University School of Computer Science COMP-202A Introduction to Computing 1 Midterm Exam Thursday, October 26, 2006, 18:00-20:00 (6:00 8:00 PM) Instructors: Mathieu Petitpas, Shah Asaduzzaman, Sherif
More informationQuestion 1 [20 points]
Question 1 [20 points] Explain following features of Eclipse IDE. Provide a very short example for each. a) Assume a class Student that represents a student of ECE department at UPRM. Give two different
More informationChapter Goals. Chapter 5 - Iteration. Calculating the Growth of an Investment
Chapter Goals To be able to program loops with the while and for statements To avoid infinite loops and off-by-one errors To be able to use common loop algorithms To understand nested loops To implement
More informationUse the scantron sheet to enter the answer to questions (pages 1-6)
Use the scantron sheet to enter the answer to questions 1-100 (pages 1-6) Part I. Mark A for True, B for false. (1 point each) 1. Abstraction allow us to specify an object regardless of how the object
More informationIntroduction to Computer Programming
Introduction to Computer Programming Lecture 2- Primitive Data and Stepwise Refinement Data Types Type - A category or set of data values. Constrains the operations that can be performed on data Many languages
More informationCOMPUTER APPLICATIONS
COMPUTER APPLICATIONS (Theory) (Two hours) Answers to this Paper must be written on the paper provided separately. You will not be allowed to write during the first 15 minutes. This time is to be spent
More informationJAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) ABSTRACT In this Lab you will learn to define and invoke void and return java methods JAVA
More informationBoolean Expressions. So, for example, here are the results of several simple Boolean expressions:
Boolean Expressions Now we have the ability to read in some information, calculate some formulas and display the information to the user in a nice format. However, the real power of computer programs lies
More informationBuilding Java Programs
Building Java Programs Chapter 2 Lecture 2-1: Expressions and Variables reading: 2.1-2.2 1 Variables reading: 2.2 self-check: 1-15 exercises: 1-4 videos: Ch. 2 #2 2 Receipt example What's bad about the
More informationBuilding Java Programs. Chapter 2: Primitive Data and Definite Loops
Building Java Programs Chapter 2: Primitive Data and Definite Loops Copyright 2008 2006 by Pearson Education 1 Lecture outline data concepts Primitive types: int, double, char (for now) Expressions: operators,
More information1 Short Answer (5 Points Each)
1 Short Answer (5 Points Each) 1. Write a declaration of an array of 300 strings. String strarray[] = new String[300];. Write a method that takes in an integer n as a parameter and returns one half of
More informationControl Structures: if and while A C S L E C T U R E 4
Control Structures: if and while A C S - 1903 L E C T U R E 4 Control structures 3 constructs are essential building blocks for programs Sequences compound statement Decisions if, switch, conditional operator
More informationChapter 3 Selections. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.
Chapter 3 Selections Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. 0132130807 1 Motivations If you assigned a negative value for radius
More informationIteration Advanced Programming
Iteration Advanced Programming ICOM 4015 Lecture 6 Reading: Java Concepts Chapter 7 Chapter Goals To be able to program loops with the while, for, and do statements To avoid infinite loops and off-by-one
More information2.2 - Making Decisions
2.2 - Making Decisions So far we have only made programs that execute the statements in order, starting with the statements at the top of the screen and moving down. However, you can write programs that
More informationChapter 3 Selections. 3.1 Introduction. 3.2 boolean Data Type
3.1 Introduction Chapter 3 Selections Java provides selections that let you choose actions with two or more alternative courses. Selection statements use conditions. Conditions are Boolean expressions.
More informationName CIS 201 Midterm II: Chapters 1-8
Name CIS 201 Midterm II: Chapters 1-8 December 15, 2010 Directions: This is a closed book, closed notes midterm. Place your answers in the space provided. The point value for each question is indicated.
More informationJava Foundations: Introduction to Program Design & Data Structures, 4e John Lewis, Peter DePasquale, Joseph Chase Test Bank: Chapter 2
Java Foundations Introduction to Program Design and Data Structures 4th Edition Lewis TEST BANK Full download at : https://testbankreal.com/download/java-foundations-introduction-toprogram-design-and-data-structures-4th-edition-lewis-test-bank/
More informationInterpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled
Interpreted vs Compiled Python 1 Java Interpreted Easy to run and test Quicker prototyping Program runs slower Compiled Execution time faster Virtual Machine compiled code portable Java Compile > javac
More informationSpring, 2014 CIT 590. Programming Languages and Techniques Homework 7
Spring, 2014 CIT 590 Programming Languages and Techniques Homework 7 Mar 21, 2014; Due Mar 28, 2014, before first recitation This homework deals with the following topics * Getting started with Java *
More informationKing Saud University College of Computer and Information Sciences Computer Science Department
King Saud University College of Computer and Information Sciences Computer Science Department Course Code: CSC 111 Course Title: Introduction to Programming Semester: Fall 2017-2018 Exercises Cover Sheet:
More informationSelections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG
Selections EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Learning Outcomes The Boolean Data Type if Statement Compound vs. Primitive Statement Common Errors
More informationLab Exercise 1. Objectives: Part 1. Introduction
Objectives: king Saud University College of Computer &Information Science CSC111 Lab Object II All Sections - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
More informationExam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:
كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this
More informationCSIS-120 Final Exam Fall 2015 Name:
1. Which line of code creates a Player object called player1 using the default constructor a) Player player1; b) Player player1 = new Player (); c) Player1 Player(); d) Player player1 = new Player ; e)
More informationObject Oriented Programming and Design in Java. Session 2 Instructor: Bert Huang
Object Oriented Programming and Design in Java Session 2 Instructor: Bert Huang Announcements TA: Yipeng Huang, yh2315, Mon 4-6 OH on MICE clarification Next Monday's class canceled for Distinguished Lecture:
More informationCS 112 Introduction to Programming
CS 112 Introduction to Programming Conditional Statements Boolean Expressions and Methods Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu
More informationCS 112 Introduction to Programming
CS 112 Introduction to Programming Conditional Statements Boolean Expressions and Methods Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu
More informationCIS October 16, 2018
CIS 1068 October 16, 2018 administrative stuff @@@ ADD ME @@@ Midterm Remember, the material is cumulative You ll see this stuff again Legal Identifiers c00lg33k is a legal identifier Legal Identifiers
More informationComputer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming
Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #2
More informationCOMP-202: Foundations of Programming. Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 3: Boolean, Mathematical Expressions, and Flow Control Sandeep Manjanna, Summer 2015 Announcements Slides will be posted before the class. There might be few
More informationBuilding Java Programs Chapter 2
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. Data types type: A category or set of data values. Constrains the operations that can
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 001 Spring 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationObject Oriented Programming. Java-Lecture 6 - Arrays
Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types
More informationCIS 1068 Design and Abstraction Spring 2017 Midterm 1a
Spring 2017 Name: TUID: Page Points Score 1 28 2 18 3 12 4 12 5 15 6 15 Total: 100 Instructions The exam is closed book, closed notes. You may not use a calculator, cell phone, etc. i Some API Reminders
More informationAP Computer Science. if/else, return values. Copyright 2010 by Pearson Education
AP Computer Science if/else, return values The if statement Executes a block of statements only if a test is true statement;... statement; Example: double gpa = console.nextdouble(); if (gpa >= 2.0) {
More informationChapter Goals. 3.1 The if Statement. Contents 1/30/2013 DECISIONS
CHAPTER DECISIONS 3 Chapter Goals To implement decisions using the if statement To compare integers, floating-point numbers, and Strings To write statements using the Boolean data type To develop strategies
More informationCSci 1103 Final. Name: Student ID:
CSci 1103 Final Name: Student ID: Instructions: Please pick and answer any 10 of the 12 problems for a total of 100 points. If you answer more than 10 problems, only the first 10 will be graded. The time
More informationIntroduction to Computer Science Unit 4B. Programs: Classes and Objects
Introduction to Computer Science Unit 4B. Programs: Classes and Objects This section must be updated to work with repl.it 1. Copy the Box class and compile it. But you won t be able to run it because it
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 000 Spring 2014 Name (print):. Instructions Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationSir Muhammad Naveed. Arslan Ahmed Shaad ( ) Muhammad Bilal ( )
Sir Muhammad Naveed Arslan Ahmed Shaad (1163135 ) Muhammad Bilal ( 1163122 ) www.techo786.wordpress.com CHAPTER: 2 NOTES:- VARIABLES AND OPERATORS The given Questions can also be attempted as Long Questions.
More informationBuilding Java Programs
Building Java Programs Chapter 4 Lecture 4-1: if and if/else Statements reading: 4.2 self-check: #4-5, 7, 10, 11 exercises: #7 videos: Ch. 4 #2-4 The if/else statement Executes one block if a test is true,
More informationCS Computers & Programming I Review_01 Dr. H. Assadipour
CS 101 - Computers & Programming I Review_01 Dr. H. Assadipour 1. What is the output of this program? public class Q_01 public static void main(string [] args) int x=8; int y=5; double z=12; System.out.println(y/x);
More informationDATA TYPES AND EXPRESSIONS
DATA TYPES AND EXPRESSIONS Outline Variables Naming Conventions Data Types Primitive Data Types Review: int, double New: boolean, char The String Class Type Conversion Expressions Assignment Mathematical
More informationCONDITIONAL EXECUTION
CONDITIONAL EXECUTION yes x > y? no max = x; max = y; logical AND logical OR logical NOT &&! Fundamentals of Computer Science I Outline Conditional Execution if then if then Nested if then statements Comparisons
More informationObject Oriented Programming. Java-Lecture 1
Object Oriented Programming Java-Lecture 1 Standard output System.out is known as the standard output object Methods to display text onto the standard output System.out.print prints text onto the screen
More informationSample Solution A10 R6.2 R6.3 R6.5. for (i = 10; i >= 0; i++)... never ends. for (i = -10; i <= 10; i = i + 3)... 6 times
Sample Solution A10 R6.2 0000000000 0123456789 0246802468 0369258147 0482604826 0505050505 0628406284 0741852963 0864208642 0987654321 R6.3 for (i = 10; i >= 0; i++)... never ends for (i = -10; i
More informationObject Oriented Programming 2015/16. Final Exam June 28, 2016
Object Oriented Programming 2015/16 Final Exam June 28, 2016 Directions (read carefully): CLEARLY print your name and ID on every page. The exam contains 8 pages divided into 4 parts. Make sure you have
More informationCSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012
CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2012 Name: This exam consists of 7 problems on the following 6 pages. You may use your single- side hand- written 8 ½ x 11 note sheet during the
More informationSelec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal
Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program
More informationChapter 3 Selection Statements
Chapter 3 Selection Statements 3.1 Introduction Java provides selection statements that let you choose actions with two or more alternative courses. Selection statements use conditions. Conditions are
More informationPractice Midterm 1 Answer Key
CS 120 Software Design I Fall 2018 Practice Midterm 1 Answer Key University of Wisconsin - La Crosse Due Date: October 5 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages
More informationBuilding Java Programs Chapter 2. bug. Primitive Data and Definite Loops. Copyright (c) Pearson All rights reserved. Software Flaw.
Building Java Programs Chapter 2 bug Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. 2 An Insect Software Flaw 3 4 Bug, Kentucky Bug Eyed 5 Cheesy Movie 6 Punch Buggy
More informationBuilding Java Programs Chapter 2
Building Java Programs Chapter 2 Primitive Data and Definite Loops Copyright (c) Pearson 2013. All rights reserved. bug 2 An Insect 3 Software Flaw 4 Bug, Kentucky 5 Bug Eyed 6 Cheesy Movie 7 Punch Buggy
More informationCONTENTS: While loops Class (static) variables and constants Top Down Programming For loops Nested Loops
COMP-202 Unit 4: Programming with Iterations Doing the same thing again and again and again and again and again and again and again and again and again... CONTENTS: While loops Class (static) variables
More informationSchool of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15
Table of Contents 1 INTRODUCTION... 1 2 IF... 1 2.1 BOOLEAN EXPRESSIONS... 3 2.2 BLOCKS... 3 2.3 IF-ELSE... 4 2.4 NESTING... 5 3 SWITCH (SOMETIMES KNOWN AS CASE )... 6 3.1 A BIT ABOUT BREAK... 7 4 CONDITIONAL
More informationDEFECT TESTING. Since the goal of each test run is to uncover another error, a successful test run is one that causes your program to fail.
DEFECT TESTING Defect testing involves finding errors in a computer program by running it. On each run you enter input and study the program s output to determine if it is correct. If not, you debug the
More informationCIS November 14, 2017
CIS 1068 November 14, 2017 Administrative Stuff Netflix Challenge New assignment posted soon Lab grades Last Time. Building Our Own Classes Why Abstraction More on the new operator Fields Class vs the
More informationCIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017
Administrative Stuff CIS 1068 Netflix Challenge New assignment posted soon Lab grades November 14, 2017 Last Time. Building Our Own Classes Why Abstraction More on the new operator Fields Class vs the
More informationSome Practice Midterm Problems
Some Practice Midterm Problems September 29, 2017 1. 1 point word count is a legal identifier in Java A. True B. False 2. 1 point k2 is a legal identifier in Java A. True B. False 3. 1 point Krazy1 is
More informationWeb-CAT submission URL: CAT.woa/wa/assignments/eclipse
King Saud University College of Computer & Information Science CSC111 Lab10 Arrays II All Sections ------------------------------------------------------------------- Instructions Web-CAT submission URL:
More information1/9/2015. Intro to CS: Java Review Assignment Due Dates Chapter 7 7.1: while Loops 7.2: for Loops Ch7 Work Time. Chapter 7 Iteration WHILE LOOPS
Chapter 7 Iteration The Plan For Today Intro to CS: Java Review Assignment Due Dates Chapter 7 7.1: while Loops 7.2: for Loops Ch7 Work Time WHILE LOOPS Executes a block of code repeatedly A condition
More informationIntroduction to Software Development (ISD) Week 3
Introduction to Software Development (ISD) Week 3 Autumn term 2012 Aims of Week 3 To learn about while, for, and do loops To understand and use nested loops To implement programs that read and process
More informationCOMP 250: Java Programming I. Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette
COMP 250: Java Programming I Carlos G. Oliver, Jérôme Waldispühl January 17-18, 2018 Slides adapted from M. Blanchette Variables and types [Downey Ch 2] Variable: temporary storage location in memory.
More informationSequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;
Control Statements Control Statements All programs could be written in terms of only one of three control structures: Sequence Structure Selection Structure Repetition Structure Sequence structure The
More informationCCHAPTER SELECTION STATEMENTS HAPTER 3. Objectives
LIANMC03v3_0132221586.QXD 5/15/06 7:41 PM Page 67 CCHAPTER HAPTER 3 1 SELECTION STATEMENTS Objectives To declare boolean type and write Boolean expressions ( 3.2). To distinguish between conditional and
More informationCS212 Midterm. 1. Read the following code fragments and answer the questions.
CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");
More informationP 6.3) import java.util.scanner;
P 6.3) import java.util.scanner; public class CurrencyConverter public static void main (String[] args) Scanner in = new Scanner(System.in); System.out.print("How many euros is one dollar: "); double rate
More informationExercise 0.1 (Review from lectures no submission required)
CSCI 2110- Data Structures and Algorithms Laboratory No. 1 Week of September 10, 2018 Due: Saturday, September 15, 2018, 11.55 PM (five minutes to midnight) Review of Object-Oriented Programming Concepts
More informationDecisions in Java Nested IF Statements
Several Actions The Nested if Statement Decisions in Java Nested IF Statements We have already explored using the if statement to choose a single action (vs no action), or to choose between two actions.
More informationWeb-CAT submission URL: CAT.woa/wa/assignments/eclipse
King Saud University College of Computer & Information Science CSC111 Lab04 Conditional Statements All Sections ------------------------------------------------------------------- Instructions Web-CAT
More informationCONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2
CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,
More informationFundamentals of Programming Data Types & Methods
Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators
More informationCAT.woa/wa/assignments/eclipse
King Saud University College of Computer & Information Science CSC111 Lab10 Arrays II All Sections ------------------------------------------------------------------- Instructions Web-CAT submission URL:
More informationFinal. Your Name CS Fall 2014 December 13, points total Your Instructor and Section
Final Your Name CS 1063 - Fall 2014 December 13, 2014 100 points total Your Instructor and Section I. (10 points, 1 point each) Match each of the terms on the left by choosing the upper case letter of
More information2/9/2015. Chapter 10 Testing and Debugging UNIT TESTS
Chapter 10 Testing and Debugging The Plan For Today Ch.9 Assignment Chapter 10 10.1: Unit Tests 10.2: Providing Test Input 10.3: Test Case Evaluation Ch9/Ch10 Work Time UNIT TESTS The single most important
More informationASSIGNMENT 2. COMP-202A, Fall 2013, All Sections. Due: October 20 th, 2013 (23:59)
ASSIGNMENT 2 COMP-202A, Fall 2013, All Sections Due: October 20 th, 2013 (23:59) Please read the entire PDF before starting. You must do this assignment individually and, unless otherwise specified, you
More informationWrite a program which converts all lowercase letter in a sentence to uppercase.
Write a program which converts all lowercase letter in a sentence to uppercase. For Example: 1) Consider a sentence "welcome to Java Programming!" its uppercase conversion is " WELCOME TO JAVA PROGRAMMING!"
More informationChapter 1 Lab Algorithms, Errors, and Testing
Chapter 1 Lab Algorithms, Errors, and Testing Lab Objectives Be able to write an algorithm Be able to compile a Java program Be able to execute a Java program using the Sun JDK or a Java IDE Be able to
More informationTopic 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
More informationGive one example where you might wish to use a three dimensional array
CS 110: INTRODUCTION TO COMPUTER SCIENCE SAMPLE TEST 3 TIME ALLOWED: 60 MINUTES Student s Name: MAXIMUM MARK 100 NOTE: Unless otherwise stated, the questions are with reference to the Java Programming
More informationTopics. The Development Process
Topics Anatomy of an API A development walkthrough General characteristics of utility classes 8 The Development Process Analysis Design Implementation Testing Deployment 9 1 The Development Process Analysis
More informationBig Java. Fifth Edition. Chapter 3 Fundamental Data Types. Cay Horstmann
Big Java Fifth Edition Cay Horstmann Chapter 3 Fundamental Data Types Chapter Goals To understand integer and floating-point numbers To recognize the limitations of the numeric types To become aware of
More informationMore Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements
More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input
More informationJAVA PROGRAMMING (340)
ANSWER KEY Page 1 of 10 JAVA PROGRAMMING (340) REGIONAL 2017 Production Portion: Program 1: School Vending Machine (400 points) TOTAL POINTS (400 points) Judge/Graders: Please double check and verify all
More informationCIS October 19, 2017
CIS 1068 October 19, 2017 Administrative Stuff String methods due tomorrow Boston Accent Reading: up to chapter 5 Midterms Last Time midterm discussion guessing game Legal Identifiers Ch33zyHaX0R cous
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 000 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More information