CSCI Problem Solving, Programming and Computers Spring, 2016 Assignment 2 {Inheritance, Interfaces, Arrays}
|
|
- Matilda Cannon
- 6 years ago
- Views:
Transcription
1 CSCI Problem Solving, Programming and Computers Spring, 2016 Assignment 2 Inheritance, Interfaces, Arrays Q1. [20 points] Q1. TXT Short answer questions Fill in the blanks in each of the following statements: 1. If a class contains at least one abstract method, it s a(n) class.answer: abstract 2. Classes from which objects can be instantiated are called classes.answer: concrete 3. involves using a superclass variable to invoke methods on superclass and subclass objects, enabling you to program in the general. Answer: Polymorphism 4. Methods that are not interface methods and that do not provide implementations must be declared using keyword. Answer: abstract 5. An array that uses two indices is referred to as a(n) array. Answer: 2-D or 2-dimensional State whether each of the statements that follows is true or false. If false, explain why. 6. [TRUE / FALSE] All methods in an abstract class must be declared as abstract methods. Why? Answer: False. An abstract class can include methods with implementations and abstract methods 7. [TRUE / FALSE] Invoking a subclass-only method through a subclass variable is not allowed. Why? Answer: False. Trying to invoke a subclass-only method with a superclass variable is not allowed. 8. [TRUE / FALSE] If a superclass declares an abstract method, a subclass must implement that method. Why? Answer: False. Only a concrete subclass must implement the method 9. [TRUE / FALSE] An object of a class that implements an interface may be thought of as an object of that interface type. Why? Answer: True 10. [TRUE / FALSE] An individual array element that s passed to a method and modified in that method will contain the modified value when the called method completes execution. Why? Answer: For individual primitive-type elements of an array: False. A called method receives and manipulates a copy of the value of such an element, so modifications do not affect the original value. If the reference of an array is passed to a method, however, modifications to the array elements made in the called method are indeed reflected in the original. For individual elements of a reference type: True. A called method receives a copy of the reference of such an element, and changes to the referenced object will be reflected in the original array element.
2 Q2. [30 points] FindDistance.java Write a program FindDistance to display the distance between two cities. Sample program run is shown (user input bolded): >This program finds the distance between two cities. Supported cities: Atlanta, Boston, Chicago, Houston, Los Angeles, New York, San Francisco, Washington. Enter starting city: San Francisco Enter destination city: Atlanta The distance from San Francisco to Atlanta is 2480 miles. The user will be asked to re-enter the name of a city if it doesn t match any of the names supported by the program. A normal two-dimensional array will be used to store the distances between cities. A ragged array could be used instead. The city names are maintained in array CITY_NAMES. The distance between each two cities are maintained in array DISTANCE. For example distance between Atlanta and Boston is Note that index of Atlanta is 0 and Boston is 1 in CITY_NAMES. So DISTNCE[0][1] is the distance between two cities. Use following class template: public class FindDistance private static final String[] CITY_NAMES = "Atlanta", "Boston", "Chicago", "Houston", "Los Angeles", "New York", "San Francisco", "Washington"; private static final int[][] DISTANCES = 0, 1110, 710, 790, 2190, 850, 2480, 620, 1110, 0, 1000, 1830, 3020, 210, 3130, 450, 710, 1000, 0, 1090, 2050, 810, 2170, 710, 790, 1830, 1090, 0, 1540, 1610, 1910, 1370, 2190, 3020, 2050, 1540, 0, 2790, 390, 2650, 850, 210, 810, 1610, 2790, 0, 2930, 240, 2480, 3130, 2170, 1910, 390, 2930, 0, 2840, 620, 450, 710, 1370, 2650, 240, 2840, 0; public static void main(string[] args) //TODO: Display initial message, including a list of legal cities // TODO:Call getcitycode to obtain codes for starting city and destination city //TODO: Display distance between chosen cities private static int getcitycode(string prompt) // TODO: method getcitycode:prompts user to enter city name; returns corresponding city code(index of city in CITY_NAMES). If city name is not recognized, allows user to enter another name.
3 Answer: // Finds the distance between two major American cities import java.util.scanner; public class FindDistance private static final String[] CITY_NAMES = "Atlanta", "Boston", "Chicago", "Houston", "Los Angeles", "New York", "San Francisco", "Washington"; private static final int[][] DISTANCES = 0, 1110, 710, 790, 2190, 850, 2480, 620, 1110, 0, 1000, 1830, 3020, 210, 3130, 450, 710, 1000, 0, 1090, 2050, 810, 2170, 710, 790, 1830, 1090, 0, 1540, 1610, 1910, 1370, 2190, 3020, 2050, 1540, 0, 2790, 390, 2650, 850, 210, 810, 1610, 2790, 0, 2930, 240, 2480, 3130, 2170, 1910, 390, 2930, 0, 2840, 620, 450, 710, 1370, 2650, 240, 2840, 0; public static void main(string[] args) //10 points // Display initial message, including a list of legal // cities System.out.println( "This program finds the distance between two cities.\n" + "Supported cities: Atlanta, Boston, Chicago, Houston,\n" + "Los Angeles, New York, San Francisco, Washington.\n"); // Call getcitycode to obtain codes for starting city and destination city int start = getcitycode("enter starting city: "); int destination = getcitycode("enter destination city: "); // Display distance between chosen cities System.out.println("\nThe distance from " + CITY_NAMES[start] + " to " + CITY_NAMES[destination] + " is " + DISTANCES[start][destination] + " miles."); // Prompts user to enter city name; returns corresponding city code. If city name is not recognized, allows user to enter another name. private static int getcitycode(string prompt) //15 points Scanner sc = new Scanner(System.in); while (true) System.out.println(prompt); String cityname = sc.nextline().trim(); for (int i = 0; i < CITY_NAMES.length; i++) if (cityname.equalsignorecase(city_names[i])) return i; System.out.println("City name was not recognized."); //5 points -comments
4 Q3. [20 points] StringReverse.java Write a program StringReverse with following methods to reverse a string:. For example, reverse("hello!") returns the string "!olleh. 1. a recursive method reverse(string text) that reverses a string 2. A iterative method reverse2(string text) that reverses a string Use following class template: public class StringReverse public static String reverse(string text) //TODO public static String reverse2(string text) //TODO public static void main(string[] args) System.out.println("reverse-recursive:") System.out.println(StringReverse.reverse("Hello!")); System.out.println("Expected:!olleH"); System.out.println(StringReverse.reverse("Odd")); System.out.println("Expected: ddo"); System.out.println("reverse-iterative:") System.out.println(StringReverse.reverse2("Hello!")); System.out.println("Expected:!olleH"); System.out.println(StringReverse.reverse2("Odd")); System.out.println("Expected: ddo"); Answer: public class StringReverse public static String reverse(string text) //10 points if (text.length() <= 1) return text; char c = text.charat(0); String rest = new String(text.substring(1)); String reversetext = reverse(rest) + c; return reversetext; public static String reverse2(string text) //10 points if (text.length() <= 1) return text; String reversetext = ""; for (int i = text.length() - 1; i >= 0; i--)
5 char c = text.charat(i); reversetext = reversetext + c; return reversetext; public static void main(string[] args) System.out.println("reverse-recursive:") System.out.println(StringReverse.reverse("Hello!")); System.out.println("Expected:!olleH"); System.out.println(StringReverse.reverse("Odd")); System.out.println("Expected: ddo"); System.out.println("reverse-iterative:") System.out.println(StringReverse.reverse2("Hello!")); System.out.println("Expected:!olleH"); System.out.println(StringReverse.reverse2("Odd")); System.out.println("Expected: ddo"); Q2. [30 points] LinearSearch.java Write a program LinearSearch that implements a method to search a value(key) in an array by scanning through elements left to right in a linear fashion. If the key is found its index should be return, otherwise -1 should be returned. Provide: 1. Iterative linear search method linearsearch(int key) 2. Recursive linear search method recursivelinearsearch(int key) Use following class template: import java.util.random; import java.util.scanner; import java.util.arrays; public class LinearArray private int[] data; // array of values private static Random generator = new Random(); public LinearArray( int size ) //populate array with random values in range data = new int[ size ]; for ( int i = 0; i < size; i++ ) data[ i ] = 10 + generator.nextint( 90 ); public String tostring() return Arrays.toString(data); /*Recursive method*/ public int recursivelinearsearch( int search, int start )
6 //TODO /*Iterative method*/ public int linearsearch( int searchkey ) //TODO public static void main( String[] args ) Scanner input = new Scanner( System.in ); int key; // search key int index; // location of search key in array // create array and output it LinearArray searcharray = new LinearArray( 10 ); System.out.println( searcharray + "\n" ); // print array // get input from user System.out.print( "Please enter an integer value (-1 to quit): " ); key = input.nextint(); // read first int from user // recursive search index = searcharray.recursivelinearsearch( key,0 ); System.out.println("Recursive search:"); if ( index == -1 ) // integer was not found System.out.println( "The integer " + key + " was not found.\n" ); else // integer was found System.out.println( "The integer " + key + " was found in index " + index + ".\n" ); //iterative search index = searcharray.linearsearch( key ); System.out.println("Iterative search:"); if ( index == -1 ) // integer was not found System.out.println( "The integer " + key + " was not found.\n" ); else // integer was found System.out.println( "The integer " + key + " was found in index " + index + ".\n" ); // end main Answer: import java.util.random; import java.util.scanner; import java.util.arrays; public class LinearArray private int[] data; // array of values private static Random generator = new Random(); public LinearArray( int size )
7 //populate array with random values in range data = new int[ size ]; for ( int i = 0; i < size; i++ ) data[ i ] = 10 + generator.nextint( 90 ); public String tostring() return Arrays.toString(data); /*Recursive method*/ public int recursivelinearsearch( int search, int start ) //20 points int location; // variable to store return value if ( start >= data.length ) // BASE CASE1: value not found location = -1; else if ( data[ start ] == search )// BASE CASE2: if item is equal to search key,return current location location = start; else location = recursivelinearsearch( search, start + 1 ); // RECURSIVE STEP return location; // return location of search key /*Iterative method*/ public int linearsearch( int searchkey ) //10 points // loop through array sequentially for ( int index = 0; index < data.length; index++ ) if ( data[ index ] == searchkey ) return index; // return index of integer return -1; // integer was not found // end method linearsearch public static void main( String[] args ) Scanner input = new Scanner( System.in ); int key; // search key int index; // location of search key in array // create array and output it LinearArray searcharray = new LinearArray( 10 ); System.out.println( searcharray + "\n" ); // print array // get input from user System.out.print( "Please enter an integer value (-1 to quit): " ); key = input.nextint(); // read first int from user // recursive search index = searcharray.recursivelinearsearch( key,0 ); System.out.println("Recursive search:"); if ( index == -1 ) // integer was not found System.out.println( "The integer " + key + " was not found.\n" );
8 else // integer was found System.out.println( "The integer " + key + " was found in index " + index + ".\n" ); //iterative search index = searcharray.linearsearch( key ); System.out.println("Iterative search:"); if ( index == -1 ) // integer was not found System.out.println( "The integer " + key + " was not found.\n" ); else // integer was found System.out.println( "The integer " + key + " was found in index " + index + ".\n" ); // end main Note: Marks will be assigned for proper comments and output. In addition to comments in your program, also include a file header comment at the top of each program file that includes your name, assignment number, and a description of the program: //********************************************************** // AssignmentNo (Enter Assignment number): (Enter ClassName) // Author(s): (Enter your full name here) // Description: (Enter Description) //********************************************************* Online Submission Instructions: Copy the folder <<yourname>>asg3 (e.g. JohnDoeAsg3) containing answer files, into /usr/people/handin/cs160 before midnight of the date indicated in class website.
CSCI Problem Solving, Programming and Computers Spring, 2016 Assignment 2 {Inheritance, Interfaces, Arrays}
CSCI 160 - Problem Solving, Programming and Computers Spring, 2016 Assignment 2 Inheritance, Interfaces, Arrays Q1. [20 points] Q1. TXT Short answer questions Fill in the blanks in each of the following
More informationLiang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
1 Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a matrix or a table. For example, the following table that describes
More informationAL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I
AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 2- Arithmetic and Decision Making: Equality and Relational Operators Objectives: To use arithmetic operators. The precedence of arithmetic
More informationJava for Non Majors Spring 2018
Java for Non Majors Spring 2018 Final Study Guide The test consists of 1. Multiple choice questions - 15 x 2 = 30 points 2. Given code, find the output - 3 x 5 = 15 points 3. Short answer questions - 3
More informationManipulating One-dimensional Arrays
Manipulating One-dimensional Arrays Mitsu Ogihara Department of Computer Science University of Miami 1 / 30 Table of Contents 1 For each 2 Exchanging Values 3 Reversing 2 / 30 For-each iteration For enumerating
More informationCSCI 355 Lab #2 Spring 2007
CSCI 355 Lab #2 Spring 2007 More Java Objectives: 1. To explore several Unix commands for displaying information about processes. 2. To explore some differences between Java and C++. 3. To write Java applications
More informationM105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014
M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014 Question One: Choose the correct answer and write it on the external answer booklet. 1. Java is. a. case
More informationProgramming with Java
Programming with Java Data Types & Input Statement Lecture 04 First stage Software Engineering Dep. Saman M. Omer 2017-2018 Objectives q By the end of this lecture you should be able to : ü Know rules
More informationdownload instant at
2 Introduction to Java Applications: Solutions What s in a name? That which we call a rose By any other name would smell as sweet. William Shakespeare When faced with a decision, I always ask, What would
More information1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003
1.00 Introduction to Computers and Engineering Problem Solving Quiz 1 March 7, 2003 Name: Email Address: TA: Section: You have 90 minutes to complete this exam. For coding questions, you do not need to
More informationArrays. Eng. Mohammed Abdualal
Islamic University of Gaza Faculty of Engineering Computer Engineering Department Computer Programming Lab (ECOM 2114) Created by Eng: Mohammed Alokshiya Modified by Eng: Mohammed Abdualal Lab 9 Arrays
More informationFundamentals of Programming Data Types & Methods
Fundamentals of Programming Data Types & Methods By Budditha Hettige Overview Summary (Previous Lesson) Java Data types Default values Variables Input data from keyboard Display results Methods Operators
More information2.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 informationMultidimensional Arrays. CSE 114, Computer Science 1 Stony Brook University
Multidimensional Arrays CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Multidimensional Arrays How do we represent matrices or tables? A two-dimensional array
More informationWeighted Graphs and Applications. CSE260, Computer Science B: Honors Stony Brook University
Weighted Graphs and Applications CSE260, Computer Science B: Honors Stony Brook University http://www.cs.stonybrook.edu/~cse260 1 Objectives To represent weighted edges using adjacency matrices and adjacency
More informationMidterm Examination (MTA)
M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and
More informationExam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 45 Obtained Marks:
كلية الحاسبات وتقنية المعلوما Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: October 18, 2015 Student Name: Student ID: Total Marks: 45 Obtained Marks: Instructions: Do not open this
More informationLanguage Features. 1. The primitive types int, double, and boolean are part of the AP
Language Features 1. The primitive types int, double, and boolean are part of the AP short, long, byte, char, and float are not in the subset. In particular, students need not be aware that strings are
More informationCSCI 355 LAB #2 Spring 2004
CSCI 355 LAB #2 Spring 2004 More Java Objectives: 1. To explore several Unix commands for displaying information about processes. 2. To explore some differences between Java and C++. 3. To write Java applications
More informationArrays Classes & Methods, Inheritance
Course Name: Advanced Java Lecture 4 Topics to be covered Arrays Classes & Methods, Inheritance INTRODUCTION TO ARRAYS The following variable declarations each allocate enough storage to hold one value
More informationCS141 Programming Assignment #6
CS141 Programming Assignment #6 Due Sunday, Nov 18th. 1) Write a class with methods to do the following output: a) 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1 b) 1 2 3 4 5 4 3 2 1 1 2 3 4 * 4 3 2 1 1 2 3 * * * 3 2 1
More informationIntroduction 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 informationCIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION
CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1 Name SOLUTION Page Points Score 2 15 3 8 4 18 5 10 6 7 7 7 8 14 9 11 10 10 Total 100 1 P age 1. Program Traces (41 points, 50 minutes)
More informationSoftware Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision
Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision Prof. Hwansoo Han T.A. Minseop Jeong T.A. Wonseok Choi 1 Java Program //package details public class ClassName {
More informationSoftware Practice 1 Basic Grammar
Software Practice 1 Basic Grammar Basic Syntax Data Type Loop Control Making Decision Prof. Joonwon Lee T.A. Jaehyun Song Jongseok Kim (42) T.A. Sujin Oh Junseong Lee (43) 1 2 Java Program //package details
More informationLecture 13 & 14. Single Dimensional Arrays. Dr. Martin O Connor CA166
Lecture 13 & 14 Single Dimensional Arrays Dr. Martin O Connor CA166 www.computing.dcu.ie/~moconnor Table of Contents Declaring and Instantiating Arrays Accessing Array Elements Writing Methods that Process
More informationObjectives of the lesson
Learning Outcome 1) DEMONSTRATE KNOWLEDGE AND UNDERSTANDING OF THE PROCEDURAL APPROACH TO SOFTWARE DEVELOPMENT. Knowledge & Understanding 2) DEVELOP A PROBLEM BASED STRATEGY FOR CREATING AND APPLYING PROGRAMMED
More informationIntroduction to Programming Using Java (98-388)
Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;
More informationWentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics
WIT COMP1000 Java Basics Java Origins Java was developed by James Gosling at Sun Microsystems in the early 1990s It was derived largely from the C++ programming language with several enhancements Java
More informationJAVA Ch. 4. Variables and Constants Lawrenceville Press
JAVA Ch. 4 Variables and Constants Slide 1 Slide 2 Warm up/introduction int A = 13; int B = 23; int C; C = A+B; System.out.print( The answer is +C); Slide 3 Declaring and using variables Slide 4 Declaring
More informationData dependent execution order data dependent control flow
Chapter 5 Data dependent execution order data dependent control flow The method of an object processes data using statements, e.g., for assignment of values to variables and for in- and output. The execution
More informationAP COMPUTER SCIENCE A
AP COMPUTER SCIENCE A CONTROL FLOW Aug 28 2017 Week 2 http://apcs.cold.rocks 1 More operators! not!= not equals to % remainder! Goes ahead of boolean!= is used just like == % is used just like / http://apcs.cold.rocks
More informationAL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I
AL GHURAIR UNIVERSITY College of Computing CSC 209 JAVA I week 3- Control Statements: Part I Objectives: To use the if and if...else selection statements to choose among alternative actions. To use the
More informationAP Computer Science Chapter 10 Implementing and Using Classes Study Guide
AP Computer Science Chapter 10 Implementing and Using Classes Study Guide 1. A class that uses a given class X is called a client of X. 2. Private features of a class can be directly accessed only within
More informationModule Contact: Dr Gavin Cawley, CMP Copyright of the University of East Anglia Version 1
UNIVERSITY OF EAST ANGLIA School of Computing Sciences Main Series UG Examination 2017-18 PROGRAMMING 1 CMP-4008Y Time allowed: 2 hours Answer FOUR questions. All questions carry equal weight. Notes are
More informationSelection 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 informationComputer Science II (20082) Week 1: Review and Inheritance
Computer Science II 4003-232-08 (20082) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Syntax and Semantics of Formal (e.g. Programming) Languages Syntax
More informationCSCI 2010 Principles of Computer Science. Basic Java Programming. 08/09/2013 CSCI Basic Java 1
CSCI 2010 Principles of Computer Science Basic Java Programming 1 Today s Topics Using Classes and Objects object creation and object references the String class and its methods the Java standard class
More informationPractice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course
: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course 1. Given the following hierarchy: class Alpha {... class Beta extends Alpha {... class Gamma extends Beta {... In what order
More informationZhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson
Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson Introduction History, Characteristics of Java language Java Language Basics Data types, Variables, Operators and Expressions Anatomy of a Java Program
More informationOverview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008
Overview Lecture 7: Inheritance and GUIs Written by: Daniel Dalevi Inheritance Subclasses and superclasses Java keywords Interfaces and inheritance The JComponent class Casting The cosmic superclass Object
More informationUniversity of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2007 Final Examination Question Max
More informationComputer Science II (20073) Week 1: Review and Inheritance
Computer Science II 4003-232-01 (20073) Week 1: Review and Inheritance Richard Zanibbi Rochester Institute of Technology Review of CS-I Hardware and Software Hardware Physical devices in a computer system
More informationArray. Array Declaration:
Array Arrays are continuous memory locations having fixed size. Where we require storing multiple data elements under single name, there we can use arrays. Arrays are homogenous in nature. It means and
More informationChapter 7 Multidimensional Arrays
Chapter 7 Multidimensional Arrays 1 Motivations You can use a two-dimensional array to represent a matrix or a table. Distance Table (in miles) Chicago Boston New York Atlanta Miami Dallas Houston Chicago
More informationFaculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202A - Introduction to Computing I (Fall 2008) Midterm Examination Tuesday, November 4, 2008 Examiners: Mathieu Petitpas [Section 1] 18:30
More informationControl Statements: Part 1
4 Let s all move one place on. Lewis Carroll Control Statements: Part 1 The wheel is come full circle. William Shakespeare How many apples fell on Newton s head before he took the hint! Robert Frost All
More informationExam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:
كلية الحاسبات وتقنية المعلوما Exam 2 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: November 22, 2015 Student Name: Student ID: Total Marks: 40 Obtained Marks: Instructions: Do not open this
More informationITERATION WEEK 4: EXMAPLES IN CLASS
Monday Section 2 import java.util.scanner; public class W4MSection2 { ITERATION WEEK 4: EXMAPLES IN CLASS public static void main(string[] args) { Scanner input1 = new Scanner (System.in); int CircleCenterX
More informationObject Oriented Programming. Java-Lecture 6 - Arrays
Object Oriented Programming Java-Lecture 6 - Arrays Arrays Arrays are data structures consisting of related data items of the same type In Java arrays are objects -> they are considered reference types
More informationSupplementary Test 1
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2009 Supplementary Test 1 Question
More informationThe Java language has a wide variety of modifiers, including the following:
PART 5 5. Modifier Types The Java language has a wide variety of modifiers, including the following: Java Access Modifiers Non Access Modifiers 5.1 Access Control Modifiers Java provides a number of access
More informationFall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.
Grading Page 1 / 4 Page3 / 20 Page 4 / 13 Page 5 / 10 Page 6 / 26 Page 7 / 17 Page 8 / 10 Total / 100 1. (4 points) What is your course section? CS 101 CS 101E Pledged Page 1 of 8 Pledged The following
More informationIntroduction to Java Applications
2 Introduction to Java Applications OBJECTIVES In this chapter you will learn: To write simple Java applications. To use input and output statements. Java s primitive types. Basic memory concepts. To use
More informationCCHS Math Recursion Worksheets M Heinen CS-A 12/5/2013. Recursion Worksheets Plus Page 1 of 6
CS-A // arraysol[][] = r; import java.util.scanner; public class RecursionApp { static int r; // return value static int[][] arraysol = new int[][7]; // create a solution array public static void main(string[]
More informationUniversity of Palestine. Mid Exam Total Grade: 100
First Question No. of Branches (5) A) Choose the correct answer: 1. If we type: system.out.println( a ); in the main() method, what will be the result? int a=12; //in the global space... void f() { int
More informationFinal Exam Practice. Partial credit will be awarded.
Please note that this problem set is intended for practice, and does not fully represent the entire scope covered in the final exam, neither the range of the types of problems that may be included in the
More informationDistributed Systems Recitation 1. Tamim Jabban
15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Tuesday: 9:30-11:59 AM Thursday: 10:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming
More informationMr. 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 informationCS1083 Week 2: Arrays, ArrayList
CS1083 Week 2: Arrays, ArrayList mostly review David Bremner 2018-01-08 Arrays (1D) Declaring and using 2D Arrays 2D Array Example ArrayList and Generics Multiple references to an array d o u b l e prices
More informationLecture 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 informationGive one example where you might wish to use a three dimensional array
CS 110: INTRODUCTION TO COMPUTER SCIENCE SAMPLE TEST 3 TIME ALLOWED: 60 MINUTES Student s Name: MAXIMUM MARK 100 NOTE: Unless otherwise stated, the questions are with reference to the Java Programming
More informationSection 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 informationfalse, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4
1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 45
More informationMORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011
MORE OO FUNDAMENTALS CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 4 09/01/2011 1 Goals of the Lecture Continue a review of fundamental object-oriented concepts 2 Overview of OO Fundamentals
More informationF1 A Java program. Ch 1 in PPIJ. Introduction to the course. The computer and its workings The algorithm concept
F1 A Java program Ch 1 in PPIJ Introduction to the course The computer and its workings The algorithm concept The structure of a Java program Classes and methods Variables Program statements Comments Naming
More information13 th Windsor Regional Secondary School Computer Programming Competition
SCHOOL OF COMPUTER SCIENCE 13 th Windsor Regional Secondary School Computer Programming Competition Hosted by The School of Computer Science, University of Windsor WORKSHOP I [ Overview of the Java/Eclipse
More informationChapter 6. Arrays. Java Actually: A Comprehensive Primer in Programming
Lecture slides for: Chapter 6 Arrays Java Actually: A Comprehensive Primer in Programming Khalid Azim Mughal, Torill Hamre, Rolf W. Rasmussen Cengage Learning, 28. ISBN: 978-1-84448-933-2 http://www.ii.uib.no/~khalid/jac/
More informationCONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2
CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,
More informationRules and syntax for inheritance. The boring stuff
Rules and syntax for inheritance The boring stuff The compiler adds a call to super() Unless you explicitly call the constructor of the superclass, using super(), the compiler will add such a call for
More informationRANDOM NUMBER GAME PROJECT
Random Number Game RANDOM NUMBER GAME - Now it is time to put all your new knowledge to the test. You are going to build a random number game. - The game needs to generate a random number between 1 and
More informationAbstract Classes and Interfaces
Abstract Classes and Interfaces Reading: Reges and Stepp: 9.5 9.6 CSC216: Programming Concepts Sarah Heckman 1 Abstract Classes A Java class that cannot be instantiated, but instead serves as a superclass
More informationLast Class. While loops Infinite loops Loop counters Iterations
Last Class While loops Infinite loops Loop counters Iterations public class January31{ public static void main(string[] args) { while (true) { forloops(); if (checkclassunderstands() ) { break; } teacharrays();
More informationa) Answer all questions. b) Write your answers in the space provided. c) Show all calculations where applicable.
Name: Please fill in your Student Number and Name. Student Number : Student Number: University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ 2008 January Exam Question Max Internal
More informationAbstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.
a and Interfaces Class Shape Hierarchy Consider the following class hierarchy Shape Circle Square Problem AND Requirements Suppose that in order to exploit polymorphism, we specify that 2-D objects must
More information1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'
Practice questions: 1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4' 2. Will System.out.println((char)4) display 4? a. Yes b. No 3. The expression "Java
More informationGraphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub 2 Crash Course in JAVA Classes A Java
More informationMethod OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters
Outline Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters Variable Length Parameter Lists split() Method from String Class Integer & Double Wrapper
More informationMid Term Exam 1. Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Total Marks: 50 Obtained Marks:
Mid Term Exam 1 Programming I (CPCS 202) Instructor: M. G. Abbas Malik Date: Sunday November 3, 2013 Student Name: Total Marks: 50 Obtained Marks: Instructions: Do not open this exam booklet until you
More informationObject-Oriented Concepts
JAC444 - Lecture 3 Object-Oriented Concepts Segment 2 Inheritance 1 Classes Segment 2 Inheritance In this segment you will be learning about: Inheritance Overriding Final Methods and Classes Implementing
More informationSection 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 informationSelection 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 informationCSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name
CSC 1051 Algorithms and Data Structures I Final Examination May 12, 2017 Name 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 the spaces provided.
More informationUniversità degli Studi di Bologna Facoltà di Ingegneria. Principles, Models, and Applications for Distributed Systems M
Università degli Studi di Bologna Facoltà di Ingegneria Principles, Models, and Applications for Distributed Systems M Control Structures Intro. Sequential execution Statements are normally executed one
More informationCenter 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 informationTwo-Dimensional Arrays
Two-Dimensional Arrays EECS2030: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG 2-D Arrays: Motivating Example (1) Consider a table of distances between seven cities: Chicago Boston New York
More informationProgramming in the Large II: Objects and Classes (Part 1)
Programming in the Large II: Objects and Classes (Part 1) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen
More informationLecture 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 informationData Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87
Data Types Java is a strongly-typed 1 programming language. Every variable has a type. Also, every (mathematical) expression has a type. There are two categories of data types: primitive data types, and
More informationChapter 6 Lab Classes and Objects
Lab Objectives Chapter 6 Lab Classes and Objects Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value Be able to write instance methods that
More informationText 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 informationMore Things We Can Do With It! Overview. Circle Calculations. πr 2. π = More operators and expression types More statements
More Things We Can Do With It! More operators and expression types More s 11 October 2007 Ariel Shamir 1 Overview Variables and declaration More operators and expressions String type and getting input
More informationAssignment 1 is due tonight at 11:59pm. Assignment 2 is due next Thursday at 11:59pm
Assignment 1 is due tonight at 11:59pm Assignment 2 is due next Thursday at 11:59pm Reading for Monday s class is the remainder of Chapter 7 and all of Chapter 8 The entire array has a single name Each
More informationfinal int CHICAGO = 0; final int BOSTON = 1; final int MIAMI = 4;
2-D Arrays: Motivating Example (2.1) Two-Dimensional Arrays Here is a solution based on what we ve learnt so far: Fix the positions of cities in the table as constants: final int CHICAGO = 0; final int
More informationLecture 3. Lecture
True Object-Oriented programming: Dynamic Objects Static Object-Oriented Programming Reference Variables Eckel: 30-31, 41-46, 107-111, 114-115 Riley: 5.1, 5.2 D0010E Object-Oriented Programming and Design
More informationChapter 6 Lab Classes and Objects
Gaddis_516907_Java 4/10/07 2:10 PM Page 51 Chapter 6 Lab Classes and Objects Objectives Be able to declare a new class Be able to write a constructor Be able to write instance methods that return a value
More informationChapter 8 Multi-Dimensional Arrays
Chapter 8 Multi-Dimensional Arrays 1 1-Dimentional and 2-Dimentional Arrays In the previous chapter we used 1-dimensional arrays to model linear collections of elements. myarray: 6 4 1 9 7 3 2 8 Now think
More informationJava Bootcamp - Villanova University. CSC 2014 Java Bootcamp. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University
Arrays CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Some slides in this presentation are adapted from the slides accompanying Java Software Solutions
More informationCS170 (005): Introduction to Computer Science Exam 2
CS70 (005): Introduction to Computer Science Exam Name (print): Instructions Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work Do NOT communicate with anyone
More information1 Shyam sir JAVA Notes
1 Shyam sir JAVA Notes 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write
More information