Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (1 vote)
134 views

Lab - Exp - 9 (Declaring and Using Different Java Collections)

This document provides instructions for a lab exercise on using different Java collections. The objectives are to learn about the Collections, Set, List, and Map interfaces and how to construct a program using them. Students will create a program that prompts the user to select between a Vector, TreeSet, or Hashtable to store and display pet name data. The program should sort and display the names, allow duplicate entries, or store data with unique identifiers depending on the collection chosen. The document includes sample code that throws an error and asks students to explain why.

Uploaded by

Reb Blando.2
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
134 views

Lab - Exp - 9 (Declaring and Using Different Java Collections)

This document provides instructions for a lab exercise on using different Java collections. The objectives are to learn about the Collections, Set, List, and Map interfaces and how to construct a program using them. Students will create a program that prompts the user to select between a Vector, TreeSet, or Hashtable to store and display pet name data. The program should sort and display the names, allow duplicate entries, or store data with unique identifiers depending on the collection chosen. The document includes sample code that throws an error and asks students to explain why.

Uploaded by

Reb Blando.2
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

COLLEGE OF COMPUTER STUDEIS

INFORMATION TECHNOLOGY DEPARTMENT

CCS0023L
(Object Oriented Programming)

EXERCISE

9
Declaring and Using Different Java Collections

<STUDENT NAME>
<SECTION>
<DATE>
I. OBJECTIVES:

At the end of the experiment, students must be able to:

Cognitive
a) Learn the behavior of the Collections Interface
b) Learn the behavior of the Set Interface
c) Learn the behavior of the List Interface
d) Learn the behavior of the Map Interface

Psychomotor:
a) construct a program using set, list and map interface
b) compile and debug the error of the program

Affective
a) appreciate the concept behind this experiment

II. BACKGROUND INFORMATION

 A Collection (also known as container) is an object that contains a group of objects


treated as a single unit.

 A List cares about the index, a Set doesn’t allow duplicates and a Map cares about the
unique identifiers.

III. EXPERIMENTAL PROCEDURE:

1. Create a program that will prompt the user to choose from the menu:

A. Vector

B. TreeSet

C. Hashtable

D. Exit

If the user selects A, ask the user to enter five pet names. Using vector, sort and display
the names in alphabetical order. Then prompt the menu.

If the user selects B, do as if the user selects A but this time apply TreeSet. Output is the same.
The menu will appear afterwards.
If the user selects C, input the following:

PetType:
PetName:
PetColor:
PetAge:
PetSize:
After inputting, together with the above pet info, display the answer using Hashtable. Then
prompt the menu.

V. QUESTION AND ANSWER:

1. The following program is supposed to print the string "Blue". Instead, it throws
an error. Why?
import java.util.*;

public class SortMe {


public static void main(String args[]) {
SortedSet<StringBuffer> s
= new TreeSet<StringBuffer>();
s.add(new StringBuffer("Red"));
s.add(new StringBuffer("White"));
s.add(new StringBuffer("Blue"));
System.out.println(s.first());
}
}
______________________________________________________________________________
______________________________________________________________________________
_____________________________________________________________________________

Topic Collections
Lab Activity No 9
Lab Activity Declaring and Using Different
Java Collections
CLO 2
Program execution (20)
Correct output (20)
Design of output (10)
Design of logic (20)
Standards (20)
Delivery (10)
TOTAL

You might also like