java_advanced_io_demos_index 08/14/18 07:14:41 walton 1 of 1

Size: px
Start display at page:

Download "java_advanced_io_demos_index 08/14/18 07:14:41 walton 1 of 1"

Transcription

1 java_advanced_io_demos_index 08/14/18 07:14:41 walton 1 of 1 JAVA ADVANCED IO DEMOS Tue Aug 14 07:14:41 EDT 2018 Advanced Input/Output Demonstrations vcalc 2D Geometry Algorithms vcalc.txt vcalc.java Problem statement. JAVA solution.

2 vcalc.txt 12/29/14 05:23:47 walton 1 of 4 Simple Vector Calculator You have been asked to implement a very simple vector calculator. The tokens of its input are <separator> ::= ( ), : <end-of-line> <symbol> ::= <symbol-character> <symbol-character>* <symbol-character> ::= character other than a <separator>, single space, horizontal tab, and form feed Given this the following are particular tokens: <variable> ::= <symbol> beginning with a letter <operator> ::= one of the following symbols: + - * / ^! && ==!= < <= > >= Whitespace is ignored except for its role in separating tokens and for the <end-of-line> token. Note that operators must be delimited by whitespace or separators. <simple-statement> ::= print <symbol>* <end-of-line> println <symbol>* <end-of-line> <variable> = <expression> <end-of-line> clear <variable>* <end-of-line> <expression> ::= <boolean-expression> <scalar-expression> <vector-expression> <boolean-expression> ::= <boolean-atom>! <boolean-atom> <boolean-atom> && <boolean-atom> <boolean-atom> <boolean-atom> <scalar-atom> == <scalar-atom> <scalar-atom>!= <scalar-atom> <scalar-atom> < <scalar-atom> <scalar-atom> <= <scalar-atom> <scalar-atom> > <scalar-atom> <scalar-atom> >= <scalar-atom> Blank lines are ignored. Any line whose first nonwhitespace characters are is a comment line and is ignored. Given these tokens, the syntax accepted by the calculator is: <program> ::= <statement>* <statement> ::= <simple-statement> if <boolean-atom>: <simple-statement> <boolean-atom> ::= <variable> with boolean value true false <scalar-expression> ::= <scalar-atom> - <scalar-atom> <scalar-atom> <scalar-atom> + <scalar-atom> <scalar-atom> - <scalar-atom> <scalar-atom> * <scalar-atom> <scalar-atom> / <scalar-atom> <scalar-atom> ::= <variable> with scalar value <number>

3 vcalc.txt 12/29/14 05:23:47 walton 2 of 4 <vector-expression> ::= <vector-atom> - <vector-atom> <vector-atom> angle <vector-atom> <vector-atom> + <vector-atom> <vector-atom> - <vector-atom> <scalar-atom> * <vector-atom> <vector-atom> ^ <scalar-atom> <vector-atom> ::= <variable> with vector value ( <scalar-atom>, <scalar-atom> ) This syntax is very limited so it is easy to implement. It has the following limits/peculiarities: 1. At most one operation such as + or - can appear in a statement. 2. Only very simple conditional statements are allowed, such as if x: y = 5 + z if m: y = true if p: print Y IS y 3. Operators such as +, *,, and must be delimited by whitespace, parentheses, commas, or colons. The semantics are what you would expect given the following: 1. Variables can have boolean, scalar, or vector values, or no values. Variables with no values are only legal in print statements: see below. 2. The expression s denotes the absolute value of the scalar s. 3. The expression v denotes the length value of the vector. 4. Angles are measured in degrees. Special care is taken with angles that are multiples of 90 degrees to be sure that rotations and the angle function give exact results. 5. The expression v ^ s denotes rotation of the vector v by the scalar angle s. 6. The print and println statements print symbols separated by single spaces. But if a symbol is a variable name and the variable has a value, the value is printed instead of the symbol. The print statement ends by printing just a single space so the line may be continued, while the println statement ends by printing a line end. 7. The clear statement clears the variables listed, meaning that these variables are given no value (and therefore print as their names). If no variables are given, all variables are cleared. 8. Attempts to assign a value to a variable named any of the following is an error: Input true false if clear print println Other language special symbols can be used as variable names. Input is a program. Lines and variable names may be arbitrarily long. Input ends with an end of file.

4 vcalc.txt 12/29/14 05:23:47 walton 3 of 4 Output Output is the lines printed by print statements. Numbers should be printed using decimal notation with 14 decimal places, but with trailing 0 s stripped, and integers printed with no decimal point. Scientific notation should NOT be used. Syntax and other errors, including divide by zero and taking the angle of a zero vector, should be detected and abort execution with an error message. There is no required format for error messages, and the program will not be judged with erroneous input. Sample Input Sample vcalc Input x = 5 y = -10 z = x + y println x + y = z p1 = ( 3, 4 ) p2 = ( -7, 3 ) p = ( 1, 4 ) p12 = p2 - p1 rp12 = p12 ^ 90 y = p * rp12 y1 = p1 * rp12 y2 = p2 * rp12 println p y = y ### p1 y = y1 ### p2 y = y2 print p is x = y > y1 if x: print to the left of x = y == y1 if x: print on x = y < y1 if x: print to the right of println p1 ---> p2 Sample Output = -5 p y = -39 ### p1 y = -37 ### p2 y = -37 (1, 4) is to the right of (3, 4) ---> (-7, 3)

5 vcalc.txt 12/29/14 05:23:47 walton 4 of 4 File: vcalc.txt Author: Bob Walton <walton@seas.harvard.edu> Date: Wed Jan 23 11:22:53 EST 2013 The authors have placed this file in the public domain; they make no warranty and accept no liability for this file. RCS Info (may not be true date or author): $Author: walton $ $Date: 2013/01/23 16:23:07 $ $RCSfile: vcalc.txt,v $ $Revision: 1.11 $

6 vcalc.java 12/29/14 05:23:47 walton 1 of 10 Solution to the Simple Vector Calculator Problem File: vcalc.java Authors: Bob Walton (walton@seas.harvard.edu) Date: Mon Feb 18 06:17:03 EST 2013 The authors have placed this program in the public domain; they make no warranty and accept no liability for this program. import java.util.scanner; import java.util.regex.pattern; import java.util.hashtable; import java.text.decimalformat; public class vcalc static boolean debug = false; static void print ( String s ) System.out.print ( s ); static void println ( String s ) System.out.println ( s ); static void println ( ) System.out.println(); static void dprint ( String s ) if ( debug ) System.out.print ( s ); static void dprintln ( String s ) if ( debug ) System.out.println ( s ); Used to get the equivalent of %.14f but with trailing fraction zeros suppressed. Use decimal.format ( x ) to convert double to string. static DecimalFormat decimal = new DecimalFormat ( "0.##############" ); final static Scanner scan = new Scanner ( System.in ).usedelimiter ( "[(),: \t\f\n]+" ); Returns next token or EOL if end of line or EOF if end of file. We make EOL and EOF be printable strings as tokens are printed in many error messages. Implements one-token backup. Implements line_number. All tokens are printable Strings and none are of zero length. final static String EOL = new String ( "(END-OF-LINE)" ); final static String EOF = new String ( "(END-OF-FILE)" ); static boolean backup = false; Set backup = true to backup. static int line_number = 0; Current line number; 1, 2, 3,... static String last_token = EOL; static Pattern comment = Pattern.compile ( "\\G[ \t\f]*(.* )(?m)$" ); Skips to end of line for both comment and blank line. static Pattern end_of_line = Pattern.compile ( "\\G\n" ); Use in findwithinhorizon ( end_of_line, 1 ). static Pattern end_space = Pattern.compile ( "\\G[ \t\f]*(?m)$" ); Skips horizontal whitespace before end of line. static Pattern separator = Pattern.compile ( "\\G[ \t\f]*([(),:])" );

7 vcalc.java 12/29/14 05:23:47 walton 2 of 10 Use in findinline ( separator ). static String get_token ( ) if ( backup ) backup = false; return last_token; if ( last_token.equals ( EOL ) ) while ( true ) ++ line_number; String s = scan.findinline ( comment ); if ( scan.findwithinhorizon ( end_of_line, 1 ) == null ) break; last_token = scan.findinline ( separator ); if ( last_token!= null ) last_token = scan.match().group ( 1 ); scan.findinline ( end_space ); Get rid of any horizontal whitespace before a line feed. if ( scan.findwithinhorizon ( end_of_line, 1 )!= null ) last_token = EOL; if ( scan.hasnext() ) last_token = scan.next(); last_token = EOF; dprint ( "" + last_token + "" ); return last_token; Print error message and exit. static void error ( String message ) println ( "ERROR in line " + line_number + ":" ); println ( " " + message ); System.exit ( 1 ); Convert token to number. If this is not possible, just return null. static Double token_to_number ( String token ) try return Double.valueOf ( token ); catch ( NumberFormatException e ) return null; static boolean is_scalar ( String token ) return token_to_number ( token )!= null; static double token_to_scalar ( String token ) Double d = token_to_number ( token ); if ( d == null ) error ( "expected scalar and got " + token + " " ); return d.doublevalue(); static void check_not_eof ( String token ) if ( token == EOF )

8 vcalc.java 12/29/14 05:23:47 walton 3 of 10 error ( "unexpected end of file" ); static void skip ( String desired ) String token = get_token(); if (! token.equals ( desired ) ) error ( "expected " + desired + " but found " + token + " " ); static boolean is_variable ( String token ) return ( Character.isLetter ( token.charat ( 0 ) ) ); static void check_variable ( String token ) if (! is_variable ( token ) ) error ( " " + token + " is not a variable" ); static class Vector double x, y; Vector ( double xval, double yval ) x = xval; y = yval; public String tostring ( ) return "(" + decimal.format ( x ) + ", " + decimal.format ( y ) + ")"; static Vector negate ( Vector v ) return new Vector ( - v.x, - v.y ); static Vector add ( Vector v1, Vector v2 ) return new Vector ( v1.x + v2.x, v1.y + v2.y ); static Vector subtract ( Vector v1, Vector v2 ) return new Vector ( v1.x - v2.x, v1.y - v2.y ); static double multiply ( Vector v1, Vector v2 ) return v1.x * v2.x + v1.y * v2.y; static Vector multiply ( double s, Vector v ) return new Vector ( s * v.x, s * v.y ); static double length ( Vector v ) return Math.sqrt ( v.x * v.x + v.y * v.y ); static double angle ( Vector v ) double result; We take extra care with angles that are multiples of 90 degrees. This is only necessary if one is using exact equality with integer coordinates instead of approximate equality. if ( v.x == 0 && v.y == 0 ) error ( "angle of zero vector" ); result = Double.NaN; Needed so compiler will not think that result does not get a value. if ( v.x == 0 ) result = ( v.y > 0? +90 : -90 ); if ( v.y == 0 ) result = ( v.x > 0? 0 : +180 );

9 vcalc.java 12/29/14 05:23:47 walton 4 of 10 result = Math.atan2 ( v.y, v.x ); result *= / Math.PI; return result; static Vector rotate ( Vector v, double angle ) double sin, cos; We take extra care with angles that are multiples of 90 degrees. This is only necessary if one is using exact equality with integer coordinates instead of approximate equality. int k = (int) ( angle / 90 ); if ( angle == k * 90 ) switch ( k % 4 ) case 0: sin = 0; cos = 1; break; case +1: case -3: sin = 1; cos = 0; break; case +2: case -2: sin = 0; cos = -1; break; case +3: case -1: sin = -1; cos = 0; break; default: sin = Double.NaN; cos = Double.NaN; Needed so compiler will not think that sin and cos do not get values. angle *= Math.PI / 180; sin = Math.sin ( angle ); cos = Math.cos ( angle ); return new Vector ( cos * v.x - sin * v.y, sin * v.x + cos * v.y ); final static int BOOLEAN = 1; final static int SCALAR = 2; final static int VECTOR = 3; static class Value int type; BOOLEAN, SCALAR, or VECTOR. boolean b; Value if BOOLEAN. double s; Value if SCALAR. Vector v; Value if VECTOR. public String tostring ( ) if ( type == BOOLEAN ) return String.valueOf ( b ); if ( type == SCALAR ) return decimal.format ( s ); if ( type == VECTOR ) return v.tostring(); return new String ( "BAD OBJECT TYPE " + type ); static Hashtable<String,Value> variable_table = new Hashtable<String,Value>(); Maps variable name Strings to Values. static void require_boolean ( Value v1 ) if ( v1.type!= BOOLEAN ) error ( "operand should be boolean" ); static void require_boolean ( Value v1, Value v2 ) if ( v1.type!= BOOLEAN ) error ( "first operand should be boolean" ); if ( v2.type!= BOOLEAN ) error

10 vcalc.java 12/29/14 05:23:47 walton 5 of 10 ( "second operand should be boolean" ); error ( "second operand should be scalar" ); static void require_scalar ( Value v1 ) if ( v1.type!= SCALAR ) error ( "operand should be scalar" ); static void require_scalar ( Value v1, Value v2 ) if ( v1.type!= SCALAR ) error ( "first operand should be scalar" ); if ( v2.type!= SCALAR ) error ( "second operand should be scalar" ); static void require_vector ( Value v1 ) if ( v1.type!= VECTOR ) error ( "operand should be vector" ); static void require_vector ( Value v1, Value v2 ) if ( v1.type!= VECTOR ) error ( "first operand should be vector" ); if ( v2.type!= VECTOR ) error ( "second operand should be vector" ); static void require_scalar_vector ( Value v1, Value v2 ) if ( v1.type!= SCALAR ) error ( "first operand should be scalar" ); if ( v2.type!= VECTOR ) error ( "second operand should be vector" ); static void require_vector_scalar ( Value v1, Value v2 ) if ( v1.type!= VECTOR ) error ( "first operand should be vector" ); if ( v2.type!= SCALAR ) Require v1 to be SCALAR or VECTOR and return true if SCALAR, false if VECTOR. static boolean is_scalar ( Value v1 ) if ( v1.type == SCALAR ) return true; if ( v1.type == VECTOR ) return false; error ( "operand should be scalar or vector" ); return false; never executed Require v1 and v2 to be BOTH SCALAR or BOTH VECTOR and return true if SCALAR, false if VECTOR. static boolean is_scalar ( Value v1, Value v2 ) if ( v1.type!= v2.type ) error ( "operands should both be scalar" + " or both be vector" ); if ( v1.type == SCALAR ) return true; if ( v2.type == VECTOR ) return false; error ( "operands should be scalar or vector" ); return false; never executed Reads a constant value and returns its Value, or a variable with a value and returns a COPY of its Value. Always returns a NEW Value.

11 vcalc.java 12/29/14 05:23:47 walton 6 of 10 static Value get_value ( ) Value v = new Value(); String token = get_token(); if ( token.equals ( "(" ) ) v.type = VECTOR; token = get_token(); double x = token_to_scalar ( token ); skip ( "," ); token = get_token(); double y = token_to_scalar ( token ); skip ( ")" ); v.v = new Vector ( x, y ); if ( token.equals ( "true" ) ) v.type = BOOLEAN; v.b = true; if ( token.equals ( "false" ) ) v.type = BOOLEAN; v.b = false; if ( is_variable ( token ) ) Value v2 = variable_table.get ( token ); if ( v2 == null ) error ( " " + token + " unassigned" ); v.type = v2.type; v.b = v2.b; v.s = v2.s; v.v = v2.v; if ( is_scalar ( token ) ) v.type = SCALAR; v.s = token_to_scalar ( token ); error ( "expected true, false, " + " scalar constant, " + " vector constant, " + " or variable but got " + token + " " ); dprint ( "[" + v.tostring() + "]" ); return v; Execute clear... statement after clear token has been read and skipped. static void execute_clear ( ) boolean found = false; while ( true ) String token = get_token(); if ( token.equals ( EOL ) ) break; check_variable ( token ); variable_table.remove ( token ); found = true; if (! found ) variable_table.clear(); Execute println... statement after println token has been read and skipped, BUT do not output final space or line end. static void execute_print ( ) boolean first = true; while ( true ) String token = get_token(); if ( token.equals ( EOL ) ) break; if ( first ) first = false;

12 vcalc.java 12/29/14 05:23:47 walton 7 of 10 print ( " " ); Value v = variable_table.get ( token ); if ( v == null ) print ( token ); print ( v.tostring() ); Execute variable =... statement after variable = tokens have been read and skipped. Check variable token to be sure its a variable name. static void execute_assign ( String variable ) check_variable ( variable ); if ( variable.equals ( "true" ) variable.equals ( "false" ) ) error ( "attempt to assign a value to " + variable + " " ); String op = get_token(); Value v1 = null; This is both the first value read and the final resulting value. Read and process statement up to but not including EOL. if ( op.equals ( "-" ) ) v1 = get_value(); if ( is_scalar ( v1 ) ) v1.s = - v1.s; v1.v = negate ( v1.v ); if ( op.equals ( " " ) ) v1 = get_value(); require_scalar ( v1 ); skip ( " " ); v1.s = Math.abs ( v1.s ); if ( op.equals ( " " ) ) v1 = get_value(); require_vector ( v1 ); skip ( " " ); v1.s = length ( v1.v ); v1.type = SCALAR; if ( op.equals ( "angle" ) ) v1 = get_value(); require_vector ( v1 ); v1.s = angle ( v1.v ); v1.type = SCALAR; if ( op.equals ( "!" ) ) v1 = get_value(); require_boolean ( v1 ); v1.b =! v1.b; Case where there is either a binary operator or no operator. backup = true; v1 = get_value(); op = get_token(); if ( op.equals ( "+" ) ) if ( is_scalar ( v1, v2 ) )

13 vcalc.java 12/29/14 05:23:47 walton 8 of 10 v1.s += v2.s; v1.v = add ( v1.v, v2.v ); if ( op.equals ( "-" ) ) if ( is_scalar ( v1, v2 ) ) v1.s -= v2.s; v1.v = subtract ( v1.v, v2.v ); if ( op.equals ( "*" ) ) if ( is_scalar ( v1 ) ) if ( is_scalar ( v2 ) ) v1.s *= v2.s; v1.v = multiply ( v1.s, v2.v ); v1.type = VECTOR; require_vector ( v1, v2 ); v1.s = multiply ( v1.v, v2.v ); v1.type = SCALAR; if ( op.equals ( "/" ) ) require_scalar ( v1, v2 ); if ( v2.s == 0 ) error ( "zero divisor" ); v1.s /= v2.s; if ( op.equals ( "^" ) ) require_vector_scalar ( v1, v2 ); v1.v = rotate ( v1.v, v2.s ); if ( op.equals ( "&&" ) ) require_boolean ( v1, v2 ); v1.b = v1.b && v2.b; if ( op.equals ( " " ) ) require_boolean ( v1, v2 ); v1.b = v1.b v2.b; if ( op.equals ( "==" ) ) require_scalar ( v1, v2 ); v1.b = ( v1.s == v2.s ); v1.type = BOOLEAN; if ( op.equals ( "!=" ) ) require_scalar ( v1, v2 ); v1.b = ( v1.s!= v2.s ); v1.type = BOOLEAN; if ( op.equals ( "<" ) ) require_scalar ( v1, v2 ); v1.b = ( v1.s < v2.s ); v1.type = BOOLEAN; if ( op.equals ( "<=" ) ) require_scalar ( v1, v2 ); v1.b = ( v1.s <= v2.s );

14 vcalc.java 12/29/14 05:23:47 walton 9 of 10 v1.type = BOOLEAN; if ( op.equals ( ">" ) ) require_scalar ( v1, v2 ); v1.b = ( v1.s > v2.s ); v1.type = BOOLEAN; if ( op.equals ( ">=" ) ) require_scalar ( v1, v2 ); v1.b = ( v1.s >= v2.s ); v1.type = BOOLEAN; if (! op.equals ( EOL ) ) error ( " " + op + " unrecognized" ); backup = true; Skip statement ending EOL. skip ( EOL ); if ( token.equals ( "if" ) ) Process if statement. If condition is true, just skip past :. Other- wise skip past EOL and go to next statement. Value v = get_value(); require_boolean ( v ); skip ( ":" ); if (! v.b ) while ( true ) token = get_token(); check_not_eof ( token ); if ( token.equals ( EOL ) ) break; continue; token = get_token(); variable_table.put ( variable, v1 ); dprintln ( "ASSIGN " + v1.tostring() + " TO " + variable ); public static void main ( String[] args ) debug = ( args.length > 0 ); Loop to read and execute a statement. while ( true ) String token = get_token(); if ( token == EOF ) break; if ( token.equals ( "clear" ) ) execute_clear(); if ( token.equals ( "print" ) ) execute_print(); print ( " " ); if ( token.equals ( "println" ) ) execute_print(); println(); skip ( "=" ); execute_assign ( token );

15 vcalc.java 12/29/14 05:23:47 walton 10 of 10

java_help_index 08/14/18 07:14:34 walton 1 of 1

java_help_index 08/14/18 07:14:34 walton 1 of 1 java_help_index 08/14/18 07:14:34 walton 1 of 1 JAVA LANGUAGE HELP Tue Aug 14 07:14:34 EDT 2018 Programming Language Specific Help ----------- -------- -------- ---- java How to write JAVA solutions. jdebug

More information

Getting started with Java

Getting started with Java Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving

More information

Full file at

Full file at Chapter 2 Console Input and Output Multiple Choice 1) Valid arguments to the System.out object s println method include: (a) Anything with double quotes (b) String variables (c) Variables of type int (d)

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

COMP 202 Java in one week

COMP 202 Java in one week CONTENTS: Basics of Programming Variables and Assignment Data Types: int, float, (string) Example: Implementing a calculator COMP 202 Java in one week The Java Programming Language A programming language

More information

Section 2.2 Your First Program in Java: Printing a Line of Text

Section 2.2 Your First Program in Java: Printing a Line of Text Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two

More information

ing execution. That way, new results can be computed each time the Class The Scanner

ing execution. That way, new results can be computed each time the Class The Scanner ing execution. That way, new results can be computed each time the run, depending on the data that is entered. The Scanner Class The Scanner class, which is part of the standard Java class provides convenient

More information

QUIZ: What value is stored in a after this

QUIZ: What value is stored in a after this QUIZ: What value is stored in a after this statement is executed? Why? a = 23/7; QUIZ evaluates to 16. Lesson 4 Statements, Expressions, Operators Statement = complete instruction that directs the computer

More information

Introduction to Computer Science Unit 2. Exercises

Introduction to Computer Science Unit 2. Exercises Introduction to Computer Science Unit 2. Exercises Note: Curly brackets { are optional if there is only one statement associated with the if (or ) statement. 1. If the user enters 82, what is 2. If the

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

CA4003 Compiler Construction Assignment Language Definition

CA4003 Compiler Construction Assignment Language Definition CA4003 Compiler Construction Assignment Language Definition David Sinclair 2017-2018 1 Overview The language is not case sensitive. A nonterminal, X, is represented by enclosing it in angle brackets, e.g.

More information

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Lexical Analysis Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Compiler Passes Analysis of input program (front-end) character stream

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

Section 2.2 Your First Program in Java: Printing a Line of Text

Section 2.2 Your First Program in Java: Printing a Line of Text Chapter 2 Introduction to Java Applications Section 2.2 Your First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler are denoted using a. Two

More information

What did we talk about last time? Examples switch statements

What did we talk about last time? Examples switch statements Week 4 - Friday What did we talk about last time? Examples switch statements History of computers Hardware Software development Basic Java syntax Output with System.out.print() Mechanical Calculation

More information

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

Wentworth 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 information

Chapter 3. Selections

Chapter 3. Selections Chapter 3 Selections 1 Outline 1. Flow of Control 2. Conditional Statements 3. The if Statement 4. The if-else Statement 5. The Conditional operator 6. The Switch Statement 7. Useful Hints 2 1. Flow of

More information

Lecture Set 2: Starting Java

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 0 This Course: Intro to Procedural

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments.

12/22/11. Java How to Program, 9/e. Help you get started with Eclipse and NetBeans integrated development environments. Java How to Program, 9/e Education, Inc. All Rights Reserved. } Java application programming } Use tools from the JDK to compile and run programs. } Videos at www.deitel.com/books/jhtp9/ Help you get started

More information

Lecture Set 2: Starting Java

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 0 This Course: Intro to Procedural

More information

BASIC INPUT/OUTPUT. Fundamentals of Computer Science

BASIC INPUT/OUTPUT. Fundamentals of Computer Science BASIC INPUT/OUTPUT Fundamentals of Computer Science Outline: Basic Input/Output Screen Output Keyboard Input Simple Screen Output System.out.println("The count is " + count); Outputs the sting literal

More information

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CONTENTS: 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 information

ARG! Language Reference Manual

ARG! Language Reference Manual ARG! Language Reference Manual Ryan Eagan, Mike Goldin, River Keefer, Shivangi Saxena 1. Introduction ARG is a language to be used to make programming a less frustrating experience. It is similar to C

More information

Full file at

Full file at Chapter 2 Introduction to Java Applications Section 2.1 Introduction ( none ) Section 2.2 First Program in Java: Printing a Line of Text 2.2 Q1: End-of-line comments that should be ignored by the compiler

More information

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below. C212 Early Evaluation Exam Mon Feb 10 2014 Name: Please provide brief (common sense) justifications with your answers below. 1. What is the type (and value) of this expression: 5 * (7 + 4 / 2) 2. What

More information

PROGRAMMING FUNDAMENTALS

PROGRAMMING FUNDAMENTALS PROGRAMMING FUNDAMENTALS Q1. Name any two Object Oriented Programming languages? Q2. Why is java called a platform independent language? Q3. Elaborate the java Compilation process. Q4. Why do we write

More information

Typescript on LLVM Language Reference Manual

Typescript on LLVM Language Reference Manual Typescript on LLVM Language Reference Manual Ratheet Pandya UNI: rp2707 COMS 4115 H01 (CVN) 1. Introduction 2. Lexical Conventions 2.1 Tokens 2.2 Comments 2.3 Identifiers 2.4 Reserved Keywords 2.5 String

More information

COMP 202. Java in one week

COMP 202. Java in one week COMP 202 CONTENTS: Basics of Programming Variables and Assignment Data Types: int, float, (string) Example: Implementing a calculator Java in one week The Java Programming Language A programming language

More information

JME Language Reference Manual

JME Language Reference Manual JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.

More information

2.8. Decision Making: Equality and Relational Operators

2.8. Decision Making: Equality and Relational Operators Page 1 of 6 [Page 56] 2.8. Decision Making: Equality and Relational Operators A condition is an expression that can be either true or false. This section introduces a simple version of Java's if statement

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1 CSC 1051 Algorithms and Data Structures I Midterm Examination February 24, 2014 Name: KEY 1 Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in

More information

Full file at C How to Program, 6/e Multiple Choice Test Bank

Full file at   C How to Program, 6/e Multiple Choice Test Bank 2.1 Introduction 2.2 A Simple Program: Printing a Line of Text 2.1 Lines beginning with let the computer know that the rest of the line is a comment. (a) /* (b) ** (c) REM (d)

More information

AP CS Unit 3: Control Structures Notes

AP CS Unit 3: Control Structures Notes AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts

More information

COMP 202 Java in one week

COMP 202 Java in one week COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of

More information

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance.

c) Comments do not cause any machine language object code to be generated. d) Lengthy comments can cause poor execution-time performance. 2.1 Introduction (No questions.) 2.2 A Simple Program: Printing a Line of Text 2.1 Which of the following must every C program have? (a) main (b) #include (c) /* (d) 2.2 Every statement in C

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

The Warhol Language Reference Manual

The Warhol Language Reference Manual The Warhol Language Reference Manual Martina Atabong maa2247 Charvinia Neblett cdn2118 Samuel Nnodim son2105 Catherine Wes ciw2109 Sarina Xie sx2166 Introduction Warhol is a functional and imperative programming

More information

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1

Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1 Module 3 SELECTION STRUCTURES 2/15/19 CSE 1321 MODULE 3 1 Motivation In the programs we have written thus far, statements are executed one after the other, in the order in which they appear. Programs often

More information

More 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! 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 information

Computational Expression

Computational Expression Computational Expression Variables, Primitive Data Types, Expressions Janyl Jumadinova 28-30 January, 2019 Janyl Jumadinova Computational Expression 28-30 January, 2019 1 / 17 Variables Variable is a name

More information

Text User Interfaces. Keyboard IO plus

Text User Interfaces. Keyboard IO plus Text User Interfaces Keyboard IO plus User Interface and Model Model: objects that solve problem at hand. User interface: interacts with user getting input from user giving output to user reporting on

More information

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION

EDIABAS BEST/2 LANGUAGE DESCRIPTION. VERSION 6b. Electronic Diagnostic Basic System EDIABAS - BEST/2 LANGUAGE DESCRIPTION EDIABAS Electronic Diagnostic Basic System BEST/2 LANGUAGE DESCRIPTION VERSION 6b Copyright BMW AG, created by Softing AG BEST2SPC.DOC CONTENTS CONTENTS...2 1. INTRODUCTION TO BEST/2...5 2. TEXT CONVENTIONS...6

More information

Repe$$on CSC 121 Spring 2017 Howard Rosenthal

Repe$$on CSC 121 Spring 2017 Howard Rosenthal Repe$$on CSC 121 Spring 2017 Howard Rosenthal Lesson Goals Learn the following three repetition structures in Java, their syntax, their similarities and differences, and how to avoid common errors when

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

More information

Chapter 2: Using Data

Chapter 2: Using Data Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

More information

Java for Python Programmers. Comparison of Python and Java Constructs Reading: L&C, App B

Java for Python Programmers. Comparison of Python and Java Constructs Reading: L&C, App B Java for Python Programmers Comparison of Python and Java Constructs Reading: L&C, App B 1 General Formatting Shebang #!/usr/bin/env python Comments # comments for human readers - not code statement #

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string

COMP 202. Built in Libraries and objects. CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Built in Libraries and objects CONTENTS: Introduction to objects Introduction to some basic Java libraries string COMP 202 Objects and Built in Libraries 1 Classes and Objects An object is an

More information

Chapter 2 Basic Elements of C++

Chapter 2 Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 2-1 Chapter 2 Basic Elements of C++ At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion

More information

SMURF Language Reference Manual Serial MUsic Represented as Functions

SMURF Language Reference Manual Serial MUsic Represented as Functions SMURF Language Reference Manual Serial MUsic Represented as Functions Richard Townsend, Lianne Lairmore, Lindsay Neubauer, Van Bui, Kuangya Zhai {rt2515, lel2143, lan2135, vb2363, kz2219}@columbia.edu

More information

Definite Loops. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting

Definite Loops. Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting Unit 2, Part 2 Definite Loops Computer Science S-111 Harvard University David G. Sullivan, Ph.D. Using a Variable for Counting Let's say that we're using a variable i to count the number of times that

More information

BLOCK STRUCTURE. class block main method block do-while statement block if statement block. if statement block. Block Structure Page 1

BLOCK STRUCTURE. class block main method block do-while statement block if statement block. if statement block. Block Structure Page 1 BLOCK STRUCTURE A block is a bundle of statements in a computer program that can include declarations and executable statements. A programming language is block structured if it (1) allows blocks to be

More information

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018 Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment

More information

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 2: Variables, and Data Types Sandeep Manjanna, Summer 2015 Announcements Midterm Exams on 4 th of June (12:35 14:35) Room allocation will be announced soon

More information

Check 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.

Check 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 information

Full file at

Full file at Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

More information

Program Fundamentals

Program Fundamentals Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

More information

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Java 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 information

Building Java Programs

Building 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 information

AP Computer Science Unit 1. Writing Programs Using BlueJ

AP Computer Science Unit 1. Writing Programs Using BlueJ AP Computer Science Unit 1. Writing Programs Using BlueJ 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save

More information

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Entry 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 information

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Review Chapters 1 to 4. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Review Chapters 1 to 4 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor:

More information

Java Bytecode (binary file)

Java Bytecode (binary file) Java is Compiled Unlike Python, which is an interpreted langauge, Java code is compiled. In Java, a compiler reads in a Java source file (the code that we write), and it translates that code into bytecode.

More information

Page 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge:

Page 1 / 3. Page 2 / 18. Page 3 / 8. Page 4 / 21. Page 5 / 15. Page 6 / 20. Page 7 / 15. Total / 100. Pledge: This pledged exam is open text book and closed notes. Different questions have different points associated with them. Because your goal is to maximize your number of points, we recommend that you do not

More information

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs

Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs Algorithms and Java basics: pseudocode, variables, assignment, and interactive programs CSC 1051 Algorithms and Data Structures I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova

More information

CS 541 Spring Programming Assignment 2 CSX Scanner

CS 541 Spring Programming Assignment 2 CSX Scanner CS 541 Spring 2017 Programming Assignment 2 CSX Scanner Your next project step is to write a scanner module for the programming language CSX (Computer Science experimental). Use the JFlex scanner-generation

More information

Università 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 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 information

Selection Statements and operators

Selection Statements and operators Selection Statements and operators CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

More information

Chapter 2: Basic Elements of Java

Chapter 2: Basic Elements of Java Chapter 2: Basic Elements of Java TRUE/FALSE 1. The pair of characters // is used for single line comments. ANS: T PTS: 1 REF: 29 2. The == characters are a special symbol in Java. ANS: T PTS: 1 REF: 30

More information

Building Java Programs

Building 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 information

Section 2: Introduction to Java. Historical note

Section 2: Introduction to Java. Historical note The only way to learn a new programming language is by writing programs in it. - B. Kernighan & D. Ritchie Section 2: Introduction to Java Objectives: Data Types Characters and Strings Operators and Precedence

More information

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Sequence 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 information

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

More information

Repe$$on CSC 121 Fall 2015 Howard Rosenthal

Repe$$on CSC 121 Fall 2015 Howard Rosenthal Repe$$on CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Learn the following three repetition methods, their similarities and differences, and how to avoid common errors when using them: while do-while

More information

First Java Program - Output to the Screen

First Java Program - Output to the Screen First Java Program - Output to the Screen These notes are written assuming that the reader has never programmed in Java, but has programmed in another language in the past. In any language, one of the

More information

Comp Assignment 2: Object-Oriented Scanning for Numbers, Words, and Quoted Strings

Comp Assignment 2: Object-Oriented Scanning for Numbers, Words, and Quoted Strings Comp 401 - Assignment 2: Object-Oriented Scanning for Numbers, Words, and Quoted Strings Date Assigned: Thu Aug 29, 2013 Completion Date: Fri Sep 6, 2013 Early Submission Date: Wed Sep 4, 2013 This work

More information

Postfix Notation is a notation in which the operator follows its operands in the expression (e.g ).

Postfix Notation is a notation in which the operator follows its operands in the expression (e.g ). Assignment 5 Introduction For this assignment, you will write classes to evaluate arithmetic expressions represented as text. For example, the string "1 2 ( * 4)" would evaluate to 15. This process will

More information

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

More information

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA 1 TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared

More information

AP Computer Science Unit 1. Writing Programs Using BlueJ

AP Computer Science Unit 1. Writing Programs Using BlueJ AP Computer Science Unit 1. Writing Programs Using BlueJ 1. Open up BlueJ. Click on the Project menu and select New Project. You should see the window on the right. Navigate to wherever you plan to save

More information

Language Reference Manual

Language Reference Manual TAPE: A File Handling Language Language Reference Manual Tianhua Fang (tf2377) Alexander Sato (as4628) Priscilla Wang (pyw2102) Edwin Chan (cc3919) Programming Languages and Translators COMSW 4115 Fall

More information

DaMPL. Language Reference Manual. Henrique Grando

DaMPL. Language Reference Manual. Henrique Grando DaMPL Language Reference Manual Bernardo Abreu Felipe Rocha Henrique Grando Hugo Sousa bd2440 flt2107 hp2409 ha2398 Contents 1. Getting Started... 4 2. Syntax Notations... 4 3. Lexical Conventions... 4

More information

Programming Lecture 3

Programming Lecture 3 Programming Lecture 3 Expressions (Chapter 3) Primitive types Aside: Context Free Grammars Constants, variables Identifiers Variable declarations Arithmetic expressions Operator precedence Assignment statements

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

Chapter 2: Data and Expressions

Chapter 2: Data and Expressions Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University April 21, 2015 Chapter 2: Data and Expressions CS 121 1 / 53 Chapter 2 Part 1: Data Types

More information

STUDENT LESSON A7 Simple I/O

STUDENT LESSON A7 Simple I/O STUDENT LESSON A7 Simple I/O Java Curriculum for AP Computer Science, Student Lesson A7 1 STUDENT LESSON A7 Simple I/O INTRODUCTION: The input and output of a program s data is usually referred to as I/O.

More information

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp DM550 / DM857 Introduction to Programming Peter Schneider-Kamp petersk@imada.sdu.dk http://imada.sdu.dk/~petersk/dm550/ http://imada.sdu.dk/~petersk/dm857/ OBJECT-ORIENTED PROGRAMMING IN JAVA 2 Programming

More information

STUDENT LESSON A12 Iterations

STUDENT LESSON A12 Iterations STUDENT LESSON A12 Iterations Java Curriculum for AP Computer Science, Student Lesson A12 1 STUDENT LESSON A12 Iterations INTRODUCTION: Solving problems on a computer very often requires a repetition of

More information

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

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

More information

VLC : Language Reference Manual

VLC : Language Reference Manual VLC : Language Reference Manual Table Of Contents 1. Introduction 2. Types and Declarations 2a. Primitives 2b. Non-primitives - Strings - Arrays 3. Lexical conventions 3a. Whitespace 3b. Comments 3c. Identifiers

More information

File class in Java. Scanner reminder. File methods 10/28/14. File Input and Output (Savitch, Chapter 10)

File class in Java. Scanner reminder. File methods 10/28/14. 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". Input is received from the keyboard, mouse, files.

More information

DM550 Introduction to Programming part 2. Jan Baumbach.

DM550 Introduction to Programming part 2. Jan Baumbach. DM550 Introduction to Programming part 2 Jan Baumbach jan.baumbach@imada.sdu.dk http://www.baumbachlab.net COURSE ORGANIZATION 2 Course Elements Lectures: 10 lectures Find schedule and class rooms in online

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Oct Decision Structures cont d

Oct 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 information

A Simple Syntax-Directed Translator

A Simple Syntax-Directed Translator Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called

More information

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program Objectives Chapter 2: Basic Elements of C++ In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates

More information

Introduction to C# Applications

Introduction to C# Applications 1 2 3 Introduction to C# Applications OBJECTIVES To write simple C# applications To write statements that input and output data to the screen. To declare and use data of various types. To write decision-making

More information