Download presentation
Presentation is loading. Please wait.
1
Remedial Tutorials Week 2 How to think about programming
2
The Problem Write a "Contact List" application that can: 1.store contacts (with a first name, last name, and year of birth) 2.get the age in years of the contact 3.get the full name (first + last) of the contact 4.add contacts to the list 5.get the number of contacts in the list And a few other things: 6.can find the oldest contact in the list 7.can find the contact with the longest name in the list 8.can ask how many contacts to input, and then allow the user to input the data for those contacts 9.can print out the count of contacts in the list 10.can print out the name of the longest contact 11.can print out the name of the oldest contact.
3
What is the first thing to do? ASK THE HIGHLY...1CREATE A CLASS...1 BREAK IT DOWN I...1CREATE A CLASS....1 BULID A CLASS S...1CREATE A CONTA...1 CLASS CONTACT...1CREATE A WAY T...1 CREATE A CLASS...1OTHER9
4
The Process Identify the requirements Brainstorm/design/discuss/redesign the structure of the program –How many classes do we need? –What are they responsible for? Define the classes (constructors, fields and signatures of functions in them) Write the code for the functions –Actually lots of steps Test and debug!
5
How many classes do we need? (Think which ones and then respond) 1.One 2.Two 3.Three 4.Four 5.Five 6.Six 7.More than 6
6
The Classes 1.ContactList –Holds all the contacts –Adds and returns contacts etc. 2.Contact –Holds details for each contact –Sets and returns details for each contact 3.Driver –Holds the “main” class –Interacts with the user (reads from keyboard, prints on screen) –Interacts with the other classes
7
Which class should be designed first (and why)? 1.ContactList 2.Contact 3.Driver
8
The Contact class What information does it need to store? Look at the problem sheet and decide (in pairs) what data fields are needed and which types they should be.
9
The Fields private String firstName; private String lastName; private int yearOfBirth;
10
Getters and Setters public void setFirstName(String firstName) public String getFirstName() public void setLastName(String lastName) public String getLastName() public void setYearOfBirth(int yearOfBirth) public int getYearOfBirth()
11
What else does this class need to be complete? :S1CONSTRUCTOR1 A CLOSING BRAC...1CONTACT AGE, F...1 ASK THEIR DATE...1CONTRUCTORS I...1 CALCULATEAGE(I...1GET AGE OF CON...1 CATCH ERROR E...1OTHER5
12
The Constructor public Contact(String firstName, String lastName, int yearOfBirth) { this.firstName = firstName; this.lastName = lastName; this.yearOfBirth = yearOfBirth; }
13
Other Functions public String getFullName() –Should return the first and last names combined public int getAge() –Should return the current age, in years, of the contact
14
The Contact class so far… public class Contact { private String firstName; private String lastName; private int yearOfBirth; public Contact(String firstName, String lastName, int yearOfBirth) { this.firstName = firstName; this.lastName = lastName; this.yearOfBirth = yearOfBirth; } public String getLastName() { } public void setLastName(String lastName) { } public int getYearOfBirth() { } public void setYearOfBirth(int yearOfBirth) { } public void setFirstName(String firstName) { } public int getAge() { } public String getFullName() { }
15
Getters and Setters public String getLastName() { return this.lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public int getYearOfBirth() { return this.yearOfBirth; } public void setYearOfBirth(int yearOfBirth) { this.yearOfBirth = yearOfBirth; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getFirstName() { return this.firstName; }
16
The ContactList class What should go in it? Look at the problem sheet and decide (in pairs) what data it needs. What functions does it need?
17
How do well do you understand how to design classes? 1.What is a class? 2.I think I could do it 3.I am pretty sure I could design a class from a specification 4.Class are my friends
18
How do well do you understand functions? 1.What is a function? 2.I think I could declare a function… 3.I am pretty sure I could declare a function 4.Functions are my friends
19
Please help us improve these classes by responding to the following questions
20
ResponseWare enabled me to receive effective feedback in this class. 1.Strongly Disagree 2.Disagree 3.Neutral 4.Agree 5.Strongly Agree
21
ResponseWare enabled me to influence the direction of the class 1.Strongly Disagree 2.Disagree 3.Neutral 4.Agree 5.Strongly Agree
22
Before the class: How did you feel about the material covered today 1.Not confident at all 2.Mostly not confident 3.Slightly confident 4.Neutral 5.Somewhat confident 6.Mostly confident 7.Absolutely confident
23
How do you feel now about the material covered today? 1.Not confident at all 2.Mostly not confident 3.Slightly confident 4.Neutral 5.Somewhat confident 6.Mostly confident 7.Absolutely confident
24
Please let us know two things you will take away from class today They can be as long or as short as you like and they won’t display on this slide. We also won’t know who has said what!
25
Using ResponseWare for parts of standard labs would be useful 1.Strongly Disagree 2.Disagree 3.Neutral 4.Agree 5.Strongly Agree
26
Any other feedback? See you next week!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.