Arun chakravarthy Alagar samy. Technical Skill. Java Code Challenge - Basic Java

Size: px
Start display at page:

Download "Arun chakravarthy Alagar samy. Technical Skill. Java Code Challenge - Basic Java"

Transcription

1 Arun chakravarthy Alagar samy DATE OF LAST ACTIVITY TEST Java Code Challenge - Basic LANGUAGES USED Java Technical Skill CANDIDATE RESULT SKILL THRESHOLD Strongly recommended regarding technical potential. Recommended regarding technical potential. More information needed. Not recommended if technical ability is crucial. TASKS IN TEST CORRECT SUBMISSIONS PLAGIARISM LANGUAGE EASY Speed Limit 2 Java EASY A New Alphabet 1 Java MEDIUM Phone List 4 Java

2 EASY Speed Limit SHOWN AS Problem A MEMORY LIMIT 1024 MB CORRECTNESS Accepted PLAGIARISM Not detected CPU TIME LIMIT 1 second LANGUAGE USED Java ATTEMPTS 2 Bill and Ted are taking a road trip. But the odometer in their car is broken, so they don t know how many miles they have driven. Fortunately, Bill has a working stopwatch, so they can record their speed and the total time they have driven. Unfortunately, their record keeping strategy is a little odd, so they need help computing the total distance driven. You are to write a program to do this computation. For example, if their log shows Speed in miles per hour Total elapsed time in hours this means they drove 2 hours at 20 miles per hour, then 6 2 = 4 hours at 30 miles per hour, then 7 6 = 1 hour at 10 miles per hour. The distance driven is then = = 170 miles. Note that the total elapsed time is always since the beginning of the trip, not since the previous entry in their log. Input The input consists of one or more data sets (at most 10). Each set starts with a line containing an integer n, 1 n 10, followed by n pairs of values, one pair per line. The first value in a pair, s, is the speed in miles per hour and the second value, t, is the total elapsed time. Both s and t are integers, 1 s 90 and 1 t 12. The values for t are always in strictly increasing order. A value of

3 1 for n signals the end of the input. Output For each input set, print the distance driven, followed by a space, followed by the word miles. Sample Input 1 Sample Output miles 180 miles 90 miles

4 TotalDistance2.java package com.assessment.question1; import java.util.arraylist; import java.util.list; import java.util.scanner; public class TotalDistance2 { public static void main(string[] args) { Scanner sc = new Scanner(System.in); List<Integer> results = new ArrayList<Integer>(); try { int val = 0; while ((val = sc.nextint())!= -1) { int datasetcount = val; int prevhourentered = 0; int totalmiles = 0; int itr = 0; while ((itr++) < datasetcount) { int speed = sc.nextint(); int currhourentered = sc.nextint(); totalmiles += speed (currhourentered - prevhourentered); prevhourentered = currhourentered; results.add(totalmiles); for (int miles : results) { System.out.println(miles + " miles"); sc.close(); catch (Exception e) { System.out.println("Main class error :" + e.getmessage()); finally { if (sc!= null) sc.close();

5 EASY A New Alphabet SHOWN AS Problem B MEMORY LIMIT 1024 MB CORRECTNESS Accepted PLAGIARISM Not detected CPU TIME LIMIT 1 second LANGUAGE USED Java ATTEMPTS 1 A New Alphabet has been developed for Internet communications. While the glyphs of the new alphabet don t necessarily improve communications in any meaningful way, they certainly make us feel cooler. You are tasked with creating a translation program to speed up the switch to our more elite New Alphabet by automatically translating ASCII plaintext symbols to our new symbol set. The new alphabet is a one-to-many translation (one character of the English alphabet translates to anywhere between 1 and 6 other characters), with each character translation as follows: Photo by r. nial bradshaw ( Original New English Description Original New English Description at symbol n []\[] brackets, backslash, brackets b 8 digit eight o 0 digit zero c ( open parenthesis p D bar, capital D d ) bar, close parenthesis q (,) parenthesis, comma, parenthesis e 3 digit three r Z bar, capital Z f # number sign (hash) s $ dollar sign g 6 digit six t '][' quote, brackets, quote h [-] bracket, hyphen, bracket u _ bar, underscore, bar i bar v \/ backslash, forward slash j _ underscore, bar w \/\/ four slashes k < bar, less than x { curly braces l 1 digit one y `/ backtick, forward slash

6 m []\/[] brackets, slashes, brackets z 2 digit two For instance, translating the string Hello World! would result in: [-]3110 \/\/0 Z1 )! Note that uppercase and lowercase letters are both converted, and any other characters remain the same (the exclamation point and space in this example). Input Input contains one line of text, terminated by a newline. The text may contain any characters in the ASCII range (space through tilde), as well as 9 (tab). Only characters listed in the above table (A Z, a z) should be translated; any non-alphabet characters should be printed (and not modified). Input has at most characters. Output Output the input text with each letter (lowercase and uppercase) translated into its New Alphabet counterpart. Sample Input 1 Sample Output 1 All your base are belong to `/0 _ Z Z3 8310[]\[]6 ']['0 _ $. Sample Input 2 Sample Output 2 What's the Frequency, Kenneth? \/\/[-]@'][''$ ']['[-]3 # Z3(,) _ 3[]\[](`/, <3[]\[][]\[]3']['[-]? Sample Input 3 Sample Output 3 A new D[-]@83']['!

7 SwitchConverter.java package com.assessment.question2; import java.util.scanner; public class SwitchConverter { public static void main(string[] args) { Scanner sc = new Scanner(System.in); try { String input = sc.nextline().tolowercase(); String[] encode = { "@", "8", "(", " )", "3", "#", "6", "[-]", " ", "_ ", " <", "1", "[]\\/[]", "[]\\[]", "0", " D", "(,)", " Z", "$", "']['", " _ ", "\\/", "\\/\\/", "{", "`/", "2" ; char[] letters = input.tochararray(); for (char ch : letters) { int ascii = (int) ch; if (ascii >= 97 && ascii <= 122) System.out.print(encode[ascii - 97]); else System.out.print(ch); sc.close(); catch (Exception e) { finally {

8 MEDIUM Phone List SHOWN AS Problem C MEMORY LIMIT 1024 MB CORRECTNESS Accepted PLAGIARISM Not detected CPU TIME LIMIT 4 seconds LANGUAGE USED Java ATTEMPTS 4 Given a list of phone numbers, determine if it is consistent in the sense that no number is the prefix of another. Let s say the phone catalogue listed these numbers: Emergency 911 Alice Bob In this case, it s not possible to call Bob, because the central would direct your call to the emergency line as soon as you had dialled the first three digits of Bob s phone number. So this list would not be consistent. Input The first line of input gives a single integer, 1 t 40, the number of test cases. Each test case starts with n, the number of phone numbers, on a separate line, 1 n Then follows n lines with one unique phone number on each line. A phone number is a sequence of at most ten digits. Note that leading zeros in phone numbers are significant, e.g., 0911 is a different phone number than 911. Output For each test case, output YES if the list is consistent, or NO otherwise. Sample Input 1 Sample Output 1

9 NO YES

10 PhoneDirectory2.java package com.assessment.question1; import java.util.arraylist; import java.util.collection; import java.util.collections; import java.util.list; import java.util.scanner; public class PhoneDirectory2 { public static void main(string[] args) { Scanner sc = new Scanner(System.in); ArrayList<String> phoneentries = null; ArrayList<String> results = new ArrayList<String>(); try { int val = sc.nextint(); do { int phoneentry = sc.nextint(); phoneentries = new ArrayList<String>(); while ((phoneentry--) > 0) { phoneentries.add(sc.next()); BinarySearchTree bst = new BinarySearchTree(phoneEntries); if (!bst.invalidtree) results.add("yes"); else results.add("no"); while ((--val) > 0); for (String result : results) { System.out.println(result); catch (Exception e) { System.out.println("Main class error :" + e.getmessage()); e.printstacktrace(); sc.close(); class TreeNode<E> { private E data; private TreeNode<E> left; private TreeNode<E> right; / Constructs a new node with the given data and references to the given left and right nodes. public TreeNode(E data, TreeNode<E> left, TreeNode<E> right) { this.data = data; this.left = left; this.right = right;

11 / Constructs a new node containing the given data. Its left and right references will be set to null. public TreeNode(E data) { this(data, null, null); / Returns the item currently stored in this node. public E getdata() { return data; / Overwrites the item stored in this Node with the given data item. public void setdata(e data) { this.data = data; / Returns this Node's left child. If there is no left left, returns null. public TreeNode<E> getleft() { return left; / Causes this Node to point to the given left child Node. public void setleft(treenode<e> left) { this.left = left; / Returns this nodes right child. If there is no right child, returns null. public TreeNode<E> getright() { return right; / Causes this Node to point to the given right child Node. public void setright(treenode<e> right) { this.right = right; class BinarySearchTree<E extends Comparable<E>> { private TreeNode<E> root = null; private int size = 0; public boolean InvalidTree = false; / Creates an empty tree. public BinarySearchTree() { public BinarySearchTree(Collection<E> col) { List<E> list = new ArrayList<E>(col); Collections.shuffle(list); for (int i = 0; i < list.size(); i++) { add(list.get(i)); / Adds the given item to this BST.

12 public void add(e item) { this.size++; if (this.root == null) { // tree is empty, so just add item this.root = new TreeNode<E>(item); else { // find where to insert, with pointer to parent node TreeNode<E> parent = null; TreeNode<E> curr = this.root; boolean wentleft = true; // InvalidTree = true; while (curr!= null &&!InvalidTree) { // will execute at least once parent = curr; int flen = item.tostring().length(); int slen = curr.getdata().tostring().length(); String fstring = null; String sstring = null; if (flen > slen) { fstring = item.tostring(); sstring = curr.getdata().tostring(); else { sstring = item.tostring(); fstring = curr.getdata().tostring(); if (fstring.startswith(sstring)) { InvalidTree = true; else { if (item.compareto(curr.getdata()) <= 0) { curr = curr.getleft(); wentleft = true; else { curr = curr.getright(); wentleft = false; if (!InvalidTree) { // now add new node on appropriate side of parent curr = new TreeNode<E>(item); if (wentleft) { parent.setleft(curr); else { parent.setright(curr); / Returns item from tree that is equivalent (according to compareto) to the given item. If item is not in tree, returns null. public E get(e item) { return get(item, this.root); / Finds it in the subtree rooted at the given node. private E get(e item, TreeNode<E> node) { if (node == null) { return null; else if (item.compareto(node.getdata()) < 0) { return get(item, node.getleft());

13 else if (item.compareto(node.getdata()) > 0) { return get(item, node.getright()); else { // found it! return node.getdata(); / Returns the number of elements currently in this BST. public int size() { return this.size; / Returns a single-line representation of this BST's contents. Specifically, this is a comma-separated list of all elements in their natural Comparable ordering. The list is surrounded by [] characters. public String tostring() { return "[" + tostring(this.root) + "]"; private String tostring(treenode<e> n) { // would have been simpler to use Iterator... but not implemented yet. if (n == null) { return ""; else { String str = ""; str += tostring(n.getleft()); if (!str.isempty()) { str += ", "; str += n.getdata(); if (n.getright()!= null) { str += ", "; str += tostring(n.getright()); return str; public String tofullstring() { StringBuilder sb = new StringBuilder(); tofullstring(root, sb); return sb.tostring(); / Preorder traversal of the tree that builds a string representation in the given n root of subtree to be sb StringBuilder in which to create a string representation / private void tofullstring(treenode<e> n, StringBuilder sb) { if (n == null) { return; sb.append(n.getdata().tostring()); sb.append("\n"); if (n.getleft()!= null) { sb.append("<"); else if (n.getright()!= null) { sb.append(">"); if (n.getleft()!= null n.getright()!= null) { tofullstring(n.getleft(), sb); tofullstring(n.getright(), sb);

a graph is a data structure made up of nodes in graph theory the links are normally called edges

a graph is a data structure made up of nodes in graph theory the links are normally called edges 1 Trees Graphs a graph is a data structure made up of nodes each node stores data each node has links to zero or more nodes in graph theory the links are normally called edges graphs occur frequently in

More information

Problem A A New Alphabet

Problem A A New Alphabet Problem A A New Alphabet A New Alphabet has been developed for Internet communications. While the glyphs of the new alphabet don t necessarily improve communications in any meaningful way, they certainly

More information

CSC 321: Data Structures. Fall 2016

CSC 321: Data Structures. Fall 2016 CSC 321: Data Structures Fall 2016 Trees & recursion trees, tree recursion BinaryTree class BST property BinarySearchTree class: override add, contains search efficiency 1 Trees a tree is a nonlinear data

More information

CSC 321: Data Structures. Fall 2012

CSC 321: Data Structures. Fall 2012 CSC 321: Data Structures Fall 2012 Proofs & trees proof techniques direct proof, proof by contradiction, proof by induction trees tree recursion BinaryTree class 1 Direct proofs the simplest kind of proof

More information

CmpSci 187: Programming with Data Structures Spring 2015

CmpSci 187: Programming with Data Structures Spring 2015 CmpSci 187: Programming with Data Structures Spring 2015 Lecture #17, Implementing Binary Search Trees John Ridgway April 2, 2015 1 Implementing Binary Search Trees Review: The BST Interface Binary search

More information

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic

BIT Java Programming. Sem 1 Session 2011/12. Chapter 2 JAVA. basic BIT 3383 Java Programming Sem 1 Session 2011/12 Chapter 2 JAVA basic Objective: After this lesson, you should be able to: declare, initialize and use variables according to Java programming language guidelines

More information

Password Management Guidelines for Cisco UCS Passwords

Password Management Guidelines for Cisco UCS Passwords Guidelines for Cisco UCS Passwords, page 1 Guidelines for Cisco UCS Usernames, page 3 Configuring the Maximum Number of Password Changes for a Change Interval, page 4 Configuring a No Change Interval for

More information

CS 231 Data Structures and Algorithms Fall Binary Search Trees Lecture 23 October 29, Prof. Zadia Codabux

CS 231 Data Structures and Algorithms Fall Binary Search Trees Lecture 23 October 29, Prof. Zadia Codabux CS 231 Data Structures and Algorithms Fall 2018 Binary Search Trees Lecture 23 October 29, 2018 Prof. Zadia Codabux 1 Agenda Ternary Operator Binary Search Tree Node based implementation Complexity 2 Administrative

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

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

Computer Science II Fall 2009

Computer Science II Fall 2009 Name: Computer Science II Fall 2009 Exam #2 Closed book and notes. This exam should have five problems and six pages. Problem 0: [1 point] On a scale of 0 5, where 5 is highest, I think I deserve a for

More information

Birkbeck (University of London) Software and Programming 1 In-class Test Mar Answer ALL Questions

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

More information

CS 307 Final Spring 2009

CS 307 Final Spring 2009 Points off 1 2 3 4 5 Total off Net Score CS 307 Final Spring 2009 Name UTEID login name Instructions: 1. Please turn off your cell phones. 2. There are 5 questions on this test. 3. You have 3 hours to

More information

Binary Search Trees. Chapter 21. Binary Search Trees

Binary Search Trees. Chapter 21. Binary Search Trees Chapter 21 Binary Search Trees Binary Search Trees A Binary Search Tree is a binary tree with an ordering property that allows O(log n) retrieval, insertion, and removal of individual elements. Defined

More information

C Sc 227 Practice Final Summer 13 Name 200 pts

C Sc 227 Practice Final Summer 13 Name 200 pts C Sc 227 Practice Final Summer 13 Name 200 pts 1. Use our familiar Node class (shown below with data and next instance variables) and this view of a linked structure to answer the questions a) through

More information

IMPLEMENTING BINARY TREES

IMPLEMENTING BINARY TREES IMPLEMENTING BINARY TREES Chapter 6 A Binary Tree BinaryTree a = new BinaryTree(); a A B C D E F 1 A Binary Tree BinaryTree a = new BinaryTree(); a A B C D E F A Binary

More information

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide

JOSE LUIS JUAREZ VIVEROS com) has a. non-transferable license to use this Student Guide Module 3 Identifiers, Keywords, and Types Objectives Upon completion of this module, you should be able to: Use comments in a source program Distinguish between valid and invalid identifiers Recognize

More information

Programming with Java

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

Mr. Monroe s Guide to Mastering Java Syntax

Mr. Monroe s Guide to Mastering Java Syntax Mr. Monroe s Guide to Mastering Java Syntax Getting Started with Java 1. Download and install the official JDK (Java Development Kit). 2. Download an IDE (Integrated Development Environment), like BlueJ.

More information

CIS265 Homework7 A (partial) solution showing creation/traversal of an expression-tree made from a a valid arithmetical expression

CIS265 Homework7 A (partial) solution showing creation/traversal of an expression-tree made from a a valid arithmetical expression CIS265 Homework7 A (partial) solution showing creation/traversal of an expression-tree made from a a valid arithmetical expression Driver package csu.matos; import java.util.stack; import java.util.stringtokenizer;

More information

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

More information

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language 1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

More information

Honors Computer Programming 1-2. Chapter 5 Exam Prep

Honors Computer Programming 1-2. Chapter 5 Exam Prep Honors Computer Programming 1-2 Chapter 5 Exam Prep 1. True or False: curly braces When writing an if statement, you MUST use if { }. false: you must use parenthesis if ( ) 2. In Java, to implement a choice

More information

Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming. Instructor: Masoud Asghari Web page:   Ch: 3 Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

More information

Java Identifiers, Data Types & Variables

Java Identifiers, Data Types & Variables Java Identifiers, Data Types & Variables 1. Java Identifiers: Identifiers are name given to a class, variable or a method. public class TestingShastra { //TestingShastra is an identifier for class char

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

from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions

from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions Exam information in lab Tue, 18 Apr 2017, 9:00-noon programming part from inheritance onwards but no GUI programming expect to see an inheritance question, recursion questions, data structure questions

More information

Final Exam. Name: Student ID: Section: Signature:

Final Exam. Name: Student ID: Section: Signature: Final Exam PIC 10B, Spring 2016 Name: Student ID: Section: Discussion 3A (2:00 2:50 with Kelly) Discussion 3B (3:00 3:50 with Andre) I attest that the work presented in this exam is my own. I have not

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2017S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

1. Is it currently raining in Tucson (4pts) a) Yes b) No? c) Don't know d) Couldn't know (not in Tucson)

1. Is it currently raining in Tucson (4pts) a) Yes b) No? c) Don't know d) Couldn't know (not in Tucson) 1. Is it currently raining in Tucson (4pts) a) Yes b) No? c) Don't know d) Couldn't know (not in Tucson) 2. Use our familiar Node class (shown below with data and next instance variables) and this view

More information

Array Lists. CSE 1310 Introduction to Computers and Programming University of Texas at Arlington. Last modified: 4/17/18

Array Lists. CSE 1310 Introduction to Computers and Programming University of Texas at Arlington. Last modified: 4/17/18 Array Lists CSE 1310 Introduction to Computers and Programming University of Texas at Arlington Last modified: 4/17/18 1 DEPARTAMENTAL FINAL EXAM Monday, DEC 10, 5:30pm-8pm rooms will be determined 2 Fixed

More information

Introduction to Java & Fundamental Data Types

Introduction to Java & Fundamental Data Types Introduction to Java & Fundamental Data Types LECTURER: ATHENA TOUMBOURI How to Create a New Java Project in Eclipse Eclipse is one of the most popular development environments for Java, as it contains

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

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

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

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

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

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

C Sc 127B Practice Test 3 Section Leader Name 100 pts

C Sc 127B Practice Test 3 Section Leader Name 100 pts C Sc 127B Practice Test 3 Section Leader Name 100 pts 1. Use the following binary tree to write out each of the three traversals indicated below. (12pts) 1 2 3 4 5 6 Preorder traversal Inorder traversal

More information

C Sc 227 Practice Final Summer 12 Name 200pt

C Sc 227 Practice Final Summer 12 Name 200pt C Sc 227 Practice Final Summer 12 Name 200pt 1. Is it currently raining in Tucson (4pts) a) Yes b) No? c) Don't know d) Couldn't know (I'm not in Tucson) 2. Use our familiar Node class (shown below with

More information

School of Computer Science CPS109 Course Notes 5 Alexander Ferworn Updated Fall 15

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

CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

More information

Assignment-1 Final Code. Student.java

Assignment-1 Final Code. Student.java package com.ds.assgn1a; public class Student { public int rollno; public String name; public double marks; Assignment-1 Final Code Student.java public Student(int rollno, String name, double marks){ this.rollno

More information

CIS 265 Lecture Notes Binary Trees V. Matos DRIVER1. package csu.matos; public class Driver1 {

CIS 265 Lecture Notes Binary Trees V. Matos DRIVER1. package csu.matos; public class Driver1 { CIS 265 Lecture Notes Binary Trees V. Matos DRIVER1 public class Driver1 { /** * GOAL: create a simple binary tree using custom-made linked nodes * nodes carry Integer numbers */ public static void main(string[]

More information

AP Computer Science A Unit 2. Exercises

AP Computer Science A Unit 2. Exercises AP Computer Science A Unit 2. Exercises A common standard is 24-bit color where 8 bits are used to represent the amount of red light, 8 bits for green light, and 8 bits for blue light. It is the combination

More information

Center for Computation & Louisiana State University -

Center for Computation & Louisiana State University - Knowing this is Required Anatomy of a class A java program may start with import statements, e.g. import java.util.arrays. A java program contains a class definition. This includes the word "class" followed

More information

SPEECH RECOGNITION COMMON COMMANDS

SPEECH RECOGNITION COMMON COMMANDS SPEECH RECOGNITION COMMON COMMANDS FREQUENTLY USED COMMANDS The table below shows some of the most commonly used commands in Windows Speech Recognition. The words in italics indicate that many different

More information

What does this program print?

What does this program print? What does this program print? Attempt 1 public class Rec { private static int f(int x){ if(x

More information

Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

More information

Basics of Java Programming

Basics of Java Programming Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

More information

STUDENT LESSON AB30 Binary Search Trees

STUDENT LESSON AB30 Binary Search Trees STUDENT LESSON AB30 Binary Search Trees Java Curriculum for AP Computer Science, Student Lesson AB30 1 STUDENT LESSON AB30 Binary Search Trees INTRODUCTION: A binary tree is a different kind of data structure

More information

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual

COMS W4115 Programming Languages & Translators GIRAPHE. Language Reference Manual COMS W4115 Programming Languages & Translators GIRAPHE Language Reference Manual Name UNI Dianya Jiang dj2459 Vince Pallone vgp2105 Minh Truong mt3077 Tongyun Wu tw2568 Yoki Yuan yy2738 1 Lexical Elements

More information

Final Exam Solutions PIC 10B, Spring 2016

Final Exam Solutions PIC 10B, Spring 2016 Final Exam Solutions PIC 10B, Spring 2016 Problem 1. (10 pts) Consider the Fraction class, whose partial declaration was given by 1 class Fraction { 2 public : 3 Fraction ( int num, int den ); 4... 5 int

More information

Java+- Language Reference Manual

Java+- Language Reference Manual Fall 2016 COMS4115 Programming Languages & Translators Java+- Language Reference Manual Authors Ashley Daguanno (ad3079) - Manager Anna Wen (aw2802) - Tester Tin Nilar Hlaing (th2520) - Systems Architect

More information

An overview of Java, Data types and variables

An overview of Java, Data types and variables An overview of Java, Data types and variables Lecture 2 from (UNIT IV) Prepared by Mrs. K.M. Sanghavi 1 2 Hello World // HelloWorld.java: Hello World program import java.lang.*; class HelloWorld { public

More information

Introduction to Programming (Java) 4/12

Introduction to Programming (Java) 4/12 Introduction to Programming (Java) 4/12 Michal Krátký Department of Computer Science Technical University of Ostrava Introduction to Programming (Java) 2008/2009 c 2006 2008 Michal Krátký Introduction

More information

Java Coding 2. Decisions, decisions!

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

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey

CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey CMPS 134: Computer Science I Fall 2011 Test #1 October 5 Name Dr. McCloskey 1. For each statement, circle the response (or write its letter on the underscore) that best completes that statement. (i) is

More information

C Sc 127B Practice Test 3 Section Leader Name 100 pts

C Sc 127B Practice Test 3 Section Leader Name 100 pts C Sc 127B Practice Test 3 Section Leader Name 100 pts 1. Use the following binary tree to write out each of the three traversals indicated below. (15pts) 1 2 3 4 5 6 Preorder traversal Inorder traversal

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

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

CS 152: Data Structures with Java Hello World with the IntelliJ IDE CS 152: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Electrical and Computer Engineering building

More information

Chapter 2: Basic Elements of C++

Chapter 2: Basic Elements of C++ Chapter 2: Basic Elements of C++ Objectives 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

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

Advanced Java Concepts Unit 5: Trees. Notes and Exercises

Advanced Java Concepts Unit 5: Trees. Notes and Exercises Advanced Java Concepts Unit 5: Trees. Notes and Exercises A Tree is a data structure like the figure shown below. We don t usually care about unordered trees but that s where we ll start. Later we will

More information

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Assoc. Prof. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved. Assoc. Prof. Marenglen Biba (C) 2010 Pearson Education, Inc. All Advanced Java This chapter discusses class String, class StringBuilder and class Character from the java.lang package. These classes provide

More information

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

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction Chapter 2: Basic Elements of C++ C++ Programming: From Problem Analysis to Program Design, Fifth Edition 1 Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers

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

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

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

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

CS 307 Final Spring 2011

CS 307 Final Spring 2011 Points off 1 2 3 4A 4B 4C 5A 5B Total Off Net CS 307 Final Spring 2011 Name UTEID login name Instructions: 1. Please turn off your cell phones and all other electronic devices. 2. There are 5 questions

More information

Section 05: Solutions

Section 05: Solutions Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access

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

3. Java - Language Constructs I

3. Java - Language Constructs I Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

More information

CSC 222: Object-Oriented Programming. Spring 2012

CSC 222: Object-Oriented Programming. Spring 2012 CSC 222: Object-Oriented Programming Spring 2012 Lists, data storage & access ArrayList class methods: add, get, size, remove, contains, set, indexof, tostring generics, for-each loop autoboxing & unboxing

More information

More on Java. Object-Oriented Programming

More on Java. Object-Oriented Programming More on Java Object-Oriented Programming Outline Instance variables vs. local variables Primitive vs. reference types Object references, object equality Objects' and variables' lifetime Parameters passing

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

IT Web and Software Developer Software Development Standards

IT Web and Software Developer Software Development Standards IT Web and Software Developer Software Development Standards Definition of terms Identifier An identifier is the name you give variables, methods, classes, packages, interfaces and named constants. Pascal

More information

Building Java Programs

Building Java Programs Building Java Programs Binary Trees reading: 17.1 17.3 2 Trees in computer science TreeMap and TreeSet implementations folders/files on a computer family genealogy; organizational charts AI: decision trees

More information

CSC 231 DYNAMIC PROGRAMMING HOMEWORK Find the optimal order, and its optimal cost, for evaluating the products A 1 A 2 A 3 A 4

CSC 231 DYNAMIC PROGRAMMING HOMEWORK Find the optimal order, and its optimal cost, for evaluating the products A 1 A 2 A 3 A 4 CSC 231 DYNAMIC PROGRAMMING HOMEWORK 10-1 PROFESSOR GODFREY MUGANDA 1. Find the optimal order, and its optimal cost, for evaluating the products where A 1 A 2 A 3 A 4 A 1 is 10 4 A 2 is 4 5 A 3 is 5 20

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

Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes. 10th ICSE. Saravanan Ganesh Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set Character set is a set of valid characters that a language can recognise A character represents any letter, digit or any other sign Java uses

More information

4. If the following Java statements are executed, what will be displayed?

4. If the following Java statements are executed, what will be displayed? Chapter 2 MULTIPLE CHOICE 1. To compile a program named First, use the following command a. java First.java b. javac First c. javac First.java d. compile First.javac 2. A Java program must have at least

More information

Full file at

Full file at Gaddis: Starting Out with Java: Early Objects, 4/e Test Bank 1 Chapter 2 Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Which of the

More information

12 Abstract Data Types

12 Abstract Data Types 12 Abstract Data Types 12.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT). Define

More information

DEPARTMENT OF MATHS, MJ COLLEGE

DEPARTMENT OF MATHS, MJ COLLEGE T. Y. B.Sc. Mathematics MTH- 356 (A) : Programming in C Unit 1 : Basic Concepts Syllabus : Introduction, Character set, C token, Keywords, Constants, Variables, Data types, Symbolic constants, Over flow,

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

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

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Expressions and Data Types CSC 121 Fall 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types and

More information

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Objectives. In this chapter, you will:

Objectives. In this chapter, you will: Objectives In this chapter, you will: Become familiar with functions, special symbols, and identifiers in C++ Explore simple data types Discover how a program evaluates arithmetic expressions Learn about

More information

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

More information

MIDTERM REVIEW. midterminformation.htm

MIDTERM REVIEW.   midterminformation.htm MIDTERM REVIEW http://pages.cpsc.ucalgary.ca/~tamj/233/exams/ midterminformation.htm 1 REMINDER Midterm Time: 7:00pm - 8:15pm on Friday, Mar 1, 2013 Location: ST 148 Cover everything up to the last lecture

More information

C Sc 227 Practice Final

C Sc 227 Practice Final C Sc 227 Practice Final Name 1. Use the Node class shown question 13 on this page below with data and next instance variables and this view of a linked structure to answer the questions a) through d) a)

More information

Computer Programming, I. Laboratory Manual. Experiment #2. Elementary Programming

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

CSCS-200 Data Structure and Algorithms. Lecture

CSCS-200 Data Structure and Algorithms. Lecture CSCS-200 Data Structure and Algorithms Lecture-13-14-15 Recursion What is recursion? Sometimes, the best way to solve a problem is by solving a smaller version of the exact same problem first Recursion

More information

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016

CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 CS4120/4121/5120/5121 Spring 2016 Xi Language Specification Cornell University Version of May 11, 2016 In this course you will start by building a compiler for a language called Xi. This is an imperative,

More information

Data Structures COE 312 ExamII Preparation Exercises

Data Structures COE 312 ExamII Preparation Exercises Data Structures COE 312 ExamII Preparation Exercises 1. Patrick designed an algorithm called search2d that can be used to find a target element x in a two dimensional array A of size N = n 2. The algorithm

More information

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings

Last Time. University of British Columbia CPSC 111, Intro to Computation Alan J. Hu. Readings University of British Columbia CPSC 111, Intro to Computation Alan J. Hu Writing a Simple Java Program Intro to Variables Readings Your textbook is Big Java (3rd Ed). This Week s Reading: Ch 2.1-2.5, Ch

More information

Language Reference Manual

Language Reference Manual ALACS Language Reference Manual Manager: Gabriel Lopez (gal2129) Language Guru: Gabriel Kramer-Garcia (glk2110) System Architect: Candace Johnson (crj2121) Tester: Terence Jacobs (tj2316) Table of Contents

More information