Sit-In Lab 2 - OOP Championship

Size: px
Start display at page:

Download "Sit-In Lab 2 - OOP Championship"

Transcription

1 Sit-In Lab 2 - OOP Championship

2 Manage championships and perform these types of queries: Simulate one team wins in a championship Simulate a match with the result of draw in a championship Print the name of the highest-ranked team in a given championship Print the name of the team that has played the most number of matches across all championship Print the top three teams names in a given championship Problem Description

3 Problem Illustration ECP Championship1 Team1 Team2 Championship2 Team3 Team4

4 Class ECP ECP - championships : ArrayList<Championship> + //methods Class Team Class Group Table - name : String - points : int - numofwins: int - numofmatchesplayed: int - champname:string + getname() : String + setpoints() : void + getpoints() : int Class Overview Group - name : String - teamlist : ArrayList<Team> + getname() : String + getteamlist() : ArrayList<Team> + addteam() : void

5 Constructors ECP: public class ECP() Team: class Team(String teamname, String champname) Championship: class Championship(String name)

6 Constructors public Team(String teamname, String champname) { this.name = teamname; this.points =0; this.numofwins = 0; this.numofmatchesplayed = 0; this.champname = champname; public Championship(String name) { this.name = name; teams = new ArrayList<Team>();

7 Useful Tips Some tips for processing the queries: Perform all logical operations in the ECP class The methods in the Team and Championship class are only for operations that modify or return their own attributes. Avoid the use of static variables and methods We define helper methods in ECP as we go along, e.g: getchampionship(string championshipname): returns the championship with the name championshipname getteambasedonname(string teamname): returns the team with the name teamname

8 public class ECP { private ArrayList<Championship> championships = new ArrayList<Championship>(); public static void main(string args[]) { ECp ecp = new ECP(); ecp.run(); public void run() { Scanner sc = new Scanner(System.in); int numofchamps = sc.nextint(); int numofteams = sc.nextint(); int numofqueries = sc.nextint(); loadchamps(sc,numofchamps); loadteams(sc,numofteams); executequeries(sc,numofqueries);

9 private void loadchampionships(scanner sc,int numofchamps ) { for (int i=0; i<numofchamps; i++) { championships.add( new Championship(sc.next())); // read input // new an instance of Championship // add the instance to ArrayList championships private void loadteams(scanner sc,int numofteams) { for (int i =0; i<numofteams; i++) { // read input String teamname = sc.next(); String championshipname = sc.next(); // new an instance of Team // find the championship by name Championship championship = getchampionship(championshipname); // add the team to ArrayList teamlist in championship

10 Helper Methods private Championship getchampionship(string championshipname) { // iterating through ArrayList championships, // return the championship with name championshipname private Team getteambasedonname(string teamname) { // iterating through ArrayList championships, get the teamlist in it // iterating through teamlist // return the team with name teamname

11 private void executequeries(scanner sc, int numofqueries) { for (int i=0; i<numofqueries; i++) { //execute queries based on type switch (sc.next()) { case "win": winmatch(sc.next(), sc.next()); break; case "draw": drawmatch(sc.next(), sc.next()); break; case "top": printtop(sc.next()); break; case "max": printmax(); break; case "final": printfinal(sc.next());

12 Query win private void winmatch(string winningteamname, String losingteamname) { // find the two teams Team winningteam = getteambasedonname(winningteamname); Team losingteam = getteambasedonname(losingteamname); // check if they are in the same championship if (!checkifvalidmatching(winningteam, losingteam)) { System.out.println("invalid matching"); else { // update points of winningteam // update numofwins of winningteam // update numofmatchesplayed of winningteam // update numofmatchesplayed of losingteam // print the name of championship System.out.println(winningTeam.getChampName()); Query 1: Assign group to favorite table

13 Helper Methods private boolean checkifvalidmatching(team team1, Team team2) { return team1.getchampname().equals(team2.getchampname());

14 Query 2: Assign group to a table Query draw private void drawmatch(string team1name, String team2name) { // find the two teams Team team1 = getteambasedonname(team1name); Team team2 = getteambasedonname(team2name); // check if they are in the same championship if (!checkifvalidmatching(team1, team2)){ System.out.println("invalid matching"); else { //update points of two teams //update numofmatchesplayed of two teams //print the name of championship System.out.println(team1.getChampName());

15 Query top private void printtop(string championshipname) { // find the championship by given name Championship championship=getchampionship(championshipname); // find the top team Team topteam=gettopteam(championship); // print the name of top team System.out.println(topTeam.getName());

16 private Team gettopteam(championship championship) { // initial top team Team topteam = championship.getteamlist().get(0); // iterating through teamlist for (Team team:championship.getteamlist()) { if (team.getpoints()>topteam.getpoints()) { // more number of points topteam = team; else if (team.getpoints()==topteam.getpoints() && team.getnumofwins()>topteam.getnumofwins()) { // more number of wins topteam = team; else if (team.getpoints()==topteam.getpoints() && team.getnumofwins()>topteam.getnumofwins() && team.getname().compareto(topteam.getname())<0) { // lexi-smaller topteam = team; return topteam;

17 Query max private void printmax() { Team maxteam = championships.get(0).getteamlist().get(0); // iterating through ArrayList championships, get the teamlist in it // iterating through teamlist // compare numofmatchesplayed // if two number are the same, choose the lexi-smaller one // print the name of maxteam

18 Query final: the last query private void printfinal(string championshipname){ // find the championship by given name Championship championship = getchampionship(championshipname); if (only two teams) { // find the top team Team topteam = gettopteam(championship); // print topteam name,space // remove topteam from teamlist // print top team name else { // loop for three times // find the top team, print name, space(no space for the third one) // remove the top team

19 Question?

2.2 - Making Decisions

2.2 - Making Decisions 2.2 - Making Decisions So far we have only made programs that execute the statements in order, starting with the statements at the top of the screen and moving down. However, you can write programs that

More information

AP COMPUTER SCIENCE A

AP 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 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

Last Name: Circle One: OCW Non-OCW

Last Name: Circle One: OCW Non-OCW First Name: AITI 2004: Exam 1 June 30, 2004 Last Name: Circle One: OCW Non-OCW Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot

More information

CMPS 11 Introduction to Programming Midterm 1 Review Problems

CMPS 11 Introduction to Programming Midterm 1 Review Problems CMPS 11 Introduction to Programming Midterm 1 Review Problems Note: The necessary material for some of these problems may not have been covered by end of class on Monday, the lecture before the exam. If

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

Lab Exercise 1. Objectives: Part 1. Introduction

Lab Exercise 1. Objectives: Part 1. Introduction Objectives: king Saud University College of Computer &Information Science CSC111 Lab Object II All Sections - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

More information

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill CSCI 136 Data Structures & Advanced Programming Lecture 3 Fall 2018 Instructors: Bill & Bill Administrative Details Lab today in TCL 217a (and 216) Lab is due by 11pm Sunday Lab 1 design doc is due at

More information

Getter and Setter Methods

Getter and Setter Methods Example 1 namespace ConsoleApplication14 public class Student public int ID; public string Name; public int Passmark = 50; class Program static void Main(string[] args) Student c1 = new Student(); Console.WriteLine("please..enter

More information

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2016 TRIMESTER 1 COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2016 TRIMESTER 1 COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2016 TRIMESTER 1 COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN

More information

CS1083 Week 2: Arrays, ArrayList

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

Software and Programming 1

Software and Programming 1 Software and Programming 1 Week 9 Lab - Use of Classes and Inheritance 8th March 2018 SP1-Lab9-2018.ppt Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Lab 9: Objectives Exercise 1 Student & StudentTest classes 1.

More information

Midterm Examination (MTA)

Midterm Examination (MTA) M105: Introduction to Programming with Java Midterm Examination (MTA) Spring 2013 / 2014 Question One: [6 marks] Choose the correct answer and write it on the external answer booklet. 1. Compilers and

More information

This exam is open book. Each question is worth 3 points.

This exam is open book. Each question is worth 3 points. This exam is open book. Each question is worth 3 points. Page 1 / 15 Page 2 / 15 Page 3 / 12 Page 4 / 18 Page 5 / 15 Page 6 / 9 Page 7 / 12 Page 8 / 6 Total / 100 (maximum is 102) 1. Are you in CS101 or

More information

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by:

Menu Driven Systems. While loops, menus and the switch statement. Mairead Meagher Dr. Siobhán Drohan. Produced by: Menu Driven Systems While loops, menus and the switch statement Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list while loops recap

More information

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2017 Instructors: Bill & Bill

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2017 Instructors: Bill & Bill CSCI 136 Data Structures & Advanced Programming Lecture 3 Fall 2017 Instructors: Bill & Bill Administrative Details Lab today in TCL 216 (217a is available, too) Lab is due by 11pm Sunday Copy your folder

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

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

Distributed Systems Recitation 1. Tamim Jabban

Distributed Systems Recitation 1. Tamim Jabban 15-440 Distributed Systems Recitation 1 Tamim Jabban Office Hours Office 1004 Sunday, Tuesday: 9:30-11:59 AM Appointment: send an e-mail Open door policy Java: Object Oriented Programming A programming

More information

COMP102: Test 2 Model Solutions

COMP102: Test 2 Model Solutions Family Name:.......................... Other Names:.......................... ID Number:............................ Instructions Time allowed: 90 minutes (1 1 2 hours). There are 90 marks in total. Answer

More information

CS 101 Fall 2005 Midterm 2 Name: ID:

CS 101 Fall 2005 Midterm 2 Name:  ID: This exam is open text book but closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts (in particular, the final two questions are worth substantially more than any

More information

Programming Problems 22nd Annual Computer Science Programming Contest

Programming Problems 22nd Annual Computer Science Programming Contest Programming Problems 22nd Annual Computer Science Programming Contest Department of Mathematics and Computer Science Western Carolina University 5 April 2011 Problem One: Add Times Represent a time by

More information

Following is the general form of a typical decision making structure found in most of the programming languages:

Following is the general form of a typical decision making structure found in most of the programming languages: Decision Making Decision making structures have one or more conditions to be evaluated or tested by the program, along with a statement or statements that are to be executed if the condition is determined

More information

CCHS Math Recursion Worksheets M Heinen CS-A 12/5/2013. Recursion Worksheets Plus Page 1 of 6

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

CS Week 14. Jim Williams, PhD

CS Week 14. Jim Williams, PhD CS 200 - Week 14 Jim Williams, PhD This Week 1. Final Exam: Conflict Alternatives Emailed 2. Team Lab: Object Oriented Space Game 3. BP2 Milestone 3: Strategy 4. Lecture: More Classes and Additional Topics

More information

1005ICT Object Oriented Programming Lecture Notes

1005ICT Object Oriented Programming Lecture Notes 1005ICT Object Oriented Programming Lecture Notes School of Information and Communication Technology Griffith University Semester 2, 2015 1 16 Generics This section introduces generics, or parameterised

More information

CS61BL. Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling

CS61BL. Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling CS61BL Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling About me Name: Edwin Liao Email: edliao@berkeley.edu Office hours: Thursday 3pm - 5pm Friday 11am - 1pm 611 Soda Or by

More information

Iteration: Intro. Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times. 2. Posttest Condition follows body Iterates 1+ times

Iteration: Intro. Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times. 2. Posttest Condition follows body Iterates 1+ times Iteration: Intro Two types of loops: 1. Pretest Condition precedes body Iterates 0+ times 2. Posttest Condition follows body Iterates 1+ times 1 Iteration: While Loops Pretest loop Most general loop construct

More information

Distributed Systems Recitation 1. Tamim Jabban

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

CS212 Midterm. 1. Read the following code fragments and answer the questions.

CS212 Midterm. 1. Read the following code fragments and answer the questions. CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");

More information

Classes. Classes as Code Libraries. Classes as Data Structures. Classes/Objects/Interfaces (Savitch, Various Chapters)

Classes. Classes as Code Libraries. Classes as Data Structures. Classes/Objects/Interfaces (Savitch, Various Chapters) Classes Classes/Objects/Interfaces (Savitch, Various Chapters) TOPICS Classes Public versus Private Static Data Static Methods Interfaces Classes are the basis of object-oriented (OO) programming. They

More information

Java and OOP. Part 2 Classes and objects

Java and OOP. Part 2 Classes and objects Java and OOP Part 2 Classes and objects 1 Objects OOP programs make and use objects An object has data members (fields) An object has methods The program can tell an object to execute some of its methods

More information

COE 212 Engineering Programming. Welcome to Exam I Thursday June 21, Instructor: Dr. Wissam F. Fawaz

COE 212 Engineering Programming. Welcome to Exam I Thursday June 21, Instructor: Dr. Wissam F. Fawaz 1 COE 212 Engineering Programming Welcome to Exam I Thursday June 21, 2018 Instructor: Dr. Wissam F. Fawaz Name: Student ID: Instructions: 1. This exam is Closed Book. Please do not forget to write your

More information

Assignment 8B SOLUTIONS

Assignment 8B SOLUTIONS CSIS 10A Assignment 8B SOLUTIONS Read: Chapter 8 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2011 Trimester 2, MID-TERM TEST COMP103 Introduction

More information

King Saud University College of Computer and Information Systems Department of Computer Science CSC 113: Java Programming-II, Spring 2016

King Saud University College of Computer and Information Systems Department of Computer Science CSC 113: Java Programming-II, Spring 2016 Create the classes along with the functionality given in the following UML Diagram. To understand the problem, please refer to the description given after the diagram. Node +Node(e:Employee) +getdata():employee

More information

Linked Lists. private int num; // payload for the node private Node next; // pointer to the next node in the list }

Linked Lists. private int num; // payload for the node private Node next; // pointer to the next node in the list } Linked Lists Since a variable referencing an object just holds the address of the object in memory, we can link multiple objects together to form dynamic lists or other structures. In our case we will

More information

1. CPU utilization: it is the percentage of time the CPU is used for a specific time period ones want to keep the CPU as busy as possible (Max.

1. CPU utilization: it is the percentage of time the CPU is used for a specific time period ones want to keep the CPU as busy as possible (Max. Cairo University Faculty of Computers & Information Computer Science Department Lab 5: CPU Scheduling Theoretical part: Definition: The process scheduling is the activity of the process manager that handles

More information

Informatik II. Andreas Bärtschi, Andreea Ciuprina, Felix Friedrich, Patrick Gruntz, Hermann Lehner, Max Rossmannek, Chris Wendler FS 2018

Informatik II. Andreas Bärtschi, Andreea Ciuprina, Felix Friedrich, Patrick Gruntz, Hermann Lehner, Max Rossmannek, Chris Wendler FS 2018 1 Informatik II Übung 4 Andreas Bärtschi, Andreea Ciuprina, Felix Friedrich, Patrick Gruntz, Hermann Lehner, Max Rossmannek, Chris Wendler FS 2018 Program Today 2 1 Feedback of last exercise 2 Repetition

More information

Introduction to Programming Using Java (98-388)

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

Classes. Classes as Code Libraries. Classes as Data Structures

Classes. Classes as Code Libraries. Classes as Data Structures Classes Classes/Objects/Interfaces (Savitch, Various Chapters) TOPICS Classes Public versus Private Static Data Static Methods Interfaces Classes are the basis of object-oriented (OO) programming. They

More information

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

University 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 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

Objects as a programming concept

Objects as a programming concept Objects as a programming concept IB Computer Science Content developed by Dartford Grammar School Computer Science Department HL Topics 1-7, D1-4 1: System design 2: Computer Organisation 3: Networks 4:

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

Reasoning about program behaviour Assertions

Reasoning about program behaviour Assertions Chapter 6 Reasoning about program behaviour Assertions To analyze, verify, and describe program behaviour, it is often helpful to look at the program states, i.e., the values of the variables. The user

More information

Loops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department

Loops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department 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 6 Loops

More information

Ū P O K O O T E I K A A M Ā U I U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2014 TRIMESTER 1

Ū P O K O O T E I K A A M Ā U I U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2014 TRIMESTER 1 T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2014 TRIMESTER 1 COMP 102 INTRODUCTION

More information

CSE143 Summer 2008 Final Exam Part A KEY August 21, 2008

CSE143 Summer 2008 Final Exam Part A KEY August 21, 2008 CSE143 Summer 28 Final Exam Part A KEY August 21, 28 Name : Section (eg. AA) : TA : This is an open-book/open-note exam. Space is provided for your answers. Use the backs of pages if necessary. The exam

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

Assignment -3 Source Code. Student.java

Assignment -3 Source Code. Student.java import java.io.serializable; Assignment -3 Source Code Student.java public class Student implements Serializable{ public int rollno; public String name; public double marks; public Student(int rollno,

More information

Programming Constructs Overview. Method Call System.out.print( hello ); Method Parameters

Programming Constructs Overview. Method Call System.out.print( hello ); Method Parameters Programming Constructs Overview Method calls More selection statements More assignment operators Conditional operator Unary increment and decrement operators Iteration statements Defining methods 27 October

More information

Unit 5: More on Classes/Objects Notes

Unit 5: More on Classes/Objects Notes Unit 5: More on Classes/Objects Notes AP CS A The Difference between Primitive and Object/Reference Data Types First, remember the definition of a variable. A variable is a. So, an obvious question is:

More information

The Java language has a wide variety of modifiers, including the following:

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

Software and Programming 1

Software and Programming 1 Software and Programming 1 Lab 8: Use of classes, static class variables and methods 1st March 2018 SP1-Lab8-2018.pdf Tobi Brodie (Tobi@dcs.bbk.ac.uk) 1 Lab 8 Objectives Understanding the encapsulation

More information

Objektorienterad programmering

Objektorienterad programmering Objektorienterad programmering Lecture 8: dynamic lists, testing and error handling Dr. Alex Gerdes Dr. Carlo A. Furia SP1 2017/18 Chalmers University of Technology In the previous lecture 7 Reading and

More information

CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015

CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015 Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 2 Fall 2015 [Bono] Nov. 10, 2015 There are 9 problems on the exam, with 54 points total available. There are 8 pages to the exam (4 pages double-sided),

More information

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External

University of Cape Town ~ Department of Computer Science Computer Science 1015F ~ Test 2. Question Max Mark Internal External 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 Test 2 Question Max Mark Internal

More information

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice

Name Section Number. CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice Name Section Number CS210 Exam #3 *** PLEASE TURN OFF ALL CELL PHONES*** Practice All Sections Bob Wilson OPEN BOOK / OPEN NOTES: You will have all 90 minutes until the start of the next class period.

More information

The Scanner class reads data entered by the user. Methods: COSC Dr. Ramon Lawrence. Page 3. COSC Dr. Ramon Lawrence A) A = 6, B = 3

The Scanner class reads data entered by the user. Methods: COSC Dr. Ramon Lawrence. Page 3. COSC Dr. Ramon Lawrence A) A = 6, B = 3 COSC 123 Computer Creativity Course Review Dr. Ramon Lawrence University of British Columbia Okanagan ramon.lawrence@ubc.ca Reading Data from the User The Scanner Class The Scanner class reads data entered

More information

The FacebookPerson Example. Dr. Xiaolin Hu CSC 2310, Spring 2015

The FacebookPerson Example. Dr. Xiaolin Hu CSC 2310, Spring 2015 The FacebookPerson Example Dr. Xiaolin Hu CSC 2310, Spring 2015 Motivation Whenever you are happy, update your facebook! Start from Simple A Facebook Person Class A test class public class FacebookPerson{

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

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 000 Spring 2015 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

Flexible data exchange with a method Parameters and return value

Flexible data exchange with a method Parameters and return value Chapter 9 Flexible data exchange with a method Parameters and return value A method provides flexibility as to where in the code its task is described to be performed: anywhere the method is called. Up

More information

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2015 TRIMESTER 1 COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN

U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2015 TRIMESTER 1 COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2015 TRIMESTER 1 COMP 102 INTRODUCTION TO COMPUTER PROGRAM DESIGN

More information

NATIONAL UNIVERSITY OF SINGAPORE

NATIONAL UNIVERSITY OF SINGAPORE NATIONAL UNIVERSITY OF SINGAPORE SCHOOL OF COMPUTING TERM TEST #1 Semester 1 AY2006/2007 CS1101X/Y/Z PROGRAMMING METHODOLOGY 16 September 2006 Time Allowed: 60 Minutes INSTRUCTIONS 1. This question paper

More information

Data dependent execution order data dependent control flow

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

Lesson 7 Part 2 Flags

Lesson 7 Part 2 Flags Lesson 7 Part 2 Flags A Flag is a boolean variable that signals when some condition exists in a program. When a flag is set to true, it means some condition exists When a flag is set to false, it means

More information

package solution; import battleship.battleship; import battleship.cellstate; import java.awt.point; import java.util.arraylist;

package solution; import battleship.battleship; import battleship.cellstate; import java.awt.point; import java.util.arraylist; package solution; import battleship.battleship; import battleship.cellstate; import java.awt.point; import java.util.arraylist; * @author Salah Abuzaid 000348604 public class SampleBot { public int gamesize;

More information

University of Massachusetts Amherst, Electrical and Computer Engineering

University of Massachusetts Amherst, Electrical and Computer Engineering University of Massachusetts Amherst, Electrical and Computer Engineering ECE 122 Midterm Exam 1 Makeup Answer key March 2, 2018 Instructions: Closed book, Calculators allowed; Duration:120 minutes; Write

More information

CSIS 10A Practice Final Exam Solutions

CSIS 10A Practice Final Exam Solutions CSIS 10A Practice Final Exam Solutions 1) (5 points) What would be the output when the following code block executes? int a=3, b=8, c=2; if (a < b && b < c) b = b + 2; if ( b > 5 a < 3) a = a 1; if ( c!=

More information

CS Week 13. Jim Williams, PhD

CS Week 13. Jim Williams, PhD CS 200 - Week 13 Jim Williams, PhD This Week 1. Team Lab: Instantiable Class 2. BP2 Strategy 3. Lecture: Classes as templates BP2 Strategy 1. M1: 2 of 3 milestone tests didn't require reading a file. 2.

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 Arrays A data structure for a collection of data that is all of the same data type. The data type can be

More information

Today s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO. Understanding Board

Today s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO. Understanding Board Ananda Gunawardena Today s plan Discuss the Bb quiz 1 Clarify Lab 1 Review basic Java materials Classes, Objects, Interfaces Strings Java IO Lab 1 Objectives Learn how to structure TicTacToeprogram as

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

Design Pattern Examples

Design Pattern Examples Factory Pattern (Creational) Design Pattern Examples Goal: Define an interface for creating an object, but let the classes that implement the interface decide which class to instantiate. The Factory method

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

DM503 Programming B. Peter Schneider-Kamp.

DM503 Programming B. Peter Schneider-Kamp. DM503 Programming B Peter Schneider-Kamp petersk@imada.sdu.dk! http://imada.sdu.dk/~petersk/dm503/! VARIABLES, EXPRESSIONS & STATEMENTS 2 Values and Types Values = basic data objects 42 23.0 "Hello!" Types

More information

Options for User Input

Options for User Input Options for User Input Options for getting information from the user Write event-driven code Con: requires a significant amount of new code to set-up Pro: the most versatile. Use System.in Con: less versatile

More information

Example: Monte Carlo Simulation 1

Example: Monte Carlo Simulation 1 Example: Monte Carlo Simulation 1 Write a program which conducts a Monte Carlo simulation to estimate π. 1 See https://en.wikipedia.org/wiki/monte_carlo_method. Zheng-Liang Lu Java Programming 133 / 149

More information

1 Short Answer (10 Points Each)

1 Short Answer (10 Points Each) 1 Short Answer (10 Points Each) 1. For the following one-dimensional array, show the final array state after each pass of the three sorting algorithms. That is, after each iteration of the outside loop

More information

PASS4TEST IT 인증시험덤프전문사이트

PASS4TEST IT 인증시험덤프전문사이트 PASS4TEST IT 인증시험덤프전문사이트 http://www.pass4test.net 일년동안무료업데이트 Exam : 1z0-809 Title : Java SE 8 Programmer II Vendor : Oracle Version : DEMO Get Latest & Valid 1z0-809 Exam's Question and Answers 1 from

More information

Object-Oriented Programming in Java

Object-Oriented Programming in Java Software and Programming I Object-Oriented Programming in Java Roman Kontchakov / Carsten Fuhs Birkbeck, University of London Outline Object-Oriented Programming Public Interface of a Class Instance Variables

More information

CSIS 10A Assignment 9 Solutions

CSIS 10A Assignment 9 Solutions CSIS 10A Assignment 9 Solutions Read: Chapter 9 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING INPUT AND OUTPUT Input devices Keyboard Mouse Hard drive Network Digital camera Microphone Output devices.

More information

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions: Name: New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case Instructions: KEEP TEST BOOKLET CLOSED UNTIL YOU ARE INSTRUCTED TO BEGIN. This exam is double sided (front

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 15 Lecture 15-1: Implementing ArrayIntList reading: 15.1-15.3 Recall: classes and objects class: A program entity that represents: A complete program or module, or A template

More information

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Page 0 German University in Cairo April 6, 2017 Media Engineering and Technology Faculty Prof. Dr. Slim Abdennadher CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam Bar Code

More information

1 Short Answer (2 Points Each)

1 Short Answer (2 Points Each) Fall 013 Exam # Key COSC 117 1 Short Answer ( Points Each) 1. What is the scope of a method/function parameter? The scope of a method/function parameter is in the method only, that is, it is local to the

More information

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Web-CAT submission URL:  CAT.woa/wa/assignments/eclipse King Saud University College of Computer & Information Science CSC111 Lab10 Arrays II All Sections ------------------------------------------------------------------- Instructions Web-CAT submission URL:

More information

Question: Total Points: Score:

Question: Total Points: Score: CS 170 Exam 1 Section 000 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than

More information

This class simulates the Sudoku board. Its important methods are setcell, dorow, docolumn and doblock.

This class simulates the Sudoku board. Its important methods are setcell, dorow, docolumn and doblock. Contents: We studied a code for implementing Sudoku for the major portion of the lecture. In the last 10 minutes, we also looked at how we can call one constructor from another using this (), the use of

More information

Today s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO

Today s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO Today s plan Discuss the Lab 1 Show Lab 2 Review basic Java materials Java API Strings Java IO Ananda Gunawardena Objects and Methods working together to solve a problem Object Oriented Programming Paradigm

More information

Recitation 3 Class and Objects

Recitation 3 Class and Objects 1.00/1.001 Introduction to Computers and Engineering Problem Solving Recitation 3 Class and Objects Spring 2012 1 Scope One method cannot see variables in another; Variables created inside a block: { exist

More information

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal Lesson Goals Understand Control Structures Understand how to control the flow of a program

More information

COMP-202: Foundations of Programming. Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015

COMP-202: Foundations of Programming. Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015 COMP-202: Foundations of Programming Lecture 12: Linked List, and File I/O Sandeep Manjanna, Summer 2015 Announcements Assignment 4 is posted and Due on 29 th of June at 11:30 pm. Course Evaluations due

More information

Question 1 [20 points]

Question 1 [20 points] Question 1 [20 points] Explain following features of Eclipse IDE. Provide a very short example for each. a) Assume a class Student that represents a student of ECE department at UPRM. Give two different

More information

JAVA PROGRAMMING (340)

JAVA PROGRAMMING (340) Page 1 of 8 JAVA PROGRAMMING (340) REGIONAL 2016 Production Portion: Program 1: Base K Addition (335 points) TOTAL POINTS (335 points) Judge/Graders: Please double check and verify all scores and answer

More information

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016

CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016 Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 2 Fall 2016 [Bono] November 8, 2016 There are 7 problems on the exam, with 50 points total available. There are 8 pages to the exam (4 pages double-sided),

More information

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016

CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016 Name: USC NetID (e.g., ttrojan): CS 455 Midterm Exam 1 Fall 2016 [Bono] Thursday, Sept. 29, 2016 There are 5 problems on the exam, with 56 points total available. There are 10 pages to the exam (5 pages

More information