CMP 326 Midterm Fall 2015

Similar documents
CMP-326 Exam 2 Spring 2018 Total 120 Points Version 1

University of Massachusetts Amherst, Electrical and Computer Engineering

CMP 326 Final Spring There is a blank page at the end of the exam if you need more room to answer a question.

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Selenium Class 9 - Java Operators

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

SampleApp.java. Page 1

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

CS 180 Final Exam Review 12/(11, 12)/08

AP COMPUTER SCIENCE A

1. Which of the following is the correct expression of character 4? a. 4 b. "4" c. '\0004' d. '4'

MIT AITI Swing Event Model Lecture 17

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

1 Looping Constructs (4 minutes, 2 points)

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

Place your name tag here

RAIK 183H Examination 2 Solution. November 10, 2014

Systems Programming. Bachelor in Telecommunication Technology Engineering Bachelor in Communication System Engineering Carlos III University of Madrid

CMPS 11 Intermediate Programming Midterm 2 Review Problems

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CIS 120 Programming Languages and Techniques. Midterm II. November 12, 2010

CONDITIONAL EXECUTION

University of Palestine. Mid Exam Total Grade: 100

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages)

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

if (x == 0); System.out.println( x=0 ); if (x = 0) System.out.println( x=0 );

RAIK 183H Examination 2 Solution. November 11, 2013

GUI Forms and Events, Part II

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

JAVA OPERATORS GENERAL

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

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

CS 101 Exam 2 Spring Id Name

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions

CSE 142, Autumn 2010 Midterm Exam, Friday, November 5, 2010

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Give one example where you might wish to use a three dimensional array

CMPS 12A Introduction to Programming Midterm 2 Review Problems

Swing from A to Z Some Simple Components. Preface

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2012

CIS 120 Programming Languages and Techniques. Midterm II. November 12, Answer key

ANSWER KEY First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

CSCI 135 Exam #0 Fundamentals of Computer Science I Fall 2013

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

Problem Grade Total

UTM CSC207: Midterm Examination October 28, 2011

University of Cape Town Department of Computer Science Computer Science CSC1017F

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

Midterm Examination (MTA)

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 2: April 16, 2004

ITEC 120 4/14/11. Review. Need. Objectives. GUI basics JFrame JPanel JLabel, JButton, JTextField Layout managers. Lecture 38 GUI Interactivity

CSE 201 JAVA PROGRAMMING I. Copyright 2016 by Smart Coding School

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

CSC 240 Computer Science III Spring 2018 Midterm Exam. Name

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

Account joeacct = new Account (100, new Account (500)); Account joeacct = new Account (100, new Account (500, null));

Question: Total Points: Score:

COMP102: Test. 18 April, 2005

I. True/False: (2 points each)

H212 Introduction to Software Systems Honors

COMP Assignment #10 (Due: Monday, March 11:30pm)

AP CS Unit 11: Graphics and Events

CSCI 135 Exam #2 Fundamentals of Computer Science I Fall 2013

CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015

Classes and Objects 3/28/2017. How can multiple methods within a Java class read and write the same variable?

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

CIS October 19, 2017

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

I. True/False: (2 points each)

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

1.00/1.001 Introduction to Computers and Engineering Problem Solving. Quiz 2: April 16, 2004

CoSc Lab # 8 (an array of a class) Due Date: Part I, Experiment classtime, Tuesday, Dec 4 th, 2018.

16. Give a detailed algorithm for making a peanut butter and jelly sandwich.

CSCI 201L Midterm Written Summer % of course grade

CS 1331 Exam 1. Fall Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score.

Graphical User Interface

Java for Interfaces and Networks (DT3010, HT10)

CS Exam 1 Review Suggestions

CS 305j Midterm 1 Fall 2007

Window Interfaces Using Swing Objects

Prof. Navrati Saxena TA: Rochak Sachan

Last Name: Circle One: OCW Non-OCW

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

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

APCS Semester #1 Final Exam Practice Problems

(b) This is a valid identifier in Java: _T_R-U_E_. (c) This is a valid identifier in Java: _F_A_L_$_E_

Practice Questions for Final Exam: Advanced Java Concepts + Additional Questions from Earlier Parts of the Course

King Saud University College of Computer and Information Sciences Computer Science Department

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

coe318 Lab 2 ComplexNumber objects

Programming Problems 22nd Annual Computer Science Programming Contest

CSci 1103 Final. Name: Student ID:

public int calculatedamage() { // Generate and return the damage inflicted on ship }

Guru Gobind Singh Public School Sector V,B Bokaro Steel City Annual IP Assignment Class 11

Transcription:

CMP 326 Midterm Fall 2015 Name: 1) (30 points; 5 points each) Write the output of each piece of code. If the code gives an error, write any output that would happen before the error, and then write ERROR. If there is an infinite loop, write what that output is the first three times through the loop, and then write INFINITE. Code Output a) int a = 5; int b = 2; double c = 5; System.out.println( ((double) a)/b); System.out.println(a/b); System.out.println(c/b); System.out.println(b/a); b) String s = Lehman ; int i = 1; while (i < s.length()) { System.out.println(s); s = s.substring(i); i++; System.out.println(s); c) for (int i = 0;i < 4; i++) { for (int j = i; j < 4; j++) { System.out.print(j); System.out.println(); d) boolean y = true; int k = 0; while (y) { k++; System.out.println(k); System.out.println(y); Page 1 of 7

1) (Continued) Code Output e) public class Abc { int a = 0; int b = 0; public Abc(int c) { a = c; public String tostring() { return "a=" + a + "; b=" + b; public static void main(string[] args){ Abc f = new Abc(5); System.out.println(f); Abc g = f; System.out.println(f); System.out.println(g); g.b = 7; System.out.println(f); System.out.println(g); f) public class Test { static int num = 0; String s = "cat"; public Test() { num++; public void fn() { s = "" + s.charat(0); num = 44; public static void main(string[] args) { Test a = new Test(); System.out.println("a:" +num+" " +a.s); Test b = new Test(); System.out.println("b:" +num+" " +b.s); a.fn(); System.out.println("a:" +num+" " +a.s); System.out.println("b:" +num+" " +b.s); Page 2 of 7

2) (30 points) The Java class called BaseballTeam is started below. An object of class BaseballTeam represents a Major or Minor League Baseball team. This class has four private instance variables: name, which is a String representing the name of the team numgamesplayed, which is an int representing the number of games played so far in this season numgameswon, which is an int representing the number of games won so far this season ismajor, which is a boolean representing whether the team is a major or minor league team (set to true for major, and false for minor) public class BaseballTeam { private String name; private int numgamesplayed; private int numgameswon; private boolean ismajor; // your code will go here a) (7 points) Write a constructor which takes in a name, number of games played, number of games won, and boolean of whether the team is a major league team or not, and assigns those values to a BaseballTeam object. b) (5 points) Use your constructor from part (a) to instantiate an object of class BaseballTeam with name New York Yankees, 162 games played, 87 wins, and a major league team. 2) (continued) Page 3 of 7

c) (8 points) Write a setter (mutator) method for the instance variable numgamesplayed. This setter should only allow numgamesplayed to be set to 0 or a positive number. If a negative number is passed in, a error message should be printed and the value of numgamesplayer should not be changed. d) (10 points) Write a non-static method iswinningteam which does not have a parameter, and returns a boolean value. This method should return true if the team has won half or more of the games played, and false if not. Page 4 of 7

3) (10 points) Write a method rearrange which does not return anything and has one parameter: a double array. This method should: - replace the first element of the array with the last element of the array - replace all other array elements with the original first element of the array If the array has length 0 or 1, do not change the array. For example, if the array is 4.2-10.0 9.5 0.0 2.66 then arrange should change it to 2.66 4.2 4.2 4.2 4.2 Page 5 of 7

4) (15 points) Write a piece of code which allows the user to enter the grades for multiple tests and average them. Specifically, this code should: 1. ask the user how many tests they have, and how many questions each test has. (You may assume all tests have the same number of questions.) 2. ask the user for the scores for each question for each test. 3. print the total score for each test (the total score is the sum of the scores for all questions in that test) 4. print the average total score (averaged over all the tests) Page 6 of 7

6) (15 points) Consider the Java GUI below that contains 1 TextField, 2 Labels, and 2 Buttons: public class Counter extends JFrame implements ActionListener{ JTextField text1 = new JTextField(20); JButton countbutton = new JButton("COUNT"); JButton anotherbutton = new JButton("DOES NOTHING"); JLabel label1 = new JLabel("Enter a String:"); JLabel label2 = new JLabel("Number of a s:"); // other methods in the class, including the // constructor and main method are not shown here public void actionperformed(actionevent e){ // your code will go here Define the body of the actionperformed method as follows: - if the button labeled COUNT is clicked, then JLabel label2 is set to be the number of letter a s in the String entered in JTextField text1 Remember that there is NO count method in Java. You may define and use a helper method. Page 7 of 7