CSC-140 Assignment 6
|
|
- Elisabeth Butler
- 6 years ago
- Views:
Transcription
1 CSC-140 Assignment 6 1 Introduction In this assignment we will start out defining our own classes. For now, we will design a class that represents a date, e.g., Tuesday, March 15, 2011, or in short hand notation: 03/15/2011. Before we specify the requirements for the class, let us just recap the important things we have learned about fields, methods and modifiers. 1.1 Modifiers Let us briefly recap the modifiers public, private, static, and final. Let us start from the back The Final Modifier If the final modifier is used with a field, it means that the field cannot be re-defined in any subclass (we haven t talked about subclasses yet, so don t worry about that), but the final modifier is also used when we wanted to declare someting as a constant (typically together with the modifier static.) The final modifier with a method means that it cannot be re-implemented in any subclasses of the class. (Again, don t worry about that for now.) The Static Modifier The static modifier is very important - please make sure you understand it 100%. If a field is declared static, only one instance of it exists, namely in the class in which it was declared. If a field is not static, each object created based on the class will have its own copy of the field. If a method is static, it can only operate on its parameters, locals and any static fields. It is important to understand why a static method cannot access non-static fields: A non-static field is associated with an object; a static method is associated with a class (just like a static field). 1
2 A static method f in a class A can be invoked as: A.f(), which means that there will be no object context, i.e., all non-static fields won t be accessible because they live in objects, but no objects are present The Public and Private Modifiers The public modifier used with a field (field) allows anyone holding a reference to the object (o), in which the field was declared, to access it through o.field. If the field is static it can further more be accessed though the class in the same manner. The same is true for methods. If the private modifier is used with a field, only object of the same class may access these fields. The same is true for methods. 2 The Date Class We wish to write a public class called Date. It should be placed in a file called Date.java. It should have three private fields: one to represent the day, one for the month, and one for the year. You can use int as a type. Further more, 2 constant String arrays (private, static and final, one called days with the names of the weekdays, starting at Sunday, and one called months with the names of the months, starting at January. Question 1: compiles. Implement this class with the 5 fields, and make sure it 2.1 Constructors and Factory Methods Naturally a class like Date should have a constructor that takes in three parameters: day, month, and year, and transfers them to the fields. Remember, if a field and a parameter is called the same, the field (if it is non-static) can be referenced by prefixing this. (this and a dot. ). However, what happens if we instantiate the class like this: newdate(15, 34, 4576); There is no 34th day in the non-existing 15th month, and the year cannot be negative, we would get a strange object representing a non-existing date. 2
3 However, we still need a constructor, but if we make it private, it cannot be invoked from outside the class. Now, how do we instantiate a class if there is no constructor? We can make a static method called makedate that takes in the day, month and year, and then before instantiating the Date class using the private constructor, it validates the date. The code for makedate is here: public static Date makedate(int day, int month, int year) { if (validdate(day,month, year)) return new Date(day, month, year); else return null; } If the validdate call returns false, no object is constructed, and the null value is returned. If the date is valid, we instantiate the object through the private constructor, and return the newly created object. Outside the class we could have code that looks something like this: Date da = Date.makeDate(12,31,2011); if (da!= null) // do something with it Your next task is to write the static method validdate used in the code snippet above, but even before that we need another private, static helper method called isleapyear, that takes in an integer parameter, representing a year, and returns a boolean value: true if the year is a leap year, false otherwise. A year is a leap year if it is divisible by 4 (i.e., the remainder when dividing by 4 is 0), unless it is divisible by 100 (the it is not a leap year, so 1900 was not a leap year), unless divisible by 400, because then it is a leap year (2000 is divisible by 4, and 100 but also by 400, so it is a leap year). No we can write validdate with the following interface: public static boolean validdate(int day, int month, int year) according to the following specification: 3
4 validdate should return true if all of the following consitions are met: The year should be greater than or equal to 1500 and smaller than or equal to The month should be greater than or equal to 1 (representing January) and smaller than or equal to 12 (representing December). The day should be greater than or equal to 1 and if the month is 1,3,5,7,8,10, or 12, smaller than or equal to 31; if the month is 4,6,9, or 11, day should be smaller than or equal to 30, and if the month is 2 (representing February, it should be smaller than or equal to 28 unless the year is a leap year, then it could be a large as 29. Question 2: Implement isleapyear Question 3: Implement isvaliddate Question 4: Implement makedate as it is shown above as well as the private constructor 2.2 Turning Objects in to Strings Java allows the author of a class to implement a special public method called tostring(); it takes no parameters and returns a String. This method is automatically invoked when a variable holding a reference to an object is used in an expression of String type. E.g. If da is a reference to an object of Date type, then String s = "Today s date is " + da; is the same as: String s = "Today s date is " + da.tostring(); Implement tostring() for the Date class such that the string returned is mm/dd/yyyy, where mm is the month, dd is the day, and yyyy is the year. Make sure that if the month and/or the day is less than 10 (i.e., does not 4
5 take up 2 spaces), that you pad an extra "0" on there. For example, January 7th, 2002 should be 01/07/2002. Question 5: Implement the tostring() method. 2.3 Printing a Fancy Date We can use the value of the month field as an index into the months array to get a textual representation of the month, but if we want to know the weekday, we need to do a little arithmetic. In the following, day, month, and year refer to the fields of a Date object. The value in the variable d will be the index into the days array. All the arithmetic is integer arithmetic. a = 14 month 12 y = year a m = month + 12 a 2 d = (day + y + y 4 y y m 12 ) % 7 Question 6: Implement a public method called getfancydate() that returns a string (appropriate for the date represented by the object), that looks like this: Friday, January 7, Comparing Dates You must write a public method called isearlier that takes in another Date object, and return a boolean. false should be returned if the parameter object represents an earlier date than the object on which the method was invoked. For example: Date d1 = Date.makeDate(1,3,2010); Date d2 = Date.makeDate(10,5,2011); boolean b1 = d1.isealier(d2); boolean b2 = d2.isealier(d1); would leave the value true in b1 and false in b2. Since the parameter is of the same type as the object to which it is passed (called the target object), the target object could access the private fields 5
6 though objref.fieldname, e.g., d2.year, but it isn t a very nice way to do it. Also, if someone else is holding a reference to a Date object and would like to know the day, there is no way to gain access to the day field as it is private to the object, and thus cannot accessed as objref.fieldname. Therefore, the class should have accessor methods that return the values of the various data fields. E.g. We can write a public method called getday() that returns the day field like this: public int getday() { return day; } Question 7: Implement getday(), getmonth(), and getyear()/ Question 8: Implement isealier(date d2). 3 Topics Covered Modifiers (static, public, private, final). Fields. Methods. Constructors / factory methods. Converting Objects to strings. 4 Work List 1. Make sure you read the Topics Covered section and familiarize yourself with all the topics. 2. Create a file Date.java, and implement the code from the questions above. 3. Create a file DateTest.java (you can see an example of one at the end of this handout) to test your code in. 6
7 4. Test your program with a number of different values. 5. Once you are happy with your solution, type the following: tar -cvf Assignment6.tar Date.java DateTest.java to create a.tar file that you can then go to csgfms.cs.unlv.edu and hand it in. If you don t name your two files Date.java and DateTest.java the tar command will fail. 6. Bring to class (along with the printout of your solution) a write up in which you explain how you solved the problem, and show output from a couple of tests; enough to convince me that it works. 5 Due Date The Assignment6.tar file must be uploaded to csgfms.cs.unlv.edu no later than Monday April 4th before midnight (midnight between Monday and Tuesday), and the write up should be brought to class the day after. 7
8 6 Sample Output from my Solution Invalid Date. d1 = 05/01/2003 d2 = 07/05/2001 d3 = 07/07/2007 d4 = 01/01/2001 Thursday, May 1, 2003 Thursday, July 5, 2001 Saturday, July 7, 2007 Monday, January 1, 2001 Is Thursday, May 1, 2003 Earlier than Thursday, July 5, 2001? false Here is the code I used to test my program, and what generated the above output: public class DateTest { public static void main(string[] args) { Date d1,d2,d3,d4,d5; d1 = Date.makeDate(1,5,2003); d2 = Date.makeDate(5,7,2001); d3 = Date.makeDate(7,7,2007); d4 = Date.makeDate(1,1,2001); d5 = Date.makeDate(12,45,-6787); if (d5 == null) System.out.println("Invalid Date."); else System.out.println("d5 = " + d5); System.out.println("d1 = " + d1); System.out.println("d2 = " + d2); System.out.println("d3 = " + d3); System.out.println("d4 = " + d4); System.out.println(d1.getFancyDate()); System.out.println(d2.getFancyDate()); System.out.println(d3.getFancyDate()); 8
9 } } System.out.println(d4.getFancyDate()); System.out.println("Is " + d1.getfancydate() + " Earlier than " + d2.getfancydate() + "? " + d1.isearlier(d2)); 9
Handout 7. Defining Classes part 1. Instance variables and instance methods.
Handout 7 CS180 Programming Fundamentals Spring 15 Page 1 of 8 Handout 7 Defining Classes part 1. Instance variables and instance methods. In Object Oriented programming, applications are comprised from
More informationCSC-140 Assignment 5
CSC-140 Assignment 5 Please do not Google a solution to these problems, cause that won t teach you anything about programming - the only way to get good at it, and understand it, is to do it! 1 Introduction
More informationProgramming Assignment #2
Programming Assignment #2 Due: 11:59pm, Wednesday, Feb. 13th Objective: This assignment will provide further practice with classes and objects, and deepen the understanding of basic OO programming. Task:
More informationCSC 172 Intermediate Progamming
CSC 172 Intermediate Progamming Lecture 2 A Review of Programming With Classes What Is A Class? A class is similar to a data type, except that the data items that it contains, the data types of which they
More informationAdministration. Exceptions. Leftovers. Agenda. When Things Go Wrong. Handling Errors. CS 99 Summer 2000 Michael Clarkson Lecture 11
Administration Exceptions CS 99 Summer 2000 Michael Clarkson Lecture 11 Lab 10 due tomorrow No lab tomorrow Work on final projects Remaining office hours Rick: today 2-3 Michael: Thursday 10-noon, Monday
More informationCMSC 132, Object-Oriented Programming II Summer Lecture 5:
CMSC 132, Object-Oriented Programming II Summer 2018 Lecturer: Anwar Mamat Lecture 5: Disclaimer: These notes may be distributed outside this class only with the permission of the Instructor. 5.1 Comparable
More information} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.
Class #10: Understanding Primitives and Assignments Software Design I (CS 120): M. Allen, 19 Sep. 18 Java Arithmetic } Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = 2 + 5 / 2; 3.
More informationBASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I
BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment
More informationTwo Types of Types. Primitive Types in Java. Using Primitive Variables. Class #07: Java Primitives. Integer types.
Class #07: Java Primitives Software Design I (CS 120): M. Allen, 13 Sep. 2018 Two Types of Types So far, we have mainly been dealing with objects, like DrawingGizmo, Window, Triangle, that are: 1. Specified
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 informationWrapper Classes double pi = new Double(3.14); 3 double pi = new Double("3.14"); 4... Zheng-Liang Lu Java Programming 290 / 321
Wrapper Classes To treat values as objects, Java supplies standard wrapper classes for each primitive type. For example, you can construct a wrapper object from a primitive value or from a string representation
More informationVariables, Data Types, and Arithmetic Expressions Learning Objectives:
Variables, Data Types, and Arithmetic Expressions Learning Objectives: Printing more than one variable in one printf() Printing formatting characters in printf Declaring and initializing variables A couple
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 informationCSC-140 Assignment 4
CSC-140 Assignment 4 Please do not Google a solution to these problem, cause that won t teach you anything about programming - the only way to get good at it, and understand it, is to do it! 1 Introduction
More informationTOP-DOWN PROCEDURAL PROGRAMMING
TOP-DOWN PROCEDURAL PROGRAMMING Top-down programming is an incremental strategy where you implement the most general modules first and work towards implementing those that provide specific functionality.
More informationTiming for Interfaces and Abstract Classes
Timing for Interfaces and Abstract Classes Consider using abstract classes if you want to: share code among several closely related classes declare non-static or non-final fields Consider using interfaces
More informationUNIT TESTING. Krysta Yousoufian CSE 331 Section April 19, With material from Marty Stepp, David Notkin, and The Pragmatic Programmer
UNIT TESTING Krysta Yousoufian CSE 331 Section April 19, 2012 With material from Marty Stepp, David Notkin, and The Pragmatic Programmer JUnit Semantics How to write a technically correct JUnit test A
More informationTips from the experts: How to waste a lot of time on this assignment
Com S 227 Spring 2018 Assignment 1 100 points Due Date: Friday, September 14, 11:59 pm (midnight) Late deadline (25% penalty): Monday, September 17, 11:59 pm General information This assignment is to be
More informationCOMP 250 Winter 2011 Reading: Java background January 5, 2011
Almost all of you have taken COMP 202 or equivalent, so I am assuming that you are familiar with the basic techniques and definitions of Java covered in that course. Those of you who have not taken a COMP
More informationCIS 190: C/C++ Programming. Classes in C++
CIS 190: C/C++ Programming Classes in C++ Outline Header Protection Functions in C++ Procedural Programming vs OOP Classes Access Constructors Headers in C++ done same way as in C including user.h files:
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 informationCOSC 1010 Introduction to Computer Programming
COSC 1010 Introduction to Computer Programming Exam 1, Spring 2016 Exam Duration: Sixty (60) Minutes The exam has three parts: Multiple Choice (17 points), Short Answer (30 points) and Programming (53
More informationCSEN 202: Introduction to Computer Programming Spring term Final Exam
Page 0 German University in Cairo May 28, 2016 Media Engineering and Technology Prof. Dr. Slim Abdennadher Dr. Wael Aboul Saadat CSEN 202: Introduction to Computer Programming Spring term 2015-2016 Final
More information09/08/2017 CS2530 INTERMEDIATE COMPUTING 9/8/2017 FALL 2017 MICHAEL J. HOLMES UNIVERSITY OF NORTHERN IOWA TODAY S TOPIC: Exceptions and enumerations.
CS2530 INTERMEDIATE COMPUTING 9/8/2017 FALL 2017 MICHAEL J. HOLMES UNIVERSITY OF NORTHERN IOWA TODAY S TOPIC: Exceptions and enumerations. 1 RUNTIME ERRORS All of us have experienced syntax errors. This
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 informationLab Assignment Three
Lab Assignment Three C212/A592 Fall Semester 2010 Due in OnCourse by Friday, September 17, 11:55pm (Dropbox will stay open until Saturday, September 18, 11:55pm) Abstract Read and solve the problems below.
More informationName Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?
1. Overriding Methods A subclass can modify behavior inherited from a parent class. A subclass can create a method with different functionality than the parent s method but with the same: Name Return type
More informationScheduling. Scheduling Tasks At Creation Time CHAPTER
CHAPTER 13 This chapter explains the scheduling choices available when creating tasks and when scheduling tasks that have already been created. Tasks At Creation Time The tasks that have the scheduling
More informationAnnouncements. 1. Forms to return today after class:
Announcements Handouts (3) to pick up 1. Forms to return today after class: Pretest (take during class later) Laptop information form (fill out during class later) Academic honesty form (must sign) 2.
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 informationAbstract Data Types. Different Views of Data:
Abstract Data Types Representing information is fundamental to computer science. The primary purpose of most computer programs is not to perform calculations, but to store and efficiently retrieve information.
More informationChapter 1 Getting Started
Chapter 1 Getting Started The C# class Just like all object oriented programming languages, C# supports the concept of a class. A class is a little like a data structure in that it aggregates different
More informationEnumerated Types. CSE 114, Computer Science 1 Stony Brook University
Enumerated Types CSE 114, Computer Science 1 Stony Brook University http://www.cs.stonybrook.edu/~cse114 1 Enumerated Types An enumerated type defines a list of enumerated values Each value is an identifier
More informationTopic 4 Expressions and variables
Topic 4 Expressions and variables "Once a person has understood the way variables are used in programming, he has understood the quintessence of programming." -Professor Edsger W. Dijkstra Based on slides
More informationAPCS 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 informationProgramming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur
Programming in C++ Prof. Partha Pratim Das Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 31 Static Members Welcome to Module 16 of Programming in C++.
More informationTopic 5: Enumerated Types and Switch Statements
Topic 5: Enumerated Types and Switch Statements Reading: JBD Sections 6.1, 6.2, 3.9 1 What's wrong with this code? if (pressure > 85.0) excesspressure = pressure - 85.0; else safetymargin = 85.0 - pressure;!
More informationCOP 3330 Final Exam Review
COP 3330 Final Exam Review I. The Basics (Chapters 2, 5, 6) a. comments b. identifiers, reserved words c. white space d. compilers vs. interpreters e. syntax, semantics f. errors i. syntax ii. run-time
More informationMIT AITI Python Software Development
MIT AITI Python Software Development PYTHON L02: In this lab we practice all that we have learned on variables (lack of types), naming conventions, numeric types and coercion, strings, booleans, operator
More informationClaremont McKenna College Computer Science
Claremont McKenna College Computer Science CS 51 Handout 4: Problem Set 4 February 10, 2011 This problem set is due 11:50pm on Wednesday, February 16. As usual, you may hand in yours until I make my solutions
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 informationGetting started with Java
Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving
More informationCS 116. Lab Assignment # 1 1
Points: 2 Submission CS 116 Lab Assignment # 1 1 o Deadline: Friday 02/05 11:59 PM o Submit on Blackboard under assignment Lab1. Please make sure that you click the Submit button and not just Save. Late
More informationB2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA
B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions. 2. PART ONE
More informationCloning Enums. Cloning and Enums BIU OOP
Table of contents 1 Cloning 2 Integer representation Object representation Java Enum Cloning Objective We have an object and we need to make a copy of it. We need to choose if we want a shallow copy or
More informationCSE 113 A. Announcements - Lab
CSE 113 A February 21-25, 2011 Announcements - Lab Lab 1, 2, 3, 4; Practice Assignment 1, 2, 3, 4 grades are available in Web-CAT look under Results -> Past Results and if looking for Lab 1, make sure
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 informationControls Structure for Repetition
Controls Structure for Repetition So far we have looked at the if statement, a control structure that allows us to execute different pieces of code based on certain conditions. However, the true power
More informationCONDITIONAL EXECUTION: PART 2
CONDITIONAL EXECUTION: PART 2 yes x > y? no max = x; max = y; logical AND logical OR logical NOT &&! Fundamentals of Computer Science I Outline Review: The if-else statement The switch statement A look
More informationCSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:
CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Tuesday 10:00 AM 12:00 PM * Wednesday 4:00 PM 5:00 PM Friday 11:00 AM 12:00 PM OR
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 informationCSC System Development with Java. Exception Handling. Department of Statistics and Computer Science. Budditha Hettige
CSC 308 2.0 System Development with Java Exception Handling Department of Statistics and Computer Science 1 2 Errors Errors can be categorized as several ways; Syntax Errors Logical Errors Runtime Errors
More informationOther conditional and loop constructs. Fundamentals of Computer Science Keith Vertanen
Other conditional and loop constructs Fundamentals of Computer Science Keith Vertanen Overview Current loop constructs: for, while, do-while New loop constructs Get out of loop early: break Skip rest of
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 informationCS 113 PRACTICE FINAL
CS 113 PRACTICE FINAL There are 13 questions on this test. The value of each question is: 1-10 multiple choice (4 pt) 11-13 coding problems (20 pt) You may get partial credit for questions 11-13. If you
More informationIf you don t, it will return the same thing as == But this may not be what you want... Several different kinds of equality to consider:
CS61B Summer 2006 Instructor: Erin Korber Lecture 5, 3 July Reading for tomorrow: Chs. 7 and 8 1 Comparing Objects Every class has an equals method, whether you write one or not. If you don t, it will
More informationAQA Decision 1 Algorithms. Section 1: Communicating an algorithm
AQA Decision 1 Algorithms Section 1: Communicating an algorithm Notes and Examples These notes contain subsections on Flow charts Pseudo code Loops in algorithms Programs for the TI-83 graphical calculator
More informationCompiler Design Spring 2017
Compiler Design Spring 2017 Patterns (again) Dr. Zoltán Majó Compiler Group Java HotSpot Virtual Machine Oracle Corporation Why? Remember questionnaire (from the beginning of the semester)? Question 7:
More informationAdvanced Java Concepts Unit 3: Stacks and Queues
Advanced Java Concepts Unit 3: Stacks and Queues Stacks are linear collections in which access is completely restricted to just one end, called the top. Stacks adhere to a last-in, first-out protocol (LIFO).
More informationHW3: CS 110X C Domain Information. Final Version: 1/29/2014
HW3: CS 110X C 2014 Note: This homework (and all remaining homework assignments) is a partner homework and must be completed by each partner pair. When you complete this assignment, you must not share
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 informationOperator overloading: extra examples
Operator overloading: extra examples CS319: Scientific Computing (with C++) Niall Madden Week 8: some extra examples, to supplement what was covered in class 1 Eg 1: Points in the (x, y)-plane Overloading
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 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 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 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 informationClasses Classes 2 / 35
Classes 1 / 35 Classes Classes 2 / 35 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 informationLesson 10A OOP Fundamentals. By John B. Owen All rights reserved 2011, revised 2014
Lesson 10A OOP Fundamentals By John B. Owen All rights reserved 2011, revised 2014 Table of Contents Objectives Definition Pointers vs containers Object vs primitives Constructors Methods Object class
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 informationExample. Section: PS 709 Examples of Calculations of Reduced Hours of Work Last Revised: February 2017 Last Reviewed: February 2017 Next Review:
Following are three examples of calculations for MCP employees (undefined hours of work) and three examples for MCP office employees. Examples use the data from the table below. For your calculations use
More informationOptions 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 informationOperational Semantics. One-Slide Summary. Lecture Outline
Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:
More informationACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1
ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1 Due to CMS by Tuesday, February 14. Social networking has caused a return of the dot-com madness. You want in on the easy money, so you have decided to make
More informationLetterkenny Institute of Technology
Letterkenny Institute of Technology Course Code: OOPR K6A02 BACHELOR OF SCIENCE IN COMPUTING WITH BUSINESS APPLICATIONS MULTIMEDIA AND DIGITAL ENTERTAINMENT COMPUTER SECURITY & DIGITAL FORENSICS COMPUTER
More informationJAVA OPERATORS GENERAL
JAVA OPERATORS GENERAL Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups: Arithmetic Operators Relational Operators Bitwise Operators
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 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 informationCSC 240 Computer Science III Spring 2018 Midterm Exam. Name
CSC 240 Computer Science III Spring 2018 Midterm Exam Name Page Points Score 2 9 4-6 53 7-10 38 Total 100 1 P age 1. Tracing programs (1 point each value): For each snippet of Java code on the left, write
More informationCISC-124. Dog.java looks like this. I have added some explanatory comments in the code, and more explanation after the code listing.
CISC-124 20180115 20180116 20180118 We continued our introductory exploration of Java and object-oriented programming by looking at a program that uses two classes. We created a Java file Dog.java and
More informationInheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L
Inheritance Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 9.4 1 Inheritance Inheritance allows a software developer to derive
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 informationMichele Van Dyne Museum 204B CSCI 136: Fundamentals of Computer Science II, Spring
Michele Van Dyne Museum 204B mvandyne@mtech.edu http://katie.mtech.edu/classes/csci136 CSCI 136: Fundamentals of Computer Science II, Spring 2016 1 Review of Java Basics Data Types Arrays NEW: multidimensional
More informationCIS 162 Project 4 Farkle (a dice game)
CIS 162 Project 4 Farkle (a dice game) Due Date at the start of class on Monday, 3 December (be prepared for quick demo and zybook test) Before Starting the Project Read chapter 10 (ArrayList) and 13 (arrays)
More informationRead and fill in this page now. Your lab section day and time: Name of the person sitting to your left: Name of the person sitting to your right:
CS3 Fall 04 Midterm 1 Read and fill in this page now Your name: Your login name: Your lab section day and time: Your lab T.A.: Name of the person sitting to your left: Name of the person sitting to your
More informationJava Identifiers, Data Types & Variables
Java Identifiers, Data Types & Variables 1. Java Identifiers: Identifiers are name given to a class, variable or a method. public class TestingShastra { //TestingShastra is an identifier for class char
More informationProgramming Language Concepts: Lecture 2
Programming Language Concepts: Lecture 2 Madhavan Mukund Chennai Mathematical Institute madhavan@cmi.ac.in http://www.cmi.ac.in/~madhavan/courses/pl2009 PLC 2009, Lecture 2, 19 January 2009 Classes and
More informationJava Foundations. 7-2 Instantiating Objects. Copyright 2015, Oracle and/or its affiliates. All rights reserved.
Java Foundations 7-2 Copyright 2015, Oracle and/or its affiliates. All rights reserved. Objectives This lesson covers the following objectives: Understand the memory consequences of instantiating objects
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 26 March 23, 2016 Inheritance and Dynamic Dispatch Chapter 24 Inheritance Example public class { private int x; public () { x = 0; } public void incby(int
More informationCSE 351: The Hardware/Software Interface. Section 2 Integer representations, two s complement, and bitwise operators
CSE 351: The Hardware/Software Interface Section 2 Integer representations, two s complement, and bitwise operators Integer representations In addition to decimal notation, it s important to be able to
More informationEquality for Abstract Data Types
Object-Oriented Design Lecture 4 CSU 370 Fall 2008 (Pucella) Tuesday, Sep 23, 2008 Equality for Abstract Data Types Every language has mechanisms for comparing values for equality, but it is often not
More informationif Statement Numeric Rela5onal Operators The if Statement Flow of Control: Branching (Savitch, Chapter 3)
if Statement Flow of Control: Branching (Savitch, Chapter 3) TOPICS Conditional Execution if and Statement Boolean Data switch Statement Ensures that a statement is executed only when some condi5on is
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 informationProgramming Language. Control Structures: Selection (switch) Eng. Anis Nazer First Semester
Programming Language Control Structures: Selection (switch) Eng. Anis Nazer First Semester 2018-2019 Multiple selection choose one of two things if/else choose one from many things multiple selection using
More informationif Statement Numeric Rela7onal Operators The if Statement Flow of Control: Branching (Savitch, Chapter 3)
if Statement Flow of Control: Branching (Savitch, Chapter 3) TOPICS Conditional Execution if,, and if boolean data switch statements CS 160, Fall Semester 2015 1 Programs o-en contain statements that may
More informationCSCI-1200 Data Structures Fall 2018 Lecture 3 Classes I
Review from Lecture 2 CSCI-1200 Data Structures Fall 2018 Lecture 3 Classes I Vectors are dynamically-sized arrays Vectors, strings and other containers should be: passed by reference when they are to
More informationProgramming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras
Programming Data Structures and Algorithms Prof. Shankar Balachandran Department of Computer Science Indian Institute of Technology, Madras Module 12B Lecture - 41 Brief introduction to C++ Hello, welcome
More informationHelping You C What You Can Do with SAS
ABSTRACT Paper SAS1747-2015 Helping You C What You Can Do with SAS Andrew Henrick, Donald Erdman, and Karen Croft, SAS Institute Inc., Cary, NC SAS users are already familiar with the FCMP procedure and
More informationCSCE 156 Computer Science II
CSCE 156 Computer Science II Lab 04 - Classes & Constructors Dr. Chris Bourke Prior to Lab 1. Review this laboratory handout prior to lab. 2. Read Object Creation tutorial: http://download.oracle.com/javase/tutorial/java/javaoo/objectcreation.
More informationSample First Midterm Exam The Answers
CSc 227 Program Design and Development (McCann) Sample First Midterm Exam The Answers Background and Advice Former students have suggested that their performance on the first midterm exam of a class would
More information