AP CS Unit 4: Classes and Objects Programs
|
|
- Ashlynn Shields
- 6 years ago
- Views:
Transcription
1 AP CS Unit 4: Classes and Objects Programs 1. Copy the Bucket class. Make sure it compiles (but you won t be able to run it because it does not have a main method). public class Bucket { private double amt; private final double CAPACITY; Add a second class (named BucketRunner) that does contain a main method. The main method should do the following: create a Bucket object that can hold 10 gallons. add a random amount using Math.random. The amount should be a decimal between 5 (inc) and 12 (exc). display how full the bucket is (e.g. 74%) empty the bucket call the percentfull method again and display the returned value ( it should be zero). 2. Copy the Walker method and complete the walk method. Then make sure it compiles. Add a second class (named Runner) and enter this code: public class Runner { public static void main(string[] args) { Walker w1 = new Walker(); w1.walk( 5 ); w1.walk( 10 ); w1.walk( 8 ); System.out.println( "w1 is now at " + w1.getx() ); Run it and make sure it works. 3. Add a third class that contains a main method. In this main method create another walker and keep calling the walk method (with an argument of 10) until its x value is 100 or greater. After it reaches 100, display its x value and the number of times the walk method was called. public Bucket( double c ) { CAPACITY = c; // gallons amt = 0; public void emptybucket() { amt = 0; public void add ( double stuff ) { amt += stuff; if ( amt > CAPACITY ) amt = CAPACITY; public double percentfull( ){ return 100 * amt / CAPACITY; public class Walker { private int x; public Walker() { x = 0; public void walk( int max ){ /* If max is less than one this method does nothing. If max is positive, then this method generates a random number between zero and max (inclusive) and increases x by that amount. */ public int getx(){ return x;
2 4. Copy and complete the CoinTosser class. An object of this class is someone who really likes tossing a coin and seeing how many times they get heads. Create another class with a main method. In that method: Instantiate two CoinTosser objects using these two names. Have each CossTosser toss his/her coin 100 times. (In other words, call the toss method). Determine who had the most heads and print out something like: #1 wins, 54.0% to 47.0% If it s a tie, say so. 5. Create another class with a main method. This is similar to the above exercise. You will again enter 2 names and instantiate 2 CoinTosser objects. But this time they will play 1,000 contests (where each contest consists of 100 tosses). This means that the main method should contain a for-loop. At the end of each iteration you need to call the reset method. Print out the results of each contest and at the end print out the number of wins for each. The results should look something like this: #1 wins, 60.0% to 47.0% #1 wins, 50.0% to 41.0% It is a tie! Both had 47.0%... #1 wins, 52.0% to 45.0% #2 wins, % to 46.0% #1 wins, 51.0% to 48.0% public class CoinTosser { private int numtosses; private int numheads; public CoinTosser() { numtosses = 0; numheads = 0; public void toss(int n){ numtosses += n; for ( int k = 1; k <= n; k++ ){ if ( heads() ) numheads++; public void reset() { numtosses = 0; numheads = 0; private boolean heads() { // half the time it returns true public double getpercentheads() { /* returns percentage of heads. For example, if 3 heads out of 4 tosses, returns 0.75 */ #1 had 546 wins #2 had 452 wins #1 wins!
3 6. First, complete the Star class. public class Star{ private int x, y, z; public Star(){ // assign the instance variables random values between 0 and 20 // write accessor methods for the instance variables public double distance( int x1, int y1, int z1 ){ // returns the distance from (x, y, z) to (x1, y1, z1) public void display(){ System.out.println( "coordinates: " + x + ", " + y + ", " + z ); Second, write a runner class that creates three Star objects and calls their display methods. Then it calculates (using the distance method) and displays the distance between the three stars. If the stars create an isosceles or equilateral triangle, it displays a message to that effect. Otherwise it determines and displays which two stars are closest to each other. Here s a sample output: Star 1 coordinates: 15, 20, 18 Star 2 coordinates: 7, 14, 15 Star 3 coordinates: 14, 18, 20 The distance from star 1 to star 2 is The distance from star 2 to star 3 is The distance from star 3 to star 1 is 3.0 Star 3 and Star 1 are the closest 7. Complete any three exercises from the String1 category at codingbat.com. 8. Complete any five exercises from the String2 category at codingbat.com. 9. Complete any three exercises from the String3 category at codingbat.com.
4 10. First, complete the code below to create a Plant class. public class Plant { private String name; private boolean living; //create a constructor (no parameters), alive = true, name =??? // write a mutator method for name // write an accessor method for name // write an addwater method that has an int parameter that represents the water added. If the amount of water added is less than 20 or greater than 80, then set living equal to false. Otherwise do nothing. Note: if a Plant is dead, then adding any amount of water to it cannot bring it back to life. public String tostring() { // returns the name and whether the plant is alive or not. Second, write a class that has a main method. The main method should: Instantiate three Plant objects. Adds a random amount of water (between 0 and 100 units) to each plant. After watering the plants, call the tostring method for each plant. 11. First, complete the code below to create a Sentence class. Note, consider any series nonwhite characters as a word. For example, the following count as words: mom, 34T, and?$_q. public class Sentence{ private String stringy; // constructor with a String parameter // write an accessor method for stringy public String trim(){ /* return a string that is identical to stringy except that there is exactly one space between each word in stringy. For example, if stringy is cat dog then this method returns cat dog (with one space between cat and dog). */ public int count(){ // returns the number of words in stringy. May return zero. // this is a lot easier if you call the above trim method within this method Create a main method that asks the user to enter three sentences. Create three Sentence objects and call the trim and count methods. Display the return values.
5 12. Complete the Name class public class Name { private String first, middle, last; public Name( String str ) { check_name( str ); private void check_name( String nm ){ nm contains a name such as John Jacob Jingleheimer Schmidt or Tuhin Gupta. You may assume that there is at least a first and last name in nm. You need to break nm into first, middle, and last names and correctly assign them to the instance variables. You may assume that nm has at least two parts. If there are 2 parts then middle should be a blank String. If there are 3 parts, then you know what to do. If there are more than 3 parts, then assign part 1 to first, part 2 to middle, and everything else to last. The first thing this method should do is call the remove_spaces method. private String remove_spaces( String s ){ This returns a String that is identical to s except that all leading and trailing spaces have been removed. In addition, if there are two or more adjacent spaces then all but one are removed. For example: if s is " that's my name too " then it returns "that's my name too" public String full_name(){ Returns first + middle + last but there should be exactly one space between each part. If there is no middle name then there should be only one space between first and last public String tostring(){ return last + ", " + first + " " + middle; Write a second class that has a main method. Have the user enter their name. Instantiate a Name object and then call the full_name and tostring methods and display the results.
APCS Semester #1 Final Exam Practice Problems
Name: Date: Per: AP Computer Science, Mr. Ferraro APCS Semester #1 Final Exam Practice Problems The problems here are to get you thinking about topics we ve visited thus far in preparation for the semester
More informationIntroduction to Computer Science Unit 4B. Programs: Classes and Objects
Introduction to Computer Science Unit 4B. Programs: Classes and Objects This section must be updated to work with repl.it 1. Copy the Box class and compile it. But you won t be able to run it because it
More informationAP CS Unit 6: Inheritance Notes
AP CS Unit 6: Inheritance Notes Inheritance is an important feature of object-oriented languages. It allows the designer to create a new class based on another class. The new class inherits everything
More informationTable of Contents Date(s) Title/Topic Page #s. Chapter 4: Writing Classes 4.1 Objects Revisited
Table of Contents Date(s) Title/Topic Page #s 11/6 Chapter 3 Reflection/Corrections 56 Chapter 4: Writing Classes 4.1 Objects Revisited 57 58-59 look over your Ch 3 Tests and write down comments/ reflections/corrections
More informationFinal Exam CS 152, Computer Programming Fundamentals May 9, 2014
Final Exam CS 152, Computer Programming Fundamentals May 9, 2014 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationAP Computer Science A Unit 7. Notes on Arrays
AP Computer Science A Unit 7. Notes on Arrays Arrays. An array is an object that consists of an of similar items. An array has a single name and the items in an array are referred to in terms of their
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 informationBinghamton University. CS-140 Fall Problem Solving. Creating a class from scratch
Problem Solving Creating a class from scratch 1 Recipe for Writing a Class 1. Write the class boilerplate stuff 2. Declare Fields 3. Write Creator(s) 4. Write accessor methods 5. Write mutator methods
More informationChapter 4 Defining Classes I
Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the
More informationJava Review. Fundamentals of Computer Science
Java Review Fundamentals of Computer Science Link to Head First pdf File https://zimslifeintcs.files.wordpress.com/2011/12/h ead-first-java-2nd-edition.pdf Outline Data Types Arrays Boolean Expressions
More information// constructor: takes a String as parameter and creates a public Cat (String x) { name = x; age = 0; lives = 9; // cats start out with 9 lives }
Quiz 6 Name: 1. Suppose you have a class Cat defined as shown below. Fill in the code for the indicated methods, following guidelines given through comments. public class Cat // instance variables String
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 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 informationCS 302 Week 9. Jim Williams
CS 302 Week 9 Jim Williams This Week P2 Milestone 3 Lab: Instantiating Classes Lecture: Wrapper Classes More Objects (Instances) and Classes Next Week: Spring Break Will this work? Double d = new Double(10);
More informationThis 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 informationAP CS Unit 7: Arrays Exercises
AP CS Unit 7: Arrays Exercises 1. What is displayed? int [] a = new int[ 3 ]; System.out.println(a.length ); 2. What is displayed? int [] sting = { 34, 23, 67, 89, 12 ; System.out.println( sting[ 1 ] );
More informationAdvanced Java Concepts Unit 2: Linked Lists.
Advanced Java Concepts Unit 2: Linked Lists. The List interface defines the structure of a linear collection. Here are some of its methods. boolean add( E element ) Appends the element to the end of the
More informationUniversity of Cape Town ~ Department of Computer Science Computer Science 1015F ~ June Exam
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 June Exam Question Max Internal
More informationData Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.
Data Structures 1 Data structures What is a data structure? Simple answer: a collection of data equipped with some operations. Examples Lists Strings... 2 Data structures In this course, we will learn
More information1 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 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 information1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean
Practice Final Quiz 1 If you want to store a letter grade (like a course grade) which variable type would you use? a. int b. String c. char d. boolean 2 If you wanted to divide two numbers precisely, which
More informationInstance Method Development Demo
Instance Method Development Demo Write a class Person with a constructor that accepts a name and an age as its argument. These values should be stored in the private attributes name and age. Then, write
More information3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal
APCS A Midterm Review You will have a copy of the one page Java Quick Reference sheet. This is the same reference that will be available to you when you take the AP Computer Science exam. 1. n bits can
More informationJava 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 informationWES-CS GROUP MEETING #9
WES-CS GROUP MEETING #9 Exercise 1: Practice Multiple-Choice Questions 1. What is output when the following code executes? String S1 = new String("hello"); String S2 = S1 +! ; S1 = S1 + S1; System.out.println(S1);
More informationCSE 143 Lecture 10. Recursion
CSE 143 Lecture 10 Recursion slides created by Marty Stepp and Alyssa Harding http://www.cs.washington.edu/143/ Recursion Iteration: a programming technique in which you describe actions to be repeated
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 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 informationAP 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 informationCMP 326 Midterm Fall 2015
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.
More informationClasses Classes 2 / 36
Classes 1 / 36 Classes Classes 2 / 36 Anatomy of a Class By the end of next lecture, you ll understand everything in this class definition. package edu. gatech. cs1331. card ; import java. util. Arrays
More informationIntroduction to Java Programs for Packet #4: Classes and Objects
Introduction to Java Programs for Packet #4: Classes and Objects Note. All of these programs involve writing and using more than one class file. 1. Copy the Box class and compile it. But you won t be able
More informationAP Computer Science Unit 1. Programs
AP Computer Science Unit 1. Programs Open DrJava. Under the File menu click on New Java Class and the window to the right should appear. Fill in the information as shown and click OK. This code is generated
More informationCS 251 Intermediate Programming Methods and Classes
CS 251 Intermediate Programming Methods and Classes Brooke Chenoweth University of New Mexico Fall 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationCS 251 Intermediate Programming Methods and More
CS 251 Intermediate Programming Methods and More Brooke Chenoweth University of New Mexico Spring 2018 Methods An operation that can be performed on an object Has return type and parameters Method with
More informationFaculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination
First Name: Last Name: McGill ID: Section: Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination Monday, March 9, 2009 Examiners: Mathieu Petitpas [Section 1] 18:30
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 informationCS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class
CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class For this assignment we will be developing a text-based Tic Tac Toe game 1. The key to this assignment is that we re going
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 Supplementary Examination Question
More informationSlide 1 CS 170 Java Programming 1
CS 170 Java Programming 1 Objects and Methods Performing Actions and Using Object Methods Slide 1 CS 170 Java Programming 1 Objects and Methods Duration: 00:01:14 Hi Folks. This is the CS 170, Java Programming
More informationPROGRAMMING 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 informationUnit 4: Classes and Objects Notes
Unit 4: Classes and Objects Notes AP CS A Another Data Type. So far, we have used two types of primitive variables: ints and doubles. Another data type is the boolean data type. Variables of type boolean
More informationUnit 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 informationSet<Integer> s = new TreeSet<Integer>(); s.add( 7 ); s.add( 7 ); System.out.println( s.size() );
Advanced Java Concepts Maps and Sets and Miscellany Exercises and Programs 1. This code a) contains a compiler error. b) contains a runtime error. c) displays 1 d) displays 2 2. This code a) contains a
More informationCS 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 informationCSE115 Introduction to Computer Science I Coding Exercise #7 Retrospective Fall 2017
This week the main activity was a quiz activity, with a structure similar to our Friday lecture activities. The retrospective for the quiz is in Quiz-07- retrospective.pdf This retrospective explores the
More informationProblem Grade Total
CS 101, Prof. Loftin: Final Exam, May 11, 2009 Name: All your work should be done on the pages provided. Scratch paper is available, but you should present everything which is to be graded on the pages
More informationUnit 5: More on Classes/Objects Exercises
Unit 5: More on Classes/Objects Exercises AP CS A 1. Select the TRUE statement. a) This does not compile. b) This does compile.. Select the TRUE statement. a) This does not compile. b) This does compile.
More informationFinal Exam CS 152, Computer Programming Fundamentals December 9, 2016
Final Exam CS 152, Computer Programming Fundamentals December 9, 2016 Name: NetID: Answer all questions in the space provided. Write clearly and legibly, you will not get credit for illegible or incomprehensible
More informationAP CS Unit 6: Inheritance Exercises
AP CS Unit 6: Inheritance Exercises 1. Suppose your program contains two classes: a Student class and a Female class. Which of the following is true? a) Making the Student class a subclass of the Female
More informationAP CS Unit 8: Inheritance Exercises
AP CS Unit 8: Inheritance Exercises public class Animal{ System.out.print("A"); public void m2(){ System.out.print("B"); public class Dog extends Animal{ System.out.print("C"); public void m3(){ System.out.print("D");
More informationProgramming 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 informationCONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics. COMP-202 Unit 1: Introduction
CONTENTS: What Is Programming? How a Computer Works Programming Languages Java Basics COMP-202 Unit 1: Introduction Announcements Did you miss the first lecture? Come talk to me after class. If you want
More informationCS 1302 Chapter 9 (Review) Object & Classes
CS 1302 Chapter 9 (Review) Object & Classes Reference Sections 9.2-9.5, 9.7-9.14 9.2 Defining Classes for Objects 1. A class is a blueprint (or template) for creating objects. A class defines the state
More informationCS 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 informationObject Oriented Programming
Object Oriented Programming Objectives To review the concepts and terminology of object-oriented programming To discuss some features of objectoriented design 1-2 Review: Objects In Java and other Object-Oriented
More informationCISC-124. Passing Parameters. A Java method cannot change the value of any of the arguments passed to its parameters.
CISC-124 20180215 These notes are intended to summarize and clarify some of the topics that have been covered recently in class. The posted code samples also have extensive explanations of the material.
More informationCSE 11 Midterm Fall 2008
Signature cs11f Name Student ID CSE 11 Midterm Fall 2008 Page 1 (10 points) Page 2 (22 points) Page 3 (23 points) Page 4 (17 points) Page 5 (12 points) Total (84 points = 80 base points + 4 points EC [5%])
More informationKey Java Simple Data Types
AP CS P w Java Unit 1 Multiple Choice Practice Key Java Simple Data Types This test includes program segments, which are not complete programs. Answer such questions with the assumption that the program
More informationReview Chapter 6 in Bravaco. Short Answers 1. This type of method does not return a value. a. null b. void c. empty d. anonymous
Assignment 3 Methods Review CSC 123 Fall 2018 Notes: All homework must be submitted via e-mail. All parts of assignment must be submitted in a single e-mail with multiple attachments when required. Notes:
More informationCSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015
CSCI 136 Written Exam #2 Fundamentals of Computer Science II Spring 2015 Name: This exam consists of 6 problems on the following 6 pages. You may use your double- sided hand- written 8 ½ x 11 note sheet
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 informationAP CS Unit 7: Interfaces. Programs
AP CS Unit 7: Interfaces. Programs You cannot use the less than () operators with objects; it won t compile because it doesn t always make sense to say that one object is less than
More informationIntroduction to the Java Basics: Control Flow Statements
Lesson 3: Introduction to the Java Basics: Control Flow Statements Repetition Structures THEORY Variable Assignment You can only assign a value to a variable that is consistent with the variable s declared
More informationPractice Midterm 1. Problem Points Score TOTAL 50
CS 120 Software Design I Spring 2019 Practice Midterm 1 University of Wisconsin - La Crosse February 25 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages including the
More informationCS 101 Fall 2006 Midterm 3 Name: ID:
You only need to write your name and e-mail ID on the first page. This exam is CLOSED text book, closed-notes, closed-calculator, closed-neighbor, etc. Questions are worth different amounts, so be sure
More informationObject-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007
Object-Oriented Design Lecture 3 CSU 370 Fall 2007 (Pucella) Friday, Sep 14, 2007 Java We will be programming in Java in this course. Partly because it is a reasonable language, and partly because you
More informationpublic static boolean isoutside(int min, int max, int value)
See the 2 APIs attached at the end of this worksheet. 1. Methods: Javadoc Complete the Javadoc comments for the following two methods from the API: (a) / @param @param @param @return @pre. / public static
More informationDocumenting, Using, and Testing Utility Classes
Documenting, Using, and Testing Utility Classes Readings: Chapter 2 of the Course Notes EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Structure of Project: Packages and Classes
More informationASSIGNMENT 4 Classes and Objects
ASSIGNMENT 4 Classes and Objects COMP-202A, Fall 2010, All Sections Due: Friday, November 19, 2010 (23:55) You MUST do this assignment individually and, unless otherwise specified, you MUST follow all
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 informationBirkbeck (University of London) Software and Programming 1 In-class Test Mar 2018
Birkbeck (University of London) Software and Programming 1 In-class Test 2.1 22 Mar 2018 Student Name Student Number Answer ALL Questions 1. What output is produced when the following Java program fragment
More informationAP CS Unit 7: Interfaces Exercises Assume all code compiles unless otherwise suggested.
AP CS Unit 7: Interfaces Exercises Assume all code compiles unless otherwise suggested. 1. The Nose class... b) will not compile because the m1 method parameter should be named n, not x. 2. The Ears class...
More informationLecture 15. For-Loops
Lecture 15 For-Loops Announcements for This Lecture Today s Material Section 2.3.8 (first use of loops in the text) All of Chapter 7 Two topics covered today Elementary graphics For-loops Both used on
More informationSPRING 13 CS 0007 FINAL EXAM V2 (Roberts) Your Name: A pt each. B pt each. C pt each. D or 2 pts each
Your Name: Your Pitt (mail NOT peoplesoft) ID: Part Question/s Points available Rubric Your Score A 1-6 6 1 pt each B 7-12 6 1 pt each C 13-16 4 1 pt each D 17-19 5 1 or 2 pts each E 20-23 5 1 or 2 pts
More information(a) Write the signature (visibility, name, parameters, types) of the method(s) required
1. (6 pts) Is the final comprehensive? 1 2. (6 pts) Java has interfaces Comparable and Comparator. As discussed in class, what is the main advantage of Comparator? 3. (6 pts) We can use a comparator in
More informationCSE 142 Su 04 Computer Programming 1 - Java. Objects
Objects Objects have state and behavior. State is maintained in instance variables which live as long as the object does. Behavior is implemented in methods, which can be called by other objects to request
More informationDay 3. COMP 1006/1406A Summer M. Jason Hinek Carleton University
Day 3 COMP 1006/1406A Summer 2016 M. Jason Hinek Carleton University today s agenda assignments 1 was due before class 2 is posted (be sure to read early!) a quick look back testing test cases for arrays
More informationChapter 7 Classes & Objects, Part B
Chapter 7 Classes & Objects, Part B These note present Dog simulation example that shows how we go about OO modeling. A number of new things are introduced. They also present the Person > BirthDate example.
More informationC# Programming for Developers Course Labs Contents
C# Programming for Developers Course Labs Contents C# Programming for Developers...1 Course Labs Contents...1 Introduction to C#...3 Aims...3 Your First C# Program...3 C# The Basics...5 The Aims...5 Declaring
More informationJava Classes - Using your classes. How the classes you write are being used
Java Classes - Using your classes How the classes you write are being used What s the use of classes? So, you have been writing a few classes by now... What for? The programs you will write will use objects
More informationJava Foundations: Unit 3. Parts of a Java Program
Java Foundations: Unit 3 Parts of a Java Program class + name public class HelloWorld public static void main( String[] args ) System.out.println( Hello world! ); A class creates a new type, something
More informationStrings. Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects.
Strings Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects. The Java platform provides the String class to create and
More informationCS212 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 informationCHAPTER 7 OBJECTS AND CLASSES
CHAPTER 7 OBJECTS AND CLASSES OBJECTIVES After completing Objects and Classes, you will be able to: Explain the use of classes in Java for representing structured data. Distinguish between objects and
More informationAP CS Unit 7: Interfaces Exercises 1. Select the TRUE statement(s).
AP CS Unit 7: Interfaces Exercises 1. Select the TRUE statement(s). a) This code will not compile because a method cannot specify an interface as a parameter. public class Testing { public static void
More informationUnit 4: Classes and Objects Exercises
Unit 4: Classes and Objects Exercises AP CS A 1. What is boolean a = 5 < 7; System.out.println( a ); 2. What does this display? boolean b = false; for ( int n = 1; n < 4; n++ ){ b =!b; System.out.print(
More informationAbstract classes are used to define a class that will be used only to build new classes. No objects will ever be instantiated from an abstract class.
Abstract classes are used to define a class that will be used only to build new classes. No objects will ever be instantiated from an abstract class. Mammal (abstract class) Human Whale Cow Any sub class
More informationAP Computer Science A Summer Assignment 2017
AP Computer Science A Summer Assignment 2017 The objective of this summer assignment is to ensure that each student has the ability to compile and run code on a computer system at home. We will be doing
More informationNews and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!
True object-oriented programming: Dynamic Objects Reference Variables D0010E Object-Oriented Programming and Design Lecture 3 Static Object-Oriented Programming UML" knows-about Eckel: 30-31, 41-46, 107-111,
More informationCS 1331 Exam 1 ANSWER KEY
CS 1331 Exam 1 Fall 2016 ANSWER KEY Failure to properly fill in the information on this page will result in a deduction of up to 5 points from your exam score. Signing signifies you are aware of and in
More informationExpress Yourself. Writing Your Own Classes
Java Programming 1 Lecture 5 Defining Classes Creating your Own Classes Express Yourself Use OpenOffice Writer to create a new document Save the file as LastFirst_ic05 Replace LastFirst with your actual
More informationTo keep track of this new wrinkle we need some new variables at the Class level:
CS201 Arrays Part II Random Trivia Game Let s refine our trivia game, and say that we would like to randomly select four questions out of all of the questions that we loaded, ask each to the player, output
More informationAssignment 4. Aggregate Objects, Command-Line Arguments, ArrayLists. COMP-202B, Winter 2011, All Sections. Due: Tuesday, March 22, 2011 (13:00)
Assignment 4 Aggregate Objects, Command-Line Arguments, ArrayLists COMP-202B, Winter 2011, All Sections Due: Tuesday, March 22, 2011 (13:00) You MUST do this assignment individually and, unless otherwise
More informationPractice problem on defining and using Class types. Part 4.
CS180 Programming Fundamentals Practice problem on defining and using Class types. Part 4. Implementing object associations: Applications typically consist of collections of objects of different related
More informationClass API. Class API. Constructors. CS200: Computer Science I. Module 19 More Objects
CS200: Computer Science I Module 19 More Objects Kevin Sahr, PhD Department of Computer Science Southern Oregon University 1 Class API a class API can contain three different types of methods: 1. constructors
More informationCMSC 341 Lecture 7 Lists
CMSC 341 Lecture 7 Lists Today s Topics Linked Lists vs Arrays Nodes Using Linked Lists Supporting Actors (member variables) Overview Creation Traversal Deletion UMBC CMSC 341 Lists 2 Linked Lists vs Arrays
More informationReview questions. Review questions, cont d. Class Definition. Methods. Class definition: methods. April 1,
April 1, 2003 1 Previous Lecture: Intro to OOP Class definition: instance variables & methods Today s Lecture: Instance methods Constructors Methods with input parameters Review questions Where do you
More informationCS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)
CS/B.TECH/CSE(New)/SEM-5/CS-504D/2013-14 2013 OBJECT ORIENTED PROGRAMMING Time Allotted : 3 Hours Full Marks : 70 The figures in the margin indicate full marks. Candidates are required to give their answers
More information