Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit 2 Review (Part 1) Arrays, Inheritance, and the Ethical Use of Computers.

Similar presentations


Presentation on theme: "Unit 2 Review (Part 1) Arrays, Inheritance, and the Ethical Use of Computers."— Presentation transcript:

1 Unit 2 Review (Part 1) Arrays, Inheritance, and the Ethical Use of Computers

2 Test Details The test will cover everything we did since the last test This includes 1-D arrays, 2-D arrays, inheritance, and the ethics surrounding piracy and cyberbulling

3 1-D Array Basics Write a sample 1-D array for each of the four primitive types.

4 Sample problem Given an array of ints of odd length, return a new array length 3 containing the elements from the middle of the array. The array length will be at least 3. midThree({1, 2, 3, 4, 5}) → {2, 3, 4} midThree({8, 6, 7, 5, 3, 0, 9}) → {7, 5, 3} midThree({1, 2, 3}) → {1, 2, 3} public int[] midThree(int[] nums) { }

5 public int[] midThree(int[] nums) { int[] a = new int[3]; a[0] = nums[nums.length/2-1]; a[1] = nums[nums.length/2]; a[2] = nums[nums.length/2+1]; return a; }

6 2-D Arrays How do you write a 2-D array that takes in a temperature recording (a decimal number) every weekday for three weeks?

7 2-D Arrays How do you write a 2-D array that takes in a temperature recording (a decimal number) every weekday for three weeks? A: double[][] decNumbers = new double[3][5];

8 Sample Problem Write a code that will fill the array a (declared as follows) with numbers typed at the keyboard. If the numbers are larger than 48 or smaller than -27, the numbers should not be recorded in the array. int[][] a = new int[3][4]; Print out each element of the array and check if you get the expected output.

9 Inheritance basics What is inheritance in computer programming?

10 Inheritance allows you to define a very general class and then later define more specialized classes simply by adding some new details to the older; more general class definition.

11 Which is the base class / derived class?

12 Writing a Base Class Class name: Person UML - name: String + Person() } constructor + Person(String initialName): void + setName(String newName): void + getName(): String + writeOutput: void + sameName(Person otherPerson): boolean

13 Always start with a constructor public Person() { name = “there is no name”; }

14 Writing a derived class Class name: Student UML: - studentNumber: int + Student() } constructor + Student(String initialName, int initialStudentNumber) + reset(String newName, int newStudentNumber) + getStudentNumber(): int + setStudentNumber(int newStudentNumber): void + writeOutput(): void + equals(Student otherStudent): boolean

15 Modify code Add super code } where can we add this ? Add extends } where does this go?

16 Modify code Add super code } where can we add this ? A: Only in the constructors of the derived class Add extends } where does this go? A: in the public class definition Example: public class Student extends Person

17 What is the difference between overloading and overriding?

18 In overloading, your methods can have the same method heading as long as there are a different number of parameters or parameter types

19 What is the difference between overloading and overriding? In overloading, your methods can have the same method heading as long as there are a different number of parameters or parameter types (used in an encapsulated class) In overriding, if you have a method in the derived class with the same heading in the base class, then the base class’s method is overridden

20 Using Computers Ethically What is cyberbullying?

21 Using Computers Ethically What is cyberbullying? Has there been a case of cyberbullying resulting in greater harm than physical bullying?

22 Using Computers Ethically What is cyberbullying? Has there been a case of cyberbullying resulting in greater harm than physical bullying? Who should monitor or be in charge of accountability when it comes to cyberbullying? The police? The school?

23 Piracy What is piracy?

24 Effects of Software Piracy on the Industry? Reduces profits for the software developer reduces development money for future products individual who uses pirated software cannot receive technical support

25 Effects of Software Piracy on the Pirate? (1997) Expense, embarrassment, ethically wrong Fines up to $250,000 Jail sentence of up to 5 years payment of legal fees (your own and the company suing you) Business Software Alliance received $5 million in settlements in 1995 alone for software copyright infringement (BSA)

26 Tomorrow Part 2 of the Review: We’ll complete Polymorphism, Dynamic Binding and the Abstract Class

27 Continue working on the Word search Program

28 Exercise WARNING: this may be hard Create a word search puzzle with the following conditions The puzzle is 10x10 Each character is created by the math class’s randomization feature (search it up) Each character in the puzzle is also stored in a 2-D array After the puzzle is generated, insert words relevant to this unit (along the vertical, horizontal and diagonal and make some intersect) Print out the word search to a txt file


Download ppt "Unit 2 Review (Part 1) Arrays, Inheritance, and the Ethical Use of Computers."

Similar presentations


Ads by Google