Preview

Narrative report in ojt

Satisfactory Essays
Open Document
Open Document
365 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Narrative report in ojt
HashMaps
And an Introduction to GUIs
Using Java's Swing Toolkit

Lecture Time!
• HashMap
• J/Frame
• Component classes
– J/Button
– J/TextField

The Java Collections Framework
• This is a set of classes you can use for containing arbitrarily large collections of objects.
• To use: import java.util.*;
• Some basic Collection classes:
– ArrayList
– Vector
– HashMap
– Hashtable (yes, that's a small t)

HashMap
• ArrayList is usually mentioned as ArrayList
– E is the object type that it will contain.
– ArrayList means that we want an

ArrayList that can contain BankAccounts.

• HashMap, however, is defined as HashMap
– K is the object type that will be used as a key.
• HashMaps do not use an index and must rely on a provided “key” data to fetch an object.

– V is the object type that the HashMap will contain.
• Similar to E in ArrayList.

Example import java.util.*; public class HashMapDemo
{
public static void main( String args[] )
{
HashMap accts = new HashMap(); accts.put( "Bob", new BankAccount( 2000 ) ); accts.put( "Alice", new BankAccount( 1000 ) ); accts.get( "Bob" ).deposit( 500 );
// how do you print Alice's and Bob's balances?
}
}

Other HashMap Methods
• void clear()

– Empties the HashMap of keys and values.
• boolean containsKey( Object key )

– True if the HashMap has a value mapped to this key.
• boolean containsValue( Object value )

– True if the HashMap has the specified value inside.
• Set keySet() // self-study

– Gives a Set of all of its keys for iteration purposes.
• Collection values() // self-study

– Gives a Collection of all its value contents for iteration purposes. Java Swing Toolkit
• import java.awt.*;
• import javax.swing.*;

• While JOptionPane is useful, programmers often want more control over their programs.
– I don't want to use System.out.println() for program output anymore!
– I want to be able to accept 3 different text inputs at the same time

You May Also Find These Documents Helpful

  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    INSTRUCTIONS: 1. THERE ARE SIX (6) QUESTIONS IN THIS PAPER. 2. ANSWER FIVE (5) QUESTIONS ONLY. Question 1 Arrays are used when storing a large number of values. You are required to create an array named a and answer the following questions regarding array manipulation. a. Write a method fillRandom(int[] a, int min, int max), fill the array a with a random integer value. (Note: Math.random() returns a double in the range of 0.0 and 1.0, therefore it is cast to an integer number, between the minimum and maximum value). [6 marks] b. Write the Bubble sort method to sort array a into descending order. [10 marks] c. In the quicksort, an algorithm an element is chosen from the unsorted list. This element is called the…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Good Essays

    Nt1330 Unit 1 Assignment 1

    • 4614 Words
    • 19 Pages

    A ______ is rectangular area that can contain a document, program, or message option1 A __________ contains icon buttons that access frequently used commands A __________ provides access to features of the program A built-in tool that performs calculations automatically is a(an) A collection of related data that has been entered into a computer is called a A collection of separate software applications that are sold as a group, like Microsoft Office, is called a(n) A database sort directs the software to find and display one or more records option2 option1 option3 option3 option4 option2…

    • 4614 Words
    • 19 Pages
    Good Essays
  • Powerful Essays

    Pt1420 Unit 1 Assignment 2

    • 1305 Words
    • 6 Pages

    Hosch, L., Liesandthem, G., Luebring, J.E., Pallardy, R., Young, G. (2014). Java. In Encyclopedia Britannica.…

    • 1305 Words
    • 6 Pages
    Powerful Essays
  • Powerful Essays

    Searching and Sorting Streams and Files Graphics GUI Components and Events Mouse, Keyboard, Sounds, and Images Big-O Analysis of Algorithms The Java Collections Framework Lists and Iterators Stacks and Queues Recursion Revisited Binary Trees Lookup Tables and Hashing Heaps and Priority Queues Design Patterns…

    • 3908 Words
    • 16 Pages
    Powerful Essays
  • Good Essays

    6. Data hiding, which means that critical data stored inside the object is protected from code outside the object is accomplished in Java by _____.…

    • 1518 Words
    • 7 Pages
    Good Essays
  • Good Essays

    Chapter 8 Quiz

    • 469 Words
    • 2 Pages

    4. Which is the simplest search technique to use to find an item in an array? (Points : 7)…

    • 469 Words
    • 2 Pages
    Good Essays
  • Good Essays

    5. The double equal sign (==) is the symbol used to represent Java's equal to operator.…

    • 719 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Unit 1 Assignment 1

    • 465 Words
    • 2 Pages

    Keyboard map= Information that matches the key (or key combination) that exists on a keyboard to some matching binary code so that the keyboard can tell the computer specifically what key(s) were just pressed.…

    • 465 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Prg420 Syllabus

    • 1691 Words
    • 7 Pages

    Horton, I. (2005). Ivor Horton’s Beginning Java 2, JDK (5th ed.). Indianapolis, IN: Wiley Publishing.…

    • 1691 Words
    • 7 Pages
    Satisfactory Essays
  • Good Essays

    Express the set using the roster method. To do that, first translate into English what this mathematical expression states. Then list the elements of this set in roster form. Explain how you arrived at your answer.…

    • 2403 Words
    • 10 Pages
    Good Essays
  • Good Essays

    From the years of 1861-1865 the bloodiest war was fought between the North and South, for the reuniting of the two nations, and to hopefully resolve the conflict of slavery. Even though the war lead to many casualties and violent actions, and ultimately the end of legal slavery, the time period after the war ended up being a disappointment to many. Reconstruction was meant to bring the nation back together, and for the United States to refurbish the former slave, and rebellious population. While this goal may have been attainable with President Abraham Lincoln, his death signaled the beginning of a difficult time. His successor, Andrew Johnson, was in fact racist, and therefore did not support the Reconstruction goals of African American…

    • 1029 Words
    • 5 Pages
    Good Essays
  • Good Essays

    To develop a date class in java similar to the one in java.util.package using java doc commands.…

    • 1459 Words
    • 6 Pages
    Good Essays
  • Powerful Essays

          Karsten builds elegant Swing apps works with Objects since 1990 helps others with UI and architectures provides libraries that complement Swing provides examples for Swing architectures writes about Java desktop issues…

    • 2893 Words
    • 12 Pages
    Powerful Essays
  • Good Essays

    Java Programming

    • 1974 Words
    • 8 Pages

    Let us begin with a simple Java program that displays the message "Welcome to Java!" on the console. The program is shown in Listing 1.1.…

    • 1974 Words
    • 8 Pages
    Good Essays
  • Powerful Essays

    Intro to Java Netbeans

    • 2703 Words
    • 11 Pages

    A computer is a machine. Humans need to provide instructions to computers to operate. Providing instructions to a computer is called “Programming”.…

    • 2703 Words
    • 11 Pages
    Powerful Essays