what is java programming?an introduction to java programming for beginners(java programming...

5
MIT Africa Information Technology Initiative 1 MIT AITI Mobile Development in Java Java Lab 08: Object Oriented Programming In this lab you will implement classes that will represent a list of contacts on a mobile phone. You will be provided with source code for a test program called Lab08Test that will interface with your implementation. Lab08Test will call your code. Thus, your code needs to adhere to the API defined in this document. The main method for this lab is located in Lab08Test. 1. Create a new project named “lab08” for this lab. In your new project, create three new classes, ContactList, ContactGroup, and Person, and store them in the src folder. Also, import Lab08Test.java into this project. 2. Implement the Application Programmer Interface (API) for the ContactList, ContactGroup, and Person classes. The API definition begins on the next page. You must abide by this API in order for Lab08Test to test your code properly. An API is an interface contract to which your code must adhere. An API defines the methods and fields that users of your class can see. The API gives an English description of the behaviour of the methods and fields. You are required to implement the internals of the classes for the lab. The API does not specify the fields required. Also, the API does not specify the modifiers of the methods. Keep the ideas of abstraction and encapsulation in mind when implementing this lab. Remember that a method or field can be either static or non‐static, and it can be public or private. 3. After you finish the three classes, you should be able to run Lab08Test. Lab08Test should only print out “Success” a number of times when run.

Upload: daroko-blogwwwprofessionalbloggertrickscom

Post on 06-May-2015

69 views

Category:

Education


5 download

DESCRIPTION

Java programming presentations By Daroko blog Do not just read java as a programmer, find projects and start making some Money, at DAROKO BLOG,WE Guide you through what you have learned in the classroom to a real business Environment, find java applications to a real business Environment, find also all IT Solutions and How you can apply them, find the best companies where you can get the IT jobs worldwide, Find java contract, Complete and start making some cash, find clients within your Country, refer and get paid when you complete the work. Not Just a contact, at daroko Blog(www.professionalbloggertricks.com/),you are also being taught How you can apply all IT related field in real world. Simply Google, Daroko Blog or visit (www.professionalbloggertricks.com/) to Know More about all these service now. Do not just learn and god, Apply them in real world

TRANSCRIPT

MIT Africa Information Technology Initiative  1 

MIT AITI Mobile Development in Java Java Lab 08: Object Oriented Programming  

In  this  lab  you will  implement  classes  that will  represent  a  list  of  contacts  on  a mobile  phone.  You will  be provided with source code for a test program called Lab08Test that will interface with your implementation.  

Lab08Test will call your code.  Thus, your code needs to adhere to the API defined in this document.  The main method for this lab is located in Lab08Test. 

 

1. Create  a  new  project  named  “lab08”  for  this  lab.    In  your  new  project,  create  three  new  classes, 

ContactList, ContactGroup, and Person, and  store  them  in  the  src  folder.   Also,  import  Lab08Test.java into this project. 

2. Implement  the Application Programmer  Interface  (API)  for  the ContactList,  ContactGroup,  and Person classes.  The API definition begins on the next page.  You must abide by this API in order for Lab08Test to 

test your code properly.   

An API is an interface contract to which your code must adhere.  An API defines the methods and fields that users of your class can see.  The API gives an English description of the behaviour of the methods and  fields.    You  are  required  to  implement  the  internals  of  the  classes  for  the  lab.  The API  does  not 

specify the fields required.  Also, the API does not specify the modifiers of the methods. Keep the ideas of abstraction and encapsulation in mind when implementing this lab.  Remember that a method or field can be either static or non‐static, and it can be public or private. 

3. After you finish the three classes, you should be able to run Lab08Test. Lab08Test should only print out “Success” a number of times when run. 

 

MIT Africa Information Technology Initiative  2 

Class Person 

A Person is constructed by giving the person’s name, phone number, and age.  Also stored in the Person class is the number of times the person has been dialed (look at the dial() method below). 

Constructor Summary 

<modifiers> Person(String name, String phoneNumber, int age)

Creates a new Person with the given name, phone number, and age.  Initialize the dialed counter to 0. 

Method Summary 

<modifiers> String getName()

Returns the person’s name. 

<modifiers> int getAge()

Returns the person’s age. 

<modifiers> String getPhoneNumber()

Returns the person’s phone number. 

<modifiers> void birthday()

Adds 1 the person’s age.  (Called on a birthday). 

<modifiers> boolean sameAge(Person p1, Person p2)

Return true if p1 and p2 are the same age. 

<modifiers> void dial()

Simulate calling a Person.   For now, simply print “Dial contact_name” to the screen on its own 

line.  Update the dialed counter for this contact. 

<modifiers> int timesDialed()

Return the number of times this Person has been dialed (the number of times the dial() method has 

been called for this Person). 

<modifiers> int totalDials()

Return the number of times all Persons have been dialed.  Think about how you can implement this 

method; it may require an extra field. 

 

MIT Africa Information Technology Initiative  3 

Class ContactGroup 

A ContactGroup is a group of contact persons that you classify as similar.  For example, you may want all of your family members as a  contact group named “Family”. One can  set  if  calls  should be accepted  from  the group. Groups  are  constructed  by  passing  a  name  for  the  group,  an  array  of  Persons  and  a  boolean  specifying 

whether or not to accept calls from this group.     Optionally, one can specify the maximum number of persons 

allowed in the group.  No group may have more than 100 Persons.  

Constructor Summary 

<modifiers> ContactGroup(String name, Person[] contacts, boolean takeCalls)

Creates a new group with the specified contacts and the default maximum number of persons. 

<modifiers> ContactGroup(String name, Person[] contacts, boolean takeCalls, int maxContacts)

Creates a new group with the specified contacts and maximum number of persons. 

Method Summary 

<modifiers> int getMaxContacts()

Returns the maximum number of persons that can be added to this group. 

<modifiers> String getName()

Returns the name of the ContactGroup. 

<modifiers> Person[] getContacts()

Returns the contacts. 

<modifiers> boolean canCall()

Returns whether calls will be taken from this group. 

<modifiers> double getAverageAge()

Returns the average age of the persons in the group. 

<modifiers> void addContact(Person p)

Adds the Person p to this contact group.  

<modifiers> void setTakeCalls(boolean b)

Changes whether the user will take calls from the group. 

 

MIT Africa Information Technology Initiative  4 

<modifiers> void doNotTakeCalls(ContactGroup[] contactGroups)

Do not take calls from each ContactGroup in the contactGroups array. 

<modifiers> boolean contactInGroup(Person p)

Determines if the given person is in the group. 

 

Class ContactList 

A ContactList stores the Persons and ContactGroups in a mobile phone.  You can only have one ContactList, as a mobile phone has only one list of contacts.  A ContactList is created by specifying an array of Persons and 

(optionally) an array of ContactGroups 

Every ContactList has the following ContactGroups defined: 

• Friends • Family • Business 

• Favorites (5 members at most in Favorites group) 

Additional groups can be created using the second form of the constructor below. 

Constructor Summary 

<modifiers> ContactList(Person[] contacts)

Creates a new ContactList with the specified contacts and the required groups.  The groups are initially 

empty. 

<modifiers> ContactList(Person[] contacts, ContactGroup[] groups)

Creates a new ContactList with the specified contacts, the required groups, and additional groups as given in the argument groups.  

Method Summary 

<modifiers> Person[] getContacts()

Returns the contact persons. 

<modifiers> ContactGroup[] getGroups()

Returns the groups in the ContactList. 

<modifiers> ContactGroup getGroup(String name)

Returns the group in the ContactList with the given name or null if no such group exists. 

MIT Africa Information Technology Initiative  5 

<modifiers> void addGroup(ContactGroup g)

Adds the ContactGroup to the ContactList. 

<modifiers> ContactGroup[] groupsOfContact(Person p)

Returns an array of groups that the Person p is in.