380 likes | 388 Views
An introduction to object-oriented programming, focusing on building and testing classes, using inheritance and polymorphism, and exploring data structures such as stack, queue, and linked lists.
E N D
COMPUTER 2430Object Oriented Programming andData Structures I Instructor: Qi Yang 213 Ullrich YangQ@uwplatt.edu 342-1418
Web Sites My Home Page http://people.uwplatt.edu/~yangq/ Click Here COMPUTER 2430 Home Page http://people.uwplatt.edu/~yangq/CS243/ Click Here
Lab Assistant Nadine Gadjou Lab 206 3:00 – 5:00 PM Monday - Thursday
Course Description • An introduction to object-oriented programming. • Emphasis on building and testing classes using software engineering techniques. • Includes study of a standard class library and use of inheritance and polymorphism for building subclasses and extensibility. • Coverage of the stack and queue classical data structures. • Discussion of searching, sorting, and hashing techniques. • Introduction to linked lists.
Expected Learning Outcomes • Develop software using elementary data structures. • Design, implement, and test programs using classes, inheritance, and polymorphism. • Compare and contrast algorithm efficiency at a very basic level. • Write module tests, system tests, and develop test specifications. • Perform simple object-oriented analysis and design. • Work in a small team (two or three people) on the analysis, design, implementation, and testing of a project.
Course Work • 6 Quizzes 60 • 3 Tests 150 • Programs and Labs 190 • Final 100 • Total 500
Grading Grade Total PointsPercentage Grade Points A 460 - 500 92% 4.0 A - 445 - 459 89% 3.7 B + 435 - 444 87% 3.3 B 410 - 434 82% 3.0 B - 395 - 409 79% 2.7 C + 385 - 394 77% 2.3 C 360 - 384 72% 2.0 C - 345 - 359 69% 1.7 D + 335 - 344 67% 1.3 D 300 - 334 60% 1.0 F Below 300 Below 60% 0.0 NO CURVE!
Prereq: COMPUTER 1430 Congratulations! C- or Better on COMPUTER 1430 AP tested out of COMPUTER 1430 Welcome to CSSE! COMPUTER 2430 is MUCH more difficult! One reason: Summer is too long! A C/C- in Computer 1430 may not be good enough! AP tested out: good enough?
Fall 2017 • 73 students at the beginning • 6 students dropped by week 2 • 67 students left • 4 students withdrew by week 8 • 63 students left • 15 failed (D or F) • 48 students passed (C- or above) • Passing rates • 66% (48/73), 72% (48/67), or 76% (48/63)
COMP 1430 and COMP 2430 • COMPUTER 1430 C++ Procedural programming Visual Studio • COMPUTER 2430 Java Object Oriented Programming (OOP) NetBeans Data Structures
COMP 1430 and COMP 2430 • Software Development Grand Rules • Must follow the rules • You may lose many points on style
NetBeans • Installed in all labs in Ullrich • Install NetBeans on Your PC K:\Academic\CSSE\Software\NetBeans_8.1_JDK_8u91 • Follow Instructions • Step by Step • Import format settings • Do not auto update
Lab1 Five Points Due Friday at 10 pm September 7 Lab Assistant in 206 1:00 – 3:00 The First Week
Creating Java Project in NetBeans • Open NetBeans • Menu File/New Project (or New Project on Toolbar) • Categories: Java • Projects: Java Application • Next • Project Name: Lab1 • Project Location: K:\, J:\ or USB drive • Uncheck “Create Main Class” • Finish
Completing Lab1 • Download file IntegersList.java to folder src of your Lab1 project folder • Open IntegersList.java in NetBeans • Source Packages • <default packages> • Complete IntegersList.java according to the 23 DOs
Running Java Programs in NetBeans • NetBeans compiles automatically after saving • Right click IntegersList.java • Select “Run File” Shift+F6 • Output Window Run: • Enter input values in the Output Window • BUILD SUCCESSFUL (total time: ?? seconds)
Submitting Lab1 to the Grader • Go to the Grader page at https://alpha.ion.uwplatt.edu/grader/ • Login using your UWP username and password • Choose CS 2430! • Choose Lab1 • Upload your IntegersList.java • Submit • Must receive 0 differences!
Limit on the Grader • You will lose points if you submit Lab1 to the grader too many times: • -1 if more than 10 times • -2 if more than 15 times • Compile and run your Lab1 • Checking output before submitting
The K:\ Drive K:\Course\CSSE\yangq\2430 Individual folders Should create the Labs/Progs inside your folder on the K:\ drive For Demo and Q&A Must use the K:\ drive
C++ and Java At the statements level for our class, Java is almost the same as C++. Review your C++ Labs and Programs!
Primitive Data Types • char ASCII and Unicode • int, short, long • float, double • bool (C++) and boolean (Java) • byte
C++ and Java // Declaration statement int value, total = 0, remainder, quotient; value = 5; // assignment if (value > 0) total += value; else { remainder = value % 5; quotient = value / 5; } // Statement terminator: semicolon
Output C++ cout << “The value: ” << value; cout << “The value: ” << value << endl; Java System.out.print(“The value: ” + value); System.out.println(“The value: ” + value);
Input C++ int intValue; cout << “Enter an integer: ” << endl; cin >> intValue; Java import java.util.Scanner; Scanner sc = new Scanner(System.in); int intValue; System.out.println(“Enter an integer: ”); intValue = sc.nextInt();
C++ and Java /** While loops are the same. We could use it for comment in C++. */ int count = 0, total = 0; while (count < 100) // magic number { ++ count; // same as count ++ in // most cases total += count; // total = total + count; }
C++ and Java /** For Loops are also the same We decided to use “/**” for comment start */ for (int i = 0; i < count; i ++) { // Count-Controlled loop // Processing array elements }
Arrays Java // Array is a class int[] intArray; float floatArray[]; // To get an array object // Magic word: new intArray = new int[50]; C++ int intArray[50]; // Array of valCount 50 0 1 3 4 48 49 Index from 0 to 49 The same in Java and C++
Arrays COMPUTER 1430 Adding elements Deleting elements Linear Search Computing max, min and avg Sorting
Linear Search /** intArray has valCount values and target is an int Return the index of 1st element which equals target. Otherwise return -1. */ for (int i = 0; i < valCount; i++) { if (intArray[i] == target) return i; else // return -1? } // When to return -1? return -1;
Linear Search /** intArray has valCount values target is an int Return the index of 1st element which equals target. Otherwise return -1. */ for (int i = 0; i < valCount; i++) { if (intArray[i] == target) return i; } return -1;
Correct? /** intArray has valCount values target is an int Return the index of 1st element which equals target. Otherwise return -1. */ for (int i = 0; i < valCount; i++) { if (intArray[i] == target) if (i == target) // Correct? return i; } return -1;
Correct? final int MAX_SIZE = 50; int intArray[] = new int[MAX_SIZE]; int valCount = 0; /** intArray has valCount values and target is an int. Return the index of 1st element which equals target. Otherwise return -1. */ for (int i = 0; i < valCount; i++) for (int i = 0; i < MAX_SIZE; i++) // Correct? { if (intArray[i] == target) return i; } return -1;
Java Class public class IntegerList { private final int MAX_SIZE = 50; private int intArray[] = new int[MAX_SIZE]; private int valCount = 0; public int find( int target ) { for (int i = 0; i < valCount; i++) if (intArray[i] == target) return i; return -1; } . . . }
Java Main Method public class IntegerList { private final int MAX_SIZE = 50; private int intArray[] = new int[MAX_SIZE]; private int valCount = 0; public int find( int target ) . . . // other methods /** Selecting “Run File” in NetBeans after right clicking IntegersList.java will run the main method. */ public static void main(String [] args) { // Testing the class return; } }
Calling Class Methods public class IntegersList { public boolean addValue ( int intValue ) public int find ( int intValue ) public void print() public static void main( String [] args ) { IntegersList list = new IntegersList(); list.addValue(inputValue); list.find(target); list.print(); . . . }
Using Scanner to Input import java.util.Scanner; public class IntegersList { . . . public static void main( String [] args ) { IntegersList list = new IntegersList(); Scanner sc = new Scanner(System.in); System.out.println("Enter a value to add: "); inputValue = sc.nextInt(); list.addValue(inputValue); . . . } }
Lab1 Five Points Due Friday at 10 pm September 7 Start Early Get zero differences Follow style rules