PARALLAG - LABEXP6 (Declaring Classes)
PARALLAG - LABEXP6 (Declaring Classes)
CCS0023L
(Object Oriented Programming)
EXERCISE
6
Declaring classes
<Nicole Parallag>
<BSITSMBA B21>
<September 24, 2019>
I. Objectives:
Cognitive
a) understand how to create classes
b) understand attributes and methods
Psychomotor:
a) construct a program using classes and objects
b) compile and debug the error of the program
Affective
a) appreciate the concept behind this experiment
}
– where,
public - means that our class is accessible to other classes outside the package
class - this is the keyword used to create a class in Java
StudentRecord - a unique identifier that describes our class
III. EXPERIMENTAL PROCEDURE:
1. Write a program to create a room class, the attributes of this class is roomno,
roomtype, roomarea and ACmachine. In this class the member functions are
setdata and displaydata.
a. Provide the necessary accessor and mutator methods for all the
attributes.
b. Constructors
3. AddressBook. Create a class address book that can contain 100 entries of
AddressBookEntry objects (use the class you created in the first exercise). You
should provide the following methods for the address book.
a. Add entry
b. Delete entry
c. View all entries
d. Update an entry
CODE:
1)
package room;
OUTPUT:
2/3)
CODE:
package addressbook;
import java.io.BufferedReader;
import java.io.InputStreamReader;
do{
sr[i]=new Addressbook();
System.out.println("\n\n\tADD ENTRY");
System.out.print("Name --> ");
String name=br.readLine();
System.out.print("Address --> ");
String address=br.readLine();
System.out.print("Email --> ");
String email=br.readLine();
System.out.print("Contact No. --> ");
int telNo=Integer.parseInt(br.readLine());
//set the values
sr[i].setName(name);
sr[i].setAddress(address);
sr[i].setEmail(email);
sr[i].setTelNo(telNo);
System.out.print("\nInput again? [y/n] --> ");
answer=(char)System.in.read();
System.in.read();
//if(answer=='y' || answer=='Y') i++;
i++;
}while(answer=='y' || answer=='Y');
return i;
}
public static void main(String[] args) throws Exception{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
Addressbook[] sr=new Addressbook[5];
String nameToCompare;
int opt,updateOption,i=0;
char answer;
boolean found;
do{
opt=displayMenu();
switch(opt){
case 1: i=addEntry(sr,i);
break;
case 5: System.out.println("\n\tGoodbye!");
}
}while(opt!=5);
}
OUTPUT:
V. QUESTION AND ANSWER: