程序代写代做 algorithm Java data structure Introduction and Object Review

Introduction and Object Review
Daniel Archambault
Pronounced: Arshambo-
CS-115: Intro and Objects
1

Self Introduction
CS-115: Intro and Objects
2

Self Introduction
Me: Hi, my name is Dan.
CS-115: Intro and Objects
2

Self Introduction
Me: Hi, my name is Dan. Class: Hi Dan.
CS-115: Intro and Objects
2

Self Introduction
Me: Hi, my name is Dan.
Class: Hi Dan.
And I have a computer science problem
CS-115: Intro and Objects
2

Self Introduction
Me: Hi, my name is Dan.
Class: Hi Dan.
And I have a computer science problem
􏰀 Many of them actually
CS-115: Intro and Objects
2

Self Introduction
Me: Hi, my name is Dan.
Class: Hi Dan.
And I have a computer science problem
􏰀 Many of them actually
􏰀 Fortunately, most of them are for you 􏰀 Bwhahahahahah!
CS-115: Intro and Objects
2

Self Introduction
Me: Hi, my name is Dan.
Class: Hi Dan.
And I have a computer science problem
􏰀 Many of them actually
􏰀 Fortunately, most of them are for you 􏰀 Bwhahahahahah!
I am teaching this class for the for the fifth time
CS-115: Intro and Objects
2

Self Introduction
Me: Hi, my name is Dan.
Class: Hi Dan.
And I have a computer science problem
􏰀 Many of them actually
􏰀 Fortunately, most of them are for you 􏰀 Bwhahahahahah!
I am teaching this class for the for the fifth time
􏰀 I am truly fortunate to be here
CS-115: Intro and Objects
2

Self Introduction
Me: Hi, my name is Dan.
Class: Hi Dan.
And I have a computer science problem
􏰀 Many of them actually
􏰀 Fortunately, most of them are for you
􏰀 Bwhahahahahah!
I am teaching this class for the for the fifth time
􏰀 I am truly fortunate to be here
􏰀 And still very nervous
CS-115: Intro and Objects
2

More About Me..
I’m Canadian, eh…
Grew up in the capital of the country
􏰀 that’s Ottawa, Ontario
I am fortunate to have studied/lived in many countries
􏰀 Queen’s University, Kingston, Canada
􏰀 Univ. of British Columbia, Vancouver, Canada
􏰀 Univ. of Victoria, Victoria, Canada
􏰀 INRIA Bordeaux Sud-Ouest, Bordeaux, France
􏰀 Univ. College Dublin, Dublin, Ireland
􏰀 Swansea University, Swansea, Wales
CS has taken me to some pretty cool places
CS-115: Intro and Objects
3

The Teaching that I’m doing with Everyone
Software Engineering Principles CS-115
􏰀 Advanced Programming Concepts
􏰀 Data Structures
􏰀 Theory and Algorithms
15 Credits, Lectures, (9x) Labs, (2x) Assignments, 1 exam Assessment
􏰀 Assignments (20%)
􏰀 Labs (10%)
􏰀 Examination (70%)
Two lectures a week (you must attend both)
􏰀 Monday 4pm in Twyni 002
􏰀 Tuesday 10am in Twyni 002
Labs: CoFo 104
􏰀 You will only be signed off in your allocated lab
􏰀 Labs will not be signed off over email. Do not email your labs.
CS-115: Intro and Objects
4

Keeping up with labs means passing
Why? It’s 10% of the module?! %@&#!
􏰀 two years ago 87% of those who failed the labs failed the module
⋆ two students passed the labs and slept through exam accidentally 􏰀 it is the minimal practice required
Please attend you weekly lab in your allocated time slot. This time programming gets real.
CS-115: Intro and Objects
5

Office Hours and Contact
My Office: CoFo 334
Office Hours: Monday & Tuesday @ 3pm
Questions about the course material? Use the forum.
Private and personal questions
d.w.archambault@swansea.ac.uk
I’m much better at explaining things in person Please make use of my office hours!
CS-115: Intro and Objects
6

How to Study for this Course
Java for Everyone: Late Objects, by C. Horstmann, Wiley, 2013.
1 Be prepared to take notes
􏰀 I tend to organise a course around lectures
􏰀 and use texts as support and alternate explanations
2 Thus, attendance is extremely important for CS-115
CS-115: Intro and Objects
7

Class Ground Rules
1 Treat everyone in the class with respect
􏰀 that includes your fellow students
􏰀 that includes me (you’d be surprised)
2 There is no such thing as a stupid question
􏰀 never be afraid to ask a question
􏰀 but don’t try to negotiate marks with me
3 Give your best effort for all parts of the assignment
􏰀 the worst thing you can do, in my mind, is not submit
􏰀 or demonstrate very little effort
4 Be positive and have fun!
CS-115: Intro and Objects
8

Cheating
CS-115: Intro and Objects
9

Cheating
It sucks.
CS-115: Intro and Objects
9

Cheating
It sucks. Don’t do it.
CS-115: Intro and Objects
9

Cheating
It sucks.
Don’t do it.
Not even unintentionally
􏰀 For individual assignments,
⋆ Do collaborate on white board or laptop
⋆ Before end of session, erase all recorded data from the session
CS-115: Intro and Objects
9

Cheating
It sucks.
Don’t do it.
Not even unintentionally
􏰀 For individual assignments,
⋆ Do collaborate on white board or laptop
⋆ Before end of session, erase all recorded data from the session
Don’t exchange code or copy text from each other
CS-115: Intro and Objects
9

Cheating
It sucks.
Don’t do it.
Not even unintentionally
􏰀 For individual assignments,
⋆ Do collaborate on white board or laptop
⋆ Before end of session, erase all recorded data from the session
Don’t exchange code or copy text from each other Obviously, no copying of code from the Internet…
CS-115: Intro and Objects
9

Why Did You Choose Computer Science?
CS-115: Intro and Objects
10

Why Did You Choose Computer Science?
Do I Have to Learn How to Program?
CS-115: Intro and Objects
10

Why Did You Choose Computer Science?
Do I Have to Learn How to Program? Yes.
CS-115: Intro and Objects
10

Why Did You Choose Computer Science?
Do I Have to Learn How to Program? Yes.
But, we’ll help you.
CS-115: Intro and Objects
10

Why Did You Choose Computer Science?
Do I Have to Learn How to Program? Yes.
But, we’ll help you.
Why don’t we skip all the programming stuff and get on to the part where I get lots of money?
CS-115: Intro and Objects
10

Why Did You Choose Computer Science?
Do I Have to Learn How to Program?
Yes.
But, we’ll help you.
Why don’t we skip all the programming stuff and get on to the part where I get lots of money?
No.
CS-115: Intro and Objects
10

Why Did You Choose Computer Science?
Do I Have to Learn How to Program?
Yes.
But, we’ll help you.
Why don’t we skip all the programming stuff and get on to the part where I get lots of money?
No.
Okay, okay. Just, allow me to avoid all the technically hard stuff so you can give me my degree and then I get lots of money!
CS-115: Intro and Objects
10

Why Did You Choose Computer Science?
Do I Have to Learn How to Program?
Yes.
But, we’ll help you.
Why don’t we skip all the programming stuff and get on to the part where I get lots of money?
No.
Okay, okay. Just, allow me to avoid all the technically hard stuff so you can give me my degree and then I get lots of money!
Avoiding the technical stuff will hurt your career prospects.
CS-115: Intro and Objects
10

Programming (Dun! Dun! Dun!) NOOOOOOO!
Learning advanced programming is hard for everyone 􏰀 some appear more confident then others
Be wary of overconfidence…
CS-115: Intro and Objects
11

Keys to Success
Image by Bernard Goldbach
1 Accept that you still have many things to learn.
2 Accept that everyone is unsure of themselves
􏰀 corollary: some people really are good at looking confident (i.e. Trump)
3 Work hard and be prepared to make lots of mistakes
CS-115: Intro an􏰀d Objects 12 and don’t beat yourself up over them.

Need Help with the Course Material?
Attention less experience programmers!
CS-115: Intro and Objects
13

Need Help with the Course Material?
Attention less experience programmers! And overconfident ones…
CS-115: Intro and Objects
13

Need Help with the Course Material?
Attention less experience programmers!
And overconfident ones…
Attend my office hours to learn how to program
􏰀 Monday and Tuesday at 3pm
􏰀 This session is completely optional
CS-115: Intro and Objects
13

Questions? Classes and Objects!
CS-115: Intro and Objects
14

Working Towards Software Engineering
You are about to enter the too much code zone Very shortly, you will not be able to:
􏰀 code without some sort of a design sketch
􏰀 hold the entire software system in your brain!
Thus, several levels of abstraction are needed
CS-115: Intro and Objects
15

Abstract Data Types
Structure software using Abstract Data Types for encapsulation Consists of one or more classes working together
Parts of abstract data types:
􏰀 What data is stored?
􏰀 What operations can you perform on it?
Can be a complex system hidden from the user
ADT as a wall between a software component and the outside world
Can be modelled as Java interfaces
An implementation of an ADT is a data structure
CS-115: Intro and Objects
16

Object-Oriented Design
We use one or more classes to construct our data structure Parts of a class:
CS-115: Intro and Objects
17

Object-Oriented Design
We use one or more classes to construct our data structure Parts of a class:
􏰀 Attributes
⋆ The data stored by the class
􏰀 Behaviours
⋆ The operations which can be performed by the class
CS-115: Intro and Objects
17

Class vs Object
Class
􏰀 A description of the data that can be stored (attributes)
􏰀 A description of the methods which can be executed on them
􏰀 int, char, String….
Object
􏰀 An instance of those values which can be stored
􏰀 An instance of the methods which can be executed on them
􏰀 6, ’c’, “Hello”
CS-115: Intro and Objects
18

Analogy
Class
Instance of a Class
CS-115: Intro and Objects
19

Analogy
Class
􏰀 int
Instance of a Class
CS-115: Intro and Objects
19

Analogy
Class
􏰀 int
Instance of a Class
􏰀 3,8,7,-4
CS-115: Intro and Objects
19

What is a Class?
DVD Demo (Code Next Page)
CS-115: Intro and Objects
20

DVD Human Program
//Somewhere, in a main method, far far away… …
DVD d1 = new DVD (“Kiki la petite sorcière”); DVD d2 = new DVD (“Spirit of the Marathon”); DVD d3 = new DVD (“Love Actually”); d1.openCase ();
d2.readBackOfCase (); d3.openCase (); d1.closeCase (); d3.removeDVD (); d3.putDVDBack ();
d1 = d3; d1.isCaseOpen(); d2 = null; d2.openCase();
CS-115: Intro and Objects
21

Structure of a Class
Meanwhile inside the DVD class…
Classes always begin with a capital letter
public class DVD {

//Some attributes (data) associated with the class private String title;
private int runningTime;

public DVD (String title) {
this.title = title;
}
public void setRunningTime (String runningTime) {
this.runningTime = runningTime; }
…. }
CS-115: Intro and Objects
22

Attributes
A description of what is stored in the object Attributes always begin with a small letter

//Some attributes (data) associated with the class private String title;
private int runningTime;

CS-115: Intro and Objects
23

Behaviours
What can be done with or to objects
In class design, it is the operations on the data Anything that modifies an attribute is a behaviour Always begins with a small letter

public void setRunningTime (String runningTime)
{
this.runningTime = runningTime;
} ….
CS-115: Intro and Objects
24

Constructors
Constructs a new object
Operations needed to initialise a new object

public DVD (String title)
{
this.title = title;

} …
CS-115: Intro and Objects
25

Public vs Private
Attributes and behaviours can be public and private
􏰀 public means accessible to other classes
􏰀 private means accessible only to the designed class
In good coding style, attributes are never public

//Some attributes (data) associated with the class private String title;
//BAD Dan! No public attributes for you!
public int runningTime;

CS-115: Intro and Objects
26

Static vs Non-Static
Attributes and behaviours can be static or not
􏰀 Static means it’s associated with the class (there is only one copy)
􏰀 If it’s not static, it’s associated with an object (one copy per
instance) Example
􏰀 Each DVD may have its own title
􏰀 There is only one number of DVDs in the classroom
Usually, most of your attributes are non-static

//Some attributes (data) associated with the class private String title;
private static int totalNumberOfDVDs;

CS-115: Intro and Objects
27

What is this
Non-static methods, like constructors, associated with an object
􏰀 Inside a non-static method, inside a particular instance of an object
􏰀 A reference is always needed to change value of that object
􏰀 This reference is this in Java
CS-115: Intro and Objects
28

Quiz
CS-115: Intro and Objects
29

Quiz
What is the difference between a class and an object?
CS-115: Intro and Objects
29

Quiz
What is the difference between a class and an object? What is a constructor?
CS-115: Intro and Objects
29

Quiz
What is the difference between a class and an object? What is a constructor?
What is the difference between private and public?
CS-115: Intro and Objects
29

Quiz
What is the difference between a class and an object? What is a constructor?
What is the difference between private and public? What is the meaning of static?
CS-115: Intro and Objects
29

Quiz
What is the difference between a class and an object? What is a constructor?
What is the difference between private and public? What is the meaning of static?
What effect does non static have?
CS-115: Intro and Objects
29

Quiz
What is the difference between a class and an object? What is a constructor?
What is the difference between private and public? What is the meaning of static?
What effect does non static have? What is this?
CS-115: Intro and Objects
29