1. A company has vans to transport goods from factory to various shops. These vans fall into two categories: 50 items 150 items
|
|
- Junior Barber
- 5 years ago
- Views:
Transcription
1 If..Else Statement Exercises 1. A company has vans to transport goods from factory to various shops. These vans fall into two categories: Category Normal Duty Van Heavy Duty Van Capacity 50 items 150 items Write a program to accept as input the number of items to be carried and outputs a message which states what type of van is to be used for delivery. The number of items should range from 2 to The examination has three papers, each out of 100 marks. To pass, a candidate must get at least an average of 45 marks in all papers. Write a program to read the name and surname of the candidate, together with the marks obtained in every paper. The program should then output the name and surname of the student and whether the student has passed or not. 3. Modify the above program 2 to state whether the student has passed from all papers or not. 4. Modify the above program 2 to state whether the student has passed from at least one paper. 5. Write a program which takes two decimal numbers as input. Then, display a menu of four arithmetic operations: 1 Addition 2 Subtraction 3 Multiplication 4 - Division The program allows the user to select an option by entering whole number and displays the result according to the chosen operation. If an invalid input is entered then prompt Invalid input. 6. Write a program to input three whole numbers and display the largest. 7. Write a program that accepts as input a year and displays a message stating whether it is a leap year or not. For a year to be a leap year it should: Either be divisible by 400 Emanuel Grech emanuel.grech@mail.com P a g e 1
2 Or divisible by 4 but not divisible by Write a program that allows the user to enter the total number of items ordered and displays the amount of vans required to deliver the items, where each van can hold up to 65 items. For example, if the user inputs 140 then the program shall display 3 vans required. 9. Determine the output of the following program: package w2q8; public class W2Q8 int a = 3; int b = 2; int c = 1; int d = 0; boolean case1 = (a==3 && c > 1 d == 0); boolean case2 = ((a-3) < d) (c > 3) ((b + d) >= 3); boolean case3 = (2<=5 && b >=c && (c < d b >= 2)); boolean case4 = (c!= 2 c > b && (a == 4 c >= 10 a - b > d) &&!(c < d)); System.out.println(case1); System.out.println(case2); System.out.println(case3); System.out.println(case4); Emanuel Grech emanuel.grech@mail.com P a g e 2
3 Sample Answers Question 1 package w2q1; public class W2Q1 int items; System.out.print("Enter number of items: "); items = input.nextint(); // Process & Output if (items <= 50) System.out.println("Normal Duty Van is to be used."); else System.out.println("Heavy Duty Van is to be used."); Emanuel Grech emanuel.grech@mail.com P a g e 3
4 Question 2 package w2q2; public class W2Q2 String name; String surname; int mark1, mark2, mark3; double average; System.out.print("Enter name: "); name = input.next(); System.out.print("Enter surname: "); surname = input.next(); System.out.print("Enter first mark: "); mark1 = input.nextint(); System.out.print("Enter second mark: "); mark2 = input.nextint(); System.out.print("Enter third mark: "); mark3 = input.nextint(); // Process average = (mark1 + mark2 + mark3) / 3.0; if (average >= 45) System.out.println(name + " " + surname + " has successfully passed."); else System.out.println(name + " " + surname + " has failed."); Emanuel Grech emanuel.grech@mail.com P a g e 4
5 Question 3 package w2q3; public class W2Q3 String name; String surname; int mark1, mark2, mark3; System.out.print("Enter name: "); name = input.next(); System.out.print("Enter surname: "); surname = input.next(); System.out.print("Enter first mark: "); mark1 = input.nextint(); System.out.print("Enter second mark: "); mark2 = input.nextint(); System.out.print("Enter third mark: "); mark3 = input.nextint(); if (mark1 >= 45 && mark2 >= 45 && mark3 >= 45) System.out.println(name + " " + surname + " has successfully passed from all papers."); else System.out.println(name + " " + surname + " has failed from at least one paper."); Emanuel Grech emanuel.grech@mail.com P a g e 5
6 Question 4 package w2q4; public class W2Q4 String name; String surname; int mark1, mark2, mark3; System.out.print("Enter name: "); name = input.next(); System.out.print("Enter surname: "); surname = input.next(); System.out.print("Enter first mark: "); mark1 = input.nextint(); System.out.print("Enter second mark: "); mark2 = input.nextint(); System.out.print("Enter third mark: "); mark3 = input.nextint(); if (mark1 >= 45 mark2 >= 45 mark3 >= 45) System.out.println(name + " " + surname + " has successfully passed at least one papers."); else System.out.println(name + " " + surname + " has failed from all papers."); Emanuel Grech emanuel.grech@mail.com P a g e 6
7 Question 5 package w2q5; public class W2Q5 double number1, number2, result; int choice; System.out.print("Enter first number: "); number1 = input.nextdouble(); System.out.print("Enter second number: "); number2 = input.nextdouble(); System.out.println("1 Addition"); System.out.println("2 Subtraction"); System.out.println("3 Multiplication"); System.out.println("4 Division"); System.out.print("Enter choice: "); choice = input.nextint(); // Process & Output if (choice == 1) result = number1 + number2; System.out.println(number1 + " + " + number2 + " = " + result); else if (choice == 2) result = number1 - number2; System.out.println(number1 + " - " + number2 + " = " + result); else if (choice == 3) result = number1 * number2; System.out.println(number1 + " * " + number2 + " = " + result); else if (choice == 4) result = number1 / number2; System.out.println(number1 + " / " + number2 + " = " + result); else System.out.println("Invalid Input"); Emanuel Grech emanuel.grech@mail.com P a g e 7
8 Question 6 package w2q6; public class W2Q6 double number1, number2, number3, largest; System.out.print("Enter first number: "); number1 = input.nextdouble(); System.out.print("Enter second number: "); number2 = input.nextdouble(); System.out.print("Enter third number: "); number3 = input.nextdouble(); // Process largest = number1; if (number2 > largest) largest = number2; if (number3 > largest) largest = number3; System.out.println("Largest number is " + largest); Emanuel Grech emanuel.grech@mail.com P a g e 8
9 Question 7 package w2q7; public class W2Q7 int year; System.out.print("Enter year: "); year = input.nextint(); if ((year % 400 == 0) (year % 4 == 0 && (year % 100!= 0))) System.out.println(year + " is a leap year."); else System.out.println(year + " is not a leap year."); Emanuel Grech emanuel.grech@mail.com P a g e 9
10 Question 8 package w2q8; public class W2Q8 System.out.print("Enter number of items ordered: "); int items = input.nextint(); int vans = items / 65; if (items % 65 > 0) vans++; // or vans = vans + 1 System.out.println(vans + " vans required."); Emanuel Grech emanuel.grech@mail.com P a g e 10
11 Question 9 true false true true Emanuel Grech emanuel.grech@mail.com P a g e 11
12 Notes Emanuel Grech P a g e 12
Midterm Examination (MTA)
M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and
More informationChapter 3. Selections. Program Listings
Chapter 3 Selections Program Listings Contents Listing 3.1 Addition Quiz... 3 Listing 3.2 Simple If Demo... 4 Listing 3.3 Subtraction Quiz... 5 Listing 3.4 Compute And Interpret BMI... 6 Listing 3.5 Compute
More informationComputer Programming, I. Laboratory Manual. Experiment #3. Selections
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 #3
More informationFLOW CONTROL. Author: Boaz Kantor The Interdisciplinary Center, Herzliya Introduction to Computer Science Winter Semester
Author: Boaz Kantor The Interdisciplinary Center, Herzliya Introduction to Computer Science Winter 2008-9 Semester FLOW CONTROL Flow Control Hold 2 balls in left hand, 1 ball in right Throw ball from left
More informationM105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014
M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Testing and Debugging
WIT COMP1000 Testing and Debugging Testing Programs When testing your code, always test a variety of input values Never test only one or two values because those samples may not catch some errors Always
More informationArrays OBJECTIVES. In this chapter you will learn:
7 Arrays 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
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 informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Methods
WIT COMP1000 Methods Methods Programs can be logically broken down into a set of tasks Example from horoscope assignment:» Get input (month, day) from user» Determine astrological sign based on inputs
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 informationEXCEPTION HANDLING. // code that may throw an exception } catch (ExceptionType parametername) {
EXCEPTION HANDLING We do our best to ensure program correctness through a rigorous testing and debugging process, but that is not enough. To ensure reliability, we must anticipate conditions that could
More informationAssignment 2.4: Loops
Writing Programs that Use the Terminal 0. Writing to the Terminal Assignment 2.4: Loops In this project, we will be sending our answers to the terminal for the user to see. To write numbers and text to
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 informationCS141 Programming Assignment #8
CS141 Programming Assignment #8 Due Sunday, April 14th. 1- Write a class with methods to do the following output: a) 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 b) 1 2 3 4 5 4 3 2 1 1 2 3 4 * 4 3 2 1 1 2 3 * * * 3 2
More informationTutorial 03. Exercise 1: CSC111 Computer Programming I
College of Computer and Information Sciences CSC111 Computer Programming I Exercise 1: Tutorial 03 Input & Output Operators Expressions A. Show the result of the following code: 1.System.out.println(2
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 informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationJAVA Ch. 4. Variables and Constants Lawrenceville Press
JAVA Ch. 4 Variables and Constants Slide 1 Slide 2 Warm up/introduction int A = 13; int B = 23; int C; C = A+B; System.out.print( The answer is +C); Slide 3 Declaring and using variables Slide 4 Declaring
More informationAP CS A Exam Review Answer Section
AP CS A Exam Review Answer Section TRUE/FALSE 1. ANS: T TOP: Declaring Variables 2. ANS: T TOP: Generating Random Numbers 3. ANS: F TOP: The String Class 4. ANS: F TOP: Method Parameters 5. ANS: F TOP:
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 informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics
WIT COMP1000 Java Basics Java Origins Java was developed by James Gosling at Sun Microsystems in the early 1990s It was derived largely from the C++ programming language with several enhancements Java
More informationFlow of Control Branching 2. Cheng, Wei COMP May 19, Title
Flow of Control Branching 2 Cheng, Wei COMP110-001 May 19, 2014 Title Review of Previous Lecture If else Q1: Write a small program that Reads an integer from user Prints Even if the integer is even Otherwise,
More informationExample: Monte Carlo Simulation 1
Example: Monte Carlo Simulation 1 Write a program which conducts a Monte Carlo simulation to estimate π. 1 See https://en.wikipedia.org/wiki/monte_carlo_method. Zheng-Liang Lu Java Programming 133 / 149
More information(c) ((!(a && b)) == (!a!b)) TRUE / FALSE. (f) ((!(a b)) == (!a &&!b)) TRUE / FALSE. (g) (!(!a) && (c-d > 0) && (b!b))
ComS 207: Programming I Midterm 2, Tue. Mar 21, 2006 Student Name: Student ID Number: Recitation Section: 1. True/False Questions (10 x 1p each = 10p) Determine the value of each boolean expression given
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 informationTutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise
Tutorial # 4 Q1. Evaluate the logical (Boolean) expression in the following exercise 1 int num1 = 3, num2 = 2; (num1 > num2) 2 double hours = 12.8; (hours > 40.2) 3 int funny = 7; (funny!= 1) 4 double
More informationCS141 Programming Assignment #6
CS141 Programming Assignment #6 Due Sunday, Nov 18th. 1) Write a class with methods to do the following output: a) 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 b) 1 2 3 4 5 4 3 2 1 1 2 3 4 * 4 3 2 1 1 2 3 * * * 3 2 1
More informationControl Structures in Java if-else and switch
Control Structures in Java if-else and switch Lecture 4 CGS 3416 Spring 2017 January 23, 2017 Lecture 4CGS 3416 Spring 2017 Selection January 23, 2017 1 / 26 Control Flow Control flow refers to the specification
More informationCheck out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.
Chapter 4 Lab Loops and Files Lab Objectives Be able to convert an algorithm using control structures into Java Be able to write a while loop Be able to write an do-while loop Be able to write a for loop
More informationLAB 4.1 Relational Operators and the if Statement
LAB 4.1 Relational Operators and the if Statement // This program tests whether or not an initialized value of num2 // is equal to a value of num1 input by the user. int main( ) int num1, // num1 is not
More informationAL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I
AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 3- Control Statements: Part I Objectives: To use the if and if...else selection statements to choose among alternative actions. To use the
More informationReading Input from Text File
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Lab 5 Reading Input from Text File Eng. Mohammed Alokshiya November 2, 2014 The simplest
More informationOperators & Expressions
Operators & Expressions Operator An operator is a symbol used to indicate a specific operation on variables in a program. Example : symbol + is an add operator that adds two data items called operands.
More informationAdd Subtract Multiply Divide
ARITHMETIC OPERATORS if AND if/else AND while LOOP Order of Operation (Precedence Part 1) Copyright 2014 Dan McElroy Add Subtract Multiply Divide + Add - Subtract * Multiply / Divide = gives the quotient
More informationJava Console Input/Output The Basics. CGS 3416 Spring 2018
Java Console Input/Output The Basics CGS 3416 Spring 2018 Console Output System.out out is a PrintStream object, a static data member of class System. This represents standard output Use this object to
More informationChapter 2 ELEMENTARY PROGRAMMING
Chapter 2 ELEMENTARY PROGRAMMING Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Objectives To write Java programs to perform simple
More informationLAB 11: METHODS. CPCS The Lab Note Lab 11 Page 1. Statement Purpose:
Statement Purpose: The purpose of this Lab. is to practically familiarize student with how to write the common code once and reuse it without rewriting it using the concept of Methods. Activity Outcomes:
More informationProgram Control Flow
Lecture slides for: Chapter 3 Program Control Flow Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2
More informationProgram Control Flow
Lecture slides for: Chapter 3 Program Control Flow Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 2008. ISBN: 978-1-844480-933-2
More informationExample. Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct.
Example Write a program which sums two random integers and lets the user repeatedly enter a new answer until it is correct. 1... 2 Scanner input = new Scanner(System.in); 3 int x = (int) (Math.random()
More informationChapter Goals. Contents LOOPS
CHAPTER 4 LOOPS Slides by Donald W. Smith TechNeTrain.com Final Draft Oct 30, 2011 Chapter Goals To implement while, for, and do loops To hand-trace the execution of a program To become familiar with common
More informationChapter 3: Operators, Expressions and Type Conversion
101 Chapter 3 Operators, Expressions and Type Conversion Chapter 3: Operators, Expressions and Type Conversion Objectives To use basic arithmetic operators. To use increment and decrement operators. To
More informationChapter 6 Primitive types
Chapter 6 Primitive types Lesson page 6-1. Primitive types Question 1. There are an infinite number of integers, so it would be too ineffient to have a type integer that would contain all of them. Question
More informationCS141 Programming Assignment #4
Due Monday, Oct 31. CS141 Programming Assignment #4 1- Write a program to read in 10 numbers and compute the average, maximum and minimum values (using both while and for loop). Solution 1: * assignment
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 informationMenu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:
Menu Driven Systems While loops, menus and the switch statement Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list while loops recap
More informationComputer Programming, I. Laboratory Manual. Experiment #5. Strings & Text Files Input
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 #5
More informationSelections. CSE 114, Computer Science 1 Stony Brook University
Selections CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Motivation If you assigned a negative value for radius in ComputeArea.java, then you don't want the
More informationAhmadu Bello University Department of Mathematics First Semester Examinations June 2014 COSC211: Introduction to Object Oriented Programming I
Ahmadu Bello University Department of Mathematics First Semester Examinations June 2014 COSC211: Introduction to Object Oriented Programming I Attempt Four questions Time: 120 mins 1. Examine the following
More informationAL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I
AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 2- Arithmetic and Decision Making: Equality and Relational Operators Objectives: To use arithmetic operators. The precedence of arithmetic
More informationEntry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes
Entry Point of Execution: the main Method Elementary Programming EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG For now, all your programming exercises will be defined within the
More informationdownload instant at
2 Introduction to Java Applications: Solutions What s in a name? That which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would
More informationCS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.
Name CS 110 Practice Final Exam originally from Winter, 2003 Instructions: closed books, closed notes, open minds, 3 hour time limit. There are 4 sections for a total of 49 points. Part I: Basic Concepts,
More informationCS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 05 / 31 / 2017 Instructor: Michael Eckmann Today s Topics Questions / Comments? recap and some more details about variables, and if / else statements do lab work
More informationJava provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
More informationJava Classes: Random, Character A C S L E C T U R E 6
Java Classes: Random, Character A C S - 1903 L E C T U R E 6 Random An instance of the Random can be used to generate a stream of random values Typical process: 1. Create a Random object 2. Use the object
More informationControl Statements: Part 1
4 Let s all move one place on. Lewis Carroll Control Statements: Part 1 The wheel is come full circle. William Shakespeare How many apples fell on Newton s head before he took the hint! Robert Frost All
More informationTester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time
Tester vs. Controller Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG For effective illustrations, code examples will mostly be written in the form of a tester
More informationException Handling. Handling bad user input. Dr. Siobhán Drohan Maireád Meagher. Produced by:
Exception Handling Handling bad user input Produced by: Dr. Siobhán Drohan Maireád Meagher Department of Computing and Mathematics http://www.wit.ie/ ShopV4.0 (or any version) When testing it, did you
More informationCT 229. Java Syntax 26/09/2006 CT229
CT 229 Java Syntax 26/09/2006 CT229 Lab Assignments Assignment Due Date: Oct 1 st Before submission make sure that the name of each.java file matches the name given in the assignment sheet!!!! Remember:
More informationMotivation of Loops. Loops. The for Loop (1) Learning Outcomes
Motivation of Loops Loops EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG We may want to repeat the similar action(s) for a (bounded) number of times. e.g., Print
More informationYork University AS/AK/ITEC INTRODUCTION TO DATA STRUCTURES. Midterm Sample I. Examiner: S. Chen Duration: One Hour and 30 Minutes
York University AS/AK/ITEC 2620 3.0 INTRODUCTION TO DATA STRUCTURES Midterm Sample I Examiner: S. Chen Duration: One Hour and 30 Minutes This exam is closed textbook(s) and closed notes. Use of any electronic
More informationLoops. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG
Loops EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG Learning Outcomes Understand about Loops : Motivation: Repetition of similar actions Two common loops: for
More informationElementary Programming
Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Learn ingredients of elementary programming: data types [numbers, characters, strings] literal
More informationCS110 Programming Language I. Lab 6: Multiple branching Mechanisms
CS110 Programming Language I Lab 6: Multiple branching Mechanisms Computer Science Department Fall 2016 Lab Objectives: In this lab, the student will practice: Using switch as a branching mechanism Lab
More informationObject-Oriented Programming
Object-Oriented Programming Java Syntax Program Structure Variables and basic data types. Industry standard naming conventions. Java syntax and coding conventions If Then Else Case statements Looping (for,
More informationCS110 Programming Language I. Lab 3: Java basics II (model answer) Dr. Hadil Shaiba
CS110 Programming Language I Lab 3: Java basics II (model answer) Dr. Hadil Shaiba Computer Science Department Spring 2017 Lab Objectives: In this lab, the student will practice: Defining variables of
More informationEntry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process
Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will
More informationUniversità degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M
Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M Control Structures Intro. Sequential execution Statements are normally executed one
More informationCEN 414 Java Programming
CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea
More informationCSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1
CSE123 LECTURE 3-1 Program Design and Control Structures Repetitions (Loops) 1-1 The Essentials of Repetition Loop Group of instructions computer executes repeatedly while some condition remains true Counter-controlled
More information1 import java.util.*; 2 3 // implementing hash tables as an array of linked lists 4 // and using it to check whether two sequencs are permutations of
1 import java.util.*; 2 3 // implementing hash tables as an array of linked lists 4 // and using it to check whether two sequencs are permutations of each other 5 6 class Node{ 7 8 private int data; 9
More informationEng. Mohammed S. Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Dept. Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 3 Selections
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 informationJava Console Input/Output The Basics
Java Console Input/Output The Basics Lecture 3 COP 3252 Summer 2017 May 23, 2017 Console Output System.out out is a PrintStream object, a static data member of class System. This represents standard output
More informationIntroduction to Java Applications
2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use
More informationThe Java language has a wide variety of modifiers, including the following:
PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access
More informationFollowing is the general form of a typical decision making structure found in most of the programming languages:
Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined
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 information5) (4 points) What is the value of the boolean variable equals after the following statement?
For problems 1-5, give a short answer to the question. (15 points, ~8 minutes) 1) (4 points) Write four Java statements that declare and initialize the following variables: A) a long integer with the value
More informationWhat we will do today Explain and look at examples of. Programs that examine data. Data types. Topic 4. variables. expressions. assignment statements
Topic 4 Variables Once a programmer has understood the use of variables, he has understood the essence of programming -Edsger Dijkstra What we will do today Explain and look at examples of primitive data
More informationLesson 5: Introduction to the Java Basics: Java Arithmetic THEORY. Arithmetic Operators
Lesson 5: Introduction to the Java Basics: Java Arithmetic THEORY Arithmetic Operators There are four basic arithmetic operations: OPERATOR USE DESCRIPTION + op1 + op2 Adds op1 and op2 - op1 + op2 Subtracts
More informationOct Decision Structures cont d
Oct. 29 - Decision Structures cont d Programming Style and the if Statement Even though an if statement usually spans more than one line, it is really one statement. For instance, the following if statements
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 informationHALF-YEARLY EXAMINATIONS FEBRUARY
HALF-YEARLY EXAMINATIONS FEBRUARY 2016 Subject: Computing Form: 4 Time: 1½ hrs MARKING SCHEME Computing Form 4 Half Yearly Exams 2016 Page 1 Section A Answer ALL questions. Each questions carries 5 marks.
More informationDecision Making in C
Decision Making in C Decision making structures require that the programmer specify one or more conditions to be evaluated or tested by the program, along with a statement or statements to be executed
More informationSECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017
SECONDARY SCHOOL, L-IMRIEĦEL HALF YEARLY EXAMINATIONS 2016/2017 YEAR: 10 Computing Time: 1½ Hr. Name: Class: Instructions: 1. Answer all the questions in the space provided on this paper. 2. Calculators
More informationCSCE 145 Exam 1 Review. This exam totals to 100 points. Follow the instructions. Good luck!
CSCE 145 Exam 1 Review This exam totals to 100 points. Follow the instructions. Good luck! Chapter 1 This chapter was mostly terms so expect a fill in the blank style questions on definition. Remember
More informationCS141 Programming Assignment #5
CS141 Programming Assignment #5 Due Wednesday, Nov 16th. 1) Write a class that asks the user for the day number (0 to 6) and prints the day name (Saturday to Friday) using switch statement. Solution 1:
More informationChapter 4: Control Structures I
Chapter 4: Control Structures I Java Programming: From Problem Analysis to Program Design, Second Edition Chapter Objectives Learn about control structures. Examine relational and logical operators. Explore
More informationMotivation of Loops. Loops. The for Loop (1) Learning Outcomes
Motivation of Loops Loops EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG We may want to repeat the similar action(s) for a (bounded) number of times. e.g., Print the Hello World message
More informationFaculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination Tuesday, November 4, 2008 Examiners: Mathieu Petitpas [Section 1] 18:30
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 informationLoops. EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG
Loops EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Understand about Loops : Motivation: Repetition of similar actions Two common loops: for and while Primitive
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 informationUniversità degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M
Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M tutor Isam M. Al Jawarneh, PhD student isam.aljawarneh3@unibo.it Mobile Middleware
More information1 import java.util.*; 2 3 // implementing hash table as an array of linked lists 4 // and using it to print the unique elements of an array 5 6 class
1 import java.util.*; 2 3 // implementing hash table as an array of linked lists 4 // and using it to print the unique elements of an array 5 6 class Node{ 7 8 private int data; 9 private Node nextnodeptr;
More informationCS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 19: NOV. 15TH INSTRUCTOR: JIAYIN WANG
CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 19: NOV. 15TH INSTRUCTOR: JIAYIN WANG 1 Notice Assignment Class Exercise 19 is assigned Homework 8 is assigned Both Homework 8 and Exercise 19 are
More informationCS 112 Introduction to Programming
CS 112 Introduction to Programming Program Analysis Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu Admin q PS5 Walkthrough Thursday
More information