76 Pages

Clas4_Java_1

Course: CS 445, Fall 2009
School: Illinois Tech
Rating:
 
 
 
 
 

Word Count: 3689

Document Preview

Java CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Topics Class Basics and Benefits Creating Objects Using Constructors Calling Methods Using Object References Calling Static Methods and Using Static Class Variables Using Predefined Java Classes CS445 <a href="/keyword/object-oriented-design/"...

Register Now

Unformatted Document Excerpt

Coursehero >> Illinois >> Illinois Tech >> CS 445

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
Java CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Topics Class Basics and Benefits Creating Objects Using Constructors Calling Methods Using Object References Calling Static Methods and Using Static Class Variables Using Predefined Java Classes CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Object-Oriented Programming Classes combine data and the methods (code) to manipulate the data Classes are a template used to create specific objects All Java programs consist of at least one class. Two types of classes Application/Applet classes Service classes CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Class Data Instance variables: variables defined in the class and given values in the object Fields: instance variables and static variables (we'll define static later) Members of a class: the class's fields and methods Fields can be: any primitive data type (int, double, etc.) objects CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Encapsulation Instance variables are usually declared to be private, which means users of the class must reference the data of an object by calling methods of the class. Thus the methods provide a protective shell around the data. We call this encapsulation. Benefit: the class methods can ensure that the object data is always valid. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Naming Conventions Class names: start with a Capital letter Object references: start with a lowercase letter In both cases, internal words start with a capital letter Example: class: Student objects: student1, student2 CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Declare an Object Reference Syntax: ClassName objectReference; or ClassName objectRef1, objectRef2...; Object reference holds address of object Example: Date d1; CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Instantiate an Object Objects MUST be instantiated before they can be used Call a constructor using new keyword Constructor has same name as class. Syntax: objectReference = new ClassName( arg list ); Arg list (argument list) is comma-separated list of initial values to assign to object data CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming The Argument List in an API Pairs of dataType variableName Specify Order of arguments Data type of each argument Arguments can be: Any expression that evaluates to the specified data type CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Void Methods Void method Does not return a value System.out.print(&quot;Hello&quot;); System.out.println(&quot;Good bye&quot;); name.setName(&quot;CS&quot;, &quot;201&quot;); object method arguments CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Value-Returning Methods Value-returning method Returns a value to the calling program String first; String last; Name name; System.out.print(&quot;Enter first name: &quot;); first = inData.readLine(); System.out.print(&quot;Enter last name: &quot;); last = inData.readLine(); name.setName(first, last); CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Value-returning example public String firstLastFormat() { return first + &quot; &quot; + last; } System.out.print(name.firstLastFormat()); object method object method Argument to print method is string returned from firstLastFormat method CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Method Return Values Can be a primitive data type, class type, or void A value-returning method Return value is not void The method call is used in an expression. When the expression is evaluated, the return value of the method replaces the method call. Have no value Method call is complete statement (ends with ;) Methods with a void return type CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Dot Notation Use when calling method to specify which object's data to use in the method Syntax: objectReference.methodName( arg1, arg2, ... ) Note: no data types in method call; values only! CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Example Next Slide Example Methods.java public class Methods { public static void main( String [] args ) { Date independenceDay = new Date( 7, 4, 1776 ); int independenceMonth = independenceDay.getMonth( ); System.out.println( &quot;Independence day is in month &quot; + independenceMonth ); Date graduationDate = new Date( 5, 15, 2008 ); System.out.println( &quot;The current day for graduation is &quot; + graduationDate.getDay( ) ); graduationDate.setDay( 12 ); System.out.println( &quot;The revised day for graduation is &quot; + graduationDate.getDay( ) ); } } CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Object Reference vs. Object Data Object references point to the location of object data. An object can have multiple object references pointing to it. Or an object can have no object references pointing to it. If so, the garbage collector will free the object's memory Example Next Slide See CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Example ObjectReferenceAssignment.java public class ObjectReferenceAssignment { public static void main( String [] args ) { Date hireDate = new Date( 2, 15, 2003 ); System.out.println( &quot;hireDate is &quot; + hireDate.getMonth( ) + &quot;/&quot; + hireDate.getDay( ) + &quot;/&quot; + hireDate.getYear( ) ); Date promotionDate = new Date( 9, 28, 2004 ); System.out.println( &quot;promotionDate is &quot; + promotionDate.getMonth( ) + &quot;/&quot; + promotionDate.getDay( ) + &quot;/&quot; + promotionDate.getYear( ) ); promotionDate = hireDate; System.out.println( &quot;\nAfter assigning hireDate &quot; + &quot;to promotionDate:&quot; ); System.out.println( &quot;hireDate is &quot; + hireDate.getMonth( ) + &quot;/&quot; + hireDate.getDay( ) + &quot;/&quot; + hireDate.getYear( ) ); System.out.println( &quot;promotionDate is &quot; + promotionDate.getMonth( ) + &quot;/&quot; + promotionDate.getDay( ) + &quot;/&quot; + promotionDate.getYear( ) ); } } CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Two References to an Object After the example runs, two object references point to the same object CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming null Object References An object reference can point to no object. In that case, the object reference has the value null Object references have the value null when they have been declared, but have not been used to instantiate an object. Attempting to use a null object reference causes a NullPointerException at run time. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Example NullReference.java public class NullReference { public static void main( String[] args ) { Date aDate; aDate.setMonth( 5 ); } } CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Example NullReference2.java public class NullReference2 { public static void main( String[] args ) { Date independenceDay = new Date( 7, 4, 1776 ); System.out.println( &quot;The month of independenceDay is &quot; + independenceDay.getMonth( ) ); independenceDay = null; // attempt to use object reference System.out.println( &quot;The month of independenceDay is &quot; + independenceDay.getMonth( ) ); } } CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Date.java Class import java.awt.Graphics; public class Date { private int month; private int day; private int year; public Date( ) { setDate( 1, 1, 2000 ); } public Date( int mm, int dd, int yyyy ) { setDate( mm, dd, yyyy ); } /* accessor methods */ int getMonth( ) { return month; } int getDay( ) { return day; } int getYear( ) { return year; } /** mutator method */ public void setMonth( int mm ) { month = ( mm &gt;= 1 &amp;&amp; mm &lt;= 12 ? mm : 1 ); } CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Date.java Class public void setDay( int dd ) { int [] validDays = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; day = ( dd &gt;= 1 &amp;&amp; dd &lt;= validDays[month] ? dd : 1 ); } public void setYear( int yyyy ) { year = yyyy; } public void setDate( int mm, int dd, int yyyy ) { setMonth( mm ); setDay( dd ); setYear(yyyy); } public String toString( ) {return month + &quot;/&quot; + day + &quot;/&quot; + year; } public boolean equals( Date d ) { if ( month == d.month &amp;&amp; day == d.day Comparing Objects &amp;&amp; year == d.year ) return true; else return false; } } CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Co n ve rti n g an O bj to St rin g ec t static Methods Also called class methods Can be called without instantiating an object Might provide some quick, one-time functionality, for example, popping up a dialog box In method API, keyword static precedes return type static dataType mthodName (arg1,ard2,...); CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Calling static Methods Use dot syntax with class name instead of object reference Syntax: ClassName.methodName( args ) Example: int absValue = Math.abs( -9 ); Uses of class methods Provide access to class variables without using an object CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming static Class Variables Syntax: ClassName.staticVariable Example: Color.BLUE BLUE is a static constant of the Color class. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Static Class Variables and Static Methods class Counter { private int value; private static int numCounters = 0; public Counter() { value = 0; numCounters++; } public static int getNumCounters() { return numCounters; } } ... System.out.println(&quot;Number of counters: &quot; + Counter.getNumCounters()); CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Static vs. Instance Variable Class (static) vs. instance variables Instance variable: each instance has its own copy Class variable: the class has one copy for all instances In instance methods only In instance methods In class methods Can use instance variables Can use class variables CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Topics Defining a Class Defining Instance Variables Writing Methods The Object Reference this The toString and equals Methods static Members of a Class Creating Packages CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Why User-Defined Classes? Primitive data types (int, double, char, .. ) are great ... ... but in the real world, we deal with more complex objects: products, Web sites, flight records, employees, students, .. Object-oriented programming enables us to manipulate real-world objects. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming User-Defined Classes Combine data and the methods that operate on the data Advantages: Class is responsible for the validity of the data. Implementation details can be hidden. Class can be reused. A program that instantiates objects and calls methods of the class Client of a class CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Syntax for Defining a Class accessModifier class ClassName { // class definition goes here } CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Software Engineering Tip Use a noun for the class name. Begin the class name with a capital letter. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Important Terminology Fields instance variables: data for each object class data: static data that all objects share fields and methods determines access rights for the class and its members defines where the class and its members can be used Members Access Modifier CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Access Modifiers Access Modifier public private protected Class or member can be referenced by... methods of the same class, and methods of other classes methods of the same class only methods of the same class, methods of subclasses, and methods of classes in the same package No access modifier methods in the same package (package access) only CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming public vs. private Classes are usually declared to be public Instance variables are usually declared to be private Methods that will be called by the client of the class are usually declared to be public Methods that will be called only by other methods of the class are usually declared to be private APIs of methods are published (made known) so that clients will know how to instantiate objects and call the methods of the class CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Defining Instance Variables Syntax: accessModifier dataType identifierList; dataType can be primitive date type or a class type identifierList can contain: one or more variable names of the same data type multiple variable names separated by commas initial values Optionally, instance variables can be declared as final CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Examples of Instance Variable Definitions private String name = &quot;&quot;; private final int PERFECT_SCORE = 100, PASSING_SCORE = 60; private int startX, startY, width, height; CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Software Engineering Tips Define instance variables for the data that all objects will have in common. Define instance variables as private so that only the methods of the class will be able to set or change their values. Begin the identifier name with a lowercase letter and capitalize internal words. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming The Auto Class public class Auto { private String model; private int milesDriven; private double gallonsOfGas; } CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Syntax: Writing Methods accessModifier returnType methodName( parameter list ) // method header { // method body } parameter list is a comma-separated list data types and variable names. of To the client, these are arguments To the method, these are parameters Note that the method header is the method API. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Software Engineering Tips Use verbs for method names. Begin the method name with a lowercase letter and capitalize internal words. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Method Return Types The return type of a method is the data type of the value that the method returns to the caller. The return type can be any of Java's primitive data types, any class type, or void. Methods with a return type of void do not return a value to the caller. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Method Body The code that performs the method's function is written between the beginning and ending curly braces. Unlike if statements and loops, these curly braces are required, regardless of the number of statements in the method body. In the method body, a method can declare variables, call other methods, and use any of the program structures we've discussed, such as if/else statements, while loops, for loops, switch statements, and do/while loops. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming main is a Method public static void main( String [] args ) { // application code } Let's look at main's API in detail: public main can be called from outside the class. (The JVM calls main.) static main can be called by the JVM without instantiating an object. void main does not return a value String [] args main's parameter is a String array CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Value-Returning Methods Use a return statement to return the value Syntax: return expression; CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Constructors Special methods that are called when an object is instantiated using the new keyword. A class can have several constructors. The job of the class constructors is to initialize the instance variables of the new object. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Defining a Constructor Syntax: public ClassName( parameter list ) { // constructor body } Note: no return value, not even void! Each constructor must have a different number of parameters or parameters of different types Default constructor: a constructor that takes no arguments. See Examples 7.1 and 7.2, Auto.java and AutoClient.java CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming If the constructor does not assign values to the instance variables, they are auto-assigned default values depending on the instance variable data type. Data Type byte, short, int, long float, double char boolean Any object reference (for example, a String) Default Value 0 0.0 space false null Default Initial Values CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Common Error Trap Do not specify a return value for a constructor (not even void). Doing so will cause a compiler error in the client program when the client attempts to instantiate an object of the class. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Class Scope Instance variables have class scope Any constructor or method of a class can directly refer to instance variables. Any method or constructor of a class can call any other method of a class (without using an object reference). Methods also have class scope CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Local Scope A method's parameters have local scope, meaning that: a method can directly access its parameters. a method's parameters cannot be accessed by other methods. A method can define local variables which also have local scope, meaning that: a method can access its local variables. a method's local variables cannot be accessed by other methods. CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Summary of Scope A method in a class can access: the instance variables of its class any parameters sent to the method any variable the method declares from the point of declaration until the end of the method or until the end of the block in which the variable is declared, whichever comes first any methods in the class CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Using Java Predefined Classes Java Packages The String Class Using System.out The Math Class The Wrapper Classes Dialog Boxes Console Input Using the Scanner Class CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Java Predefined Classes Included in the Java SDK are more than 2,000 classes that can be used to add functionality to our programs APIs for Java classes are published on Sun Microsystems Web site: http://www.java.sun.com CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Java Packages Package Classes are grouped in packages according to functionality Categories of Classes Basic functionality common to many programs, such as the String class and Math class Graphics classes for drawing and using colors java.lang java.awt javax.swing User-interface components java.text java.util Classes for formatting numeric output The Scanner class and other miscellaneous classes CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming Using a Class From a Package Classes in java.lang are automatically available to use Classes in other packages need to be &quot;imported&quot; using this syntax: import package.ClassName; or import package.*; Example import java.text.DecimalFormat; or import java.text.*; CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming The String Class Represents a sequence of characters String constructors: String( String str ) allocates a String object with the value of str, which can be String object or a String literal String( ) allocates an empty String CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming String Concatenation Operators + appends a String to another String. At least one operand must be a String += shortcut String concatenation operator CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming The length Method Return type int Method name and argument list length( ) returns the number of characters in the String Example: String hello = &quot;Hello&quot;; int len = hello.length( ); The value of len is 5 CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming The toUpperCase and toLowercase Methods Return type String Method name and argument list toUpperCase( ) returns a copy of the String will all letters uppercase toLowerCase( ) returns a copy of the String will all letters lowercase String Example: String hello = &quot;Hello&quot;; hello = hello.toUpperCase( ); The value of hello is &quot;HELLO&quot; CS445 <a href="/keyword/object-oriented-design/" >object oriented design</a> and Programming The indexOf Methods Return type int Method name and argument list indexOf( String searchString ) returns the index of the first character of searchString or -1 if not found indexOf( char searchChar ) returns the index of the first character of searchChar or -1 if not found int The index of the first character of a String is 0. Example: String hello = &quot;Hello&quot;; int index = hello.indexOf( 'e' ); The value of index is 1. CS445 <a href="/keyword/object-oriented-design/" >object oriented des...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

Illinois Tech - CS - 445
Java AppletsCS445ObjectOrientedDesignandProgrammingTopics Applet Structure Executing an Applet Applet Life Cycle Drawing Shapes with Graphics Methods Using Colors and Fonts Etc.CS445ObjectOrientedDesignandProgrammingAppletsExecute
Illinois Tech - CS - 445
Design and Implementation ConceptsCS445 Object Oriented Design and ProgrammingDesign Concepts Public and Helper Classes Ordering Class Members Class Organization Design Guidelines Javadoc Canonical Form of Classes No-arg Construct
Illinois Tech - CS - 480
CS-480 Logical Agents and InferenceAIMA, Chapter 7Outline Knowledge-based agents Wumpus world Logic in general - models and entailment Propositional (Boolean) logic Equivalence, validity, satisfiability Inference rules and theorem proving
Illinois Tech - CS - 441
Grading Criteria for Project Part-B FALL 2007NAMES: _Design:1. javadocs : authors and version variables all methods all classes 2. DESCRIPTIONS IN WORD DOCUMENT:Points: 4 1 1 1 1 1--Total 5Code and Presentation: FUNCTIONALITY/APPEARANCE1.
Illinois Tech - CS - 441
Grading Criteria for Project Part-B SPRING 2008NAMES: _Design:1. javadocs : authors and version variables all methods all classes 2. DESCRIPTIONS IN WORD DOCUMENT:Points: 4 1 1 1 1 1--Total 5Code and Presentation: FUNCTIONALITY/APPEARANCE1
Illinois Tech - CS - 201
CS201 In Class Assignment - Form groups of 3 or 4 students. Your group will be assigned an example implementation of the below problem (A, B or C). I have also emailed all three implementations to everyone. By the end of class today, have your group
Illinois Tech - CS - 201
CS201 EXAM 1 Fall 2007 NAME _ 1. (20 points) Write a java code segment that will determine if the digits of a user entered, threedigit number are all odd, all even, or mixed odd and even. You can assume the user enters an integer.
Illinois Tech - CS - 201
CS201INCLASSASSIGNMENTNAME_SomepracticeonRecursion Writerecursive methods forthefollowing: 1. Calculate thenth term inthefibonaccisequence 2. Find thelargest integer inan array and return itsindex 3. Doalinear search forakeyonan array ofintegers,
Illinois Tech - CS - 201
CS201Fall2007EXAM#3NAME_ 1)(25points)WriteaVehicleclassforatollbooth collection system (standard cartollof50centsfor automatic,$1formanual) with thefollowing: Necessary constants Instance variables fortheVehicle's o tolltype String,A forautomatic,M
Illinois Tech - CS - 201
CS201EXAM2Fall2007 NAME_ 1.(50points)Writeaprogram that plays aguessing game. Thegame willpickarandom number between 2 setvalues (alow limitand high limit)and prompt theuser toguess that number untilheorsheguesses correctly.On each wrong guess,thega
Illinois Tech - CS - 201
CS201INCLASSASSIGNMENTNAME_Designandimplemementaclassforastopwatch.Allowtheusertostart,stopandresetthestopwatchanddisplay (toString)thetimeinseconds. ExtraCredit:Display(toString)thetimeashh:mm:ssLimitthetimeyoucancountto24hours,thenrolloverto0ag
Illinois Tech - CS - 201
CS201INCLASSASSIGNMENTNAME_SomepracticeonInhertiance Suppose you wanted aclassthat would allow you touse fractions inaprogram (weareNOT reducing orsimplifying fractions).Remember avalid fraction isan integer over anonzero integer. Wewant both a
Illinois Tech - CS - 201
CS201 EXAM 2 MAKEUP Fall 2007 NAME _ 1. (50 points) Write a program that plays a guessing game. The game will pick a random number between 2 set values (a low limit and high limit) and prompt the user to guess that number until
Illinois Tech - CS - 201
CS201 PLACEMENT EXAM 45 MINUTES NAME _ 1. Please write code / pseudocode for two new functions for the &quot;ThreeIntMath &quot; class: &quot;polynomial&quot; that assumes the three integers x, y, z, for an object are the integer coefficients of a pol
Illinois Tech - CS - 115
CS 115 FALL 2007 Lab Problem #12 CD Compilation Part A, IndividualIndividually read the memo and article below.Internal Memo Brand New Sound Co. To: New Hire Engineering Team From: Billy Valens, Vice President of Marketing Re: Product Mixing Hel
Illinois Tech - CS - 441
SPRING 08 Project B Version 1You must answer the questions below which are worth 10 points. Every point you loose by not giving the correct answer gets subtracted from your grade for your project during your presentation. Question 1: In a a RMI dis
Illinois Tech - CS - 116
102726710 graduated104685526 graduated105708840 inactive106703604 inactive108788932 inactive110724715 graduated112482628 inactive-n113740426 graduated115863141 graduated116729274 inactive117669891 graduated118703144 inactive118726395 inac
Illinois Tech - CS - 116
IIT - CS116 Lab 0file:/C|/Bauer/CS116/www/labs/Lab0/Lab0.htmCS 116 - Lab 0 Objectives:1. 2. 3. 4. 5. 6.Tasks:Enter, compile, and run simple Java programs without using an IDE. (the standard &quot;Hello World!&quot; first program). Recognize syntax err
Illinois Tech - CS - 116
Encapsulation &amp; Selection1EncapsulationClass implementation details are hidden from the programmer who uses the class. This is called encapsulation Public methods of a class provide the interface between the application code and the class object
Illinois Tech - CS - 116
Chapter 9 TopicsAtomic Data Types q Composite Data Types q One-Dimensional Arrays q Examples of Declaring and Processing Arrays q Arrays of Objects q Arrays and Methods q Special Kinds of Array Processingq1Java Primitive Data Typesprimitivein
Illinois Tech - CS - 116
Chapter 10 Inheritance, Polymorphism, and Scope1Chapter 10 Topicsq qq q q q q qInheritance Inheritance and the Object-Oriented Design Process How to Read a Class Hierarchy Derived Class Syntax Scope of Access Implementing a Derived Class Copy
Illinois Tech - CS - 116
Chapter 11 Array-Based Lists1Chapter 11 Topicsqq q q qq qInsertion into and Deletion from an Unordered List Straight Selection Sort Insertion into and Deletion from a Sorted List Abstract classes Searching s Sequential s Binary Complexity o
Illinois Tech - CS - 116
q Chapter q Writing7.8 - Exceptionsto a File Complexityq Algorithmic1ExceptionsqIllegal operations at run time can generate an exception, for example:s ArrayIndexOutOfBoundsException s ArithmeticException s NullPointerException s InputM
Illinois Tech - CS - 116
Chapter 8 Object-OrientedSoftware Design and Implementation TopicsSoftware Design Strategies q Objects and Classes Revisited q Object-Oriented Design q The CRC Card Design Process q Functional Decomposition q Object-Oriented Implementationq1So
Illinois Tech - CS - 116
1.(5 points) Understand and correct Java compile errors and runtime errors (conditions and iteration). Programming and Problem Solving with Java, Page 271, #10if (Math.abs(x2-x1)&lt;.00001) System.out.println(&quot;Slope undefined&quot;);else { m=(y2-y1)/(
Illinois Tech - CS - 116
1. (10 points) Determine the time complexity of simple algorithms. PREDICTED WHYSELECTION SORT n^2 2 nested loopsRANDOM inner loop n, n-1, n-2, n-3, etc n+(n-1)+(n-2)+. =
Illinois Tech - CS - 116
1.(6 points) Explain the basics of the concept of recursion. 1. (A) The number of elements in arr that are less than num 2. (D) 43211234 3. (D) 2432.(14 points) Design/Code an object for a multi-object application containing inheritance.
Illinois Tech - CS - 116
0.0178173520.0240969550.0482115620.0697062060.0787579870.0821025160.0851559690.0887409080.094427750.1313963520.133466550.1475134060.1476946620.1611041470.1623873830.1654102610.1658394070.1789697390.1838542270.1955364310.210542828
Illinois Tech - CS - 116
1. (20 points) Design a user-defined object containing an array. (CONTINUATION OF LAB 2,5,6)There is ALOT of flexibility on student answers on this one.Key idea is how they are protecting the cases from EVERYONE until you open a case.public cla
Illinois Tech - CS - 116
CS 116 SPRING 2008 , SECS. 3-6 LAB #10 ARRAYLIST SOLUTIONExercise #1 = #4: See ExerciseApp in suggested coded solution. Solution: I took a List class and derived a UserList class and overrode some methods. Most students will just create a UserLis
Illinois Tech - CS - 116
CS 116 SPRING 2008 , SECS. 3-6 LAB #5 ARRAYS SOLUTION Homework: Programming &amp; Problem Solving with Java,2nd Ed, Dale &amp; Weems: p. 518: #1, #2, #3 Exercise #1: See coded solution. Exercise #2: See coded solution. Write the pseudocode to solve this pr
Illinois Tech - CS - 116
CS 116 SPRING 2008 , SECS. 3-6 LAB #3 SELECTION + DEBUG SOLUTIONHomework: Programming &amp; Problem Solving with Java,2nd Ed, Dale &amp; Weems: (1 point) p. 270: #6, 9, 10, 116.if (year % 4 = 0) System.out.print(year + &quot; is a leap year.&quot;); else { year
Illinois Tech - CS - 116
CS 116 SPRING 2008 , SECS. 3-6 LAB #9 POLYMORPHISM Objective 1. 2. 3. 4.To learn to use polymorphism. To learn to read and handle an input file with two input formats. To learn to use an Abstract class. To learn the difference between private and
Illinois Tech - CS - 116
CS 116SPRING 2008 WEEKLY LAB PROBLEM #11 SEARCHING AND SORTING AN ARRAY LIST SOLUTION Ex. #1: See exercises package. Test valuepluShort.txtSearch result before selection sort:found 3016 at: 56 found 3082 at: 28 found 3251 at: -1 found 3161 at: 48
Illinois Tech - CS - 116
CS 116 SPRING 2008 , SECS. 3-6 LAB #2 USER-DEFINED CLASS + APPLICATION Objective: 1. Learn to write java arithmetic expressions. 2. Learn to use explicit casting. 3. Learn to use static methods from the Math API 4. Learn to use precedence of operat
Illinois Tech - CS - 116
CS 116 SPRING 2008, Sec. 3-6 LAB #1 USER-DEFINED CLASS WITH STATIC METHODS SOLUTION Homework: p. 100, #15: (1 point)This program may be corrected in several ways. Here is one correct version: public class LotsOfErrors { public static void main(Stri
Illinois Tech - CS - 116
CS 116SPRING 2007 WEEKLY LAB PROBLEM #8A ID ARRAY LIST Object: To learn how to implement an array list of objects Problem: The philanthropic organization would like to be able to have non-technical personnel manipulate the data stored in the data st
Illinois Tech - CS - 116
CS 116 SPRING 2008 , SECS. 3-6 LAB #8 INHERITANCE, COMPOSITION SOLUTIONExercise #1:Rectangle: length: 4 width: 5 area 20 perimeter: 18 Box: length: 8 width: 6 area 48 perimeter: 28 depth: 4 volume: 192Exercise #2:Length: 8 Width: 6 Width: 12
Illinois Tech - CS - 116
CS 116 SPRING 2008 , SECS. 3-6 LAB #4 ITERATION, FILE I/O SOLUTIONHomework: Programming &amp; Problem Solving with Java,2nd Ed, Dale &amp; Weems: p. 333: #2, 3, 5, 8, 10, 11 Grade #2, 5, 10 1 point apiece2. while ( ! dangerous ) { pressure = datain.nex
Illinois Tech - CS - 116
CS 116SPRING 2008 WEEKLY LAB PROBLEM #11 SEARCHING AND SORTING AN ARRAY LIST Objective: 1. To start coding your final project. 2. To search an array of objects using sequential search. 3. To sort an array of objects using selection sort. 4. To search
Illinois Tech - CS - 116
CS 116 SPRING 2008 , SECS. 3-6 LAB #9 POLYMORPHISM SOLUTION Exercise #1: See ex1_4 Exercise #2: See ex1_4 Exercise #3: See ex1_4. Be sure student have called the correct calcArea() method using polymorphism. Exercise #4: See ex 1_4. Be sure the stu
Illinois Tech - CS - 116
CS 116 SPRING 2008 , SECS. 3-6 LAB #4 ITERATION, FILE I/OObjective: 1. To learn to use iteration to solve a problem. 2. To learn to read and process data from a file. 3. To learn to merge two files. 4. To learn to use nested loops. Homework: Prog
Illinois Tech - CS - 115
Poor:12/40The end product doesn't work at all. They missed key points on the assignment (such as drawing up an API)Also, most of their group did not show up to the second session.Average:30/40The end product has major problems, and some o
Illinois Tech - CS - 115
/* # * cs115 * section3 * homework 2 * 7th September 2007 */package homework2; public class Homework { /* * @param args */ public static void main(String[] args) { / TODO Auto-generated method stub/ System.out.println(&quot;my name is #&quot;); System.out.prin
Illinois Tech - CS - 115
Find a set of instructions for operating an appliance that requires you to set the date and time, such as a DVD player, microwave oven, clock radio, or a computer. Identify the obvious objects in the instructions. Then identify which portions of this
Illinois Tech - CS - 115
08/31/2007 HOMEWORK CS115004*2.Find a set of instructions for operating an appliance that requires you to set the date and time, such as a DVD player, kitchen oven, clock radio, or a computer, identify the obvious objects in the instructions. The
Illinois Tech - CS - 115
/* * # * cs115 sec007 * Lab2 */ package lab2; public class CrissCross { public static void main(String[] args) { char star = '*'; char space = ' '; String string1 = &quot; * String string2 = &quot;* * * * * * * * &quot;; *&quot;;System.out.println(string2); System.out
Illinois Tech - CS - 115
public class JackBanner { /* * @param args */ public static void main(String[] args) { String jack0 = (&quot;Black Jack&quot;); String jack1 = (&quot;#&quot;); char someone = 'j'; String jays = &quot;j j j j j j j&quot;; &quot; &quot; &quot; &quot; System.out.println(jack0+&quot; &quot;+jack0+&quot; &quot;+jack0+&quot; &quot;+ja
Illinois Tech - CS - 115
package Collection; public class cds { private String artiste; private int numCds; / default constructor public cds() { artiste=&quot;Taylor Swift&quot;; numCds=1; } /constructor public cds(String newArtiste, int newNumCds) { artiste = newArtiste; numCds = new
Illinois Tech - CS - 115
No example poor lab for Lab 1 currently exists. None of the students that produced poor labs submitted them to blackboard's digital dropbox.?/15The Homework is poor; it is from the S.Pasari, and is poor because it does not go into detail, or eve
Illinois Tech - CS - 115
The lab is from L. Xu, and it is poor because it completed the spirit of the assignment, while ignoring most of the rules. It had no string of spaces, and each line did not relate to the others. It was more like someone had just started throwing word
Illinois Tech - CS - 331
2 JUNITCS 331 Lab 2: JUnit and Array Lists Spring 20081 IntroductionThe title of this lab is Array List, but is really about JUnit, the testing framework we will be using in this course.1.1ObjectivesYour objective is to become familiar with
Illinois Tech - CS - 331
Linked Lists3 YOUR WORKCS 331 Lab 3: Linked Lists Spring 20081 IntroductionIn this lab you will code some of the basic functions for a singly linked list, and write tests to verify that they work correctly.1.1ObjectivesYour objectives for
Illinois Tech - CS - 331
Stacks and Queues2 GIVEN FILESCS 331 Lab: Stacks and Queues Spring 20081 IntroductionAs we discussed in lecture, stacks and queues are easy to code if you already have a working linked list implementation. In this lab, you will encapsulate a li
Illinois Tech - CS - 331
Binary Search Trees3 GIVEN FILESCS 331 Lab: Binary Search Trees Spring 20081 Objectives Be able to use the find and add traversal patterns. Be able to write delete for the three cases. Have experience using a dictionary style container. Use
Illinois Tech - CS - 331
Iterators1 GIVEN FILESCS 331 Lab 5: Iterators Fall 2007Rev : 4700.1ObjectivesIn this lab you will create two iterators for a singly linked list. Have experience using the Interface feature of Java. Know how to implement a traversal itera
Illinois Tech - CS - 331
Stacks and Queues2 GIVEN FILESCS 331 Lab: Stacks and Queues Fall 2007 Rev : 4691 IntroductionAs we discussed in lecture, stacks and queues are easy to code if you already have a working linked list implementation. In this lab, you will encapsul
Illinois Tech - CS - 331
Binary Search Trees3 GIVEN FILESCS 331 Lab: Binary Search Trees Fall 2007 Rev : 4861 Objectives Be able to use the find and add traversal patterns. Be able to write delete for the three cases. Have experience using a dictionary style containe
Illinois Tech - CS - 331
Iterators3 GIVEN FILESCS 331: Doubly Linked Lists Fall 2007Rev : 4801Objectives Create a doubly linked list. Have more experience using the Interface feature of Java. Use inheritance to enable you to reuse code.In this lab you will crea
Illinois Tech - CS - 331
Linked Lists3 YOUR WORKCS 331 Lab 3: Linked Lists Fall 2007Rev : 4531IntroductionIn this lab you will code some of the basic functions for a singly linked list, and write tests to verify that they work correctly.1.1ObjectivesYour obj
Illinois Tech - CS - 331
Traversals4 YOUR WORKCS 331 Lab: Tree Traversals Fall 2007 Rev : 2301 ObjectivesIn this lab you will create a binary search tree and write some traversal iterators for it. Be able to write iterators for DFS, BFS, Frontier, Preorder, Postorder,