Histogram Demo and Design Example using Java.io and Generic Collection Libraries, Lecture notes of Programming Languages

A lecture note from CIS1200 course at a university. It contains an announcement about a homework, a bonus lecture, and a design exercise using java.io and the generic collection libraries. The design exercise is about writing a program that calculates the frequencies of each distinct word of a text file and prints the frequency distribution to the console as a sequence of “word: freq” pairs (one per line). The document also explains how to produce a stream of words by iterating through the text file and identifying all of the words.

Typology: Lecture notes

2021/2022

Uploaded on 05/11/2023

christina
christina 🇺🇸

4.6

(23)

393 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programming Languages
and Techniques
(CIS1200)
Lecture 32
Histogram Demo
Chapter 28
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Histogram Demo and Design Example using Java.io and Generic Collection Libraries and more Lecture notes Programming Languages in PDF only on Docsity!

Programming Languages

and Techniques

(CIS1200)

Lecture 32

Histogram Demo

Chapter 28

Announcements (1)

• HW07: PennPals

– Due tomorrow at 11.59pm

• This Week

  • No recitations this week
  • TA OH on Monday and Tuesday are virtual
  • OH on Wednesday are cancelled
  • No lecture on Friday

• Wednesday, November 23

rd

– Bonus Lecture

  • Only 10:15 AM class
  • Material is not needed for HW or Exams
  • Should be fun!

HW9: Game project

• Game Design Proposal Milestone Due: (8 points)

Tuesday, November 29

th

at 11:59PM

  • (Should take about 1 hour)
  • Submit on GRADESCOPE
  • TAs will give you feedback soon

• Final Program Due: (92 points)

Monday, December 12

th

at 11:59pm

  • Submit zipfile online, submission only checks if your code compiles
  • IntelliJ is STRONGLY recommended for this project
  • May distribute your game (after the deadline) if you do not use any of our code

• Grade based on demo with your TA during/after reading days

  • Grading rubric on the assignment website
  • Recommendation: don’t be too ambitious.

• NO LATE SUBMISSIONS PERMITTED

HW9: Game Project

Problem Statement

Write a program that, given a filename for a text file as input, calculates the frequencies ( i.e. , number of occurrences) of each distinct word of the file. The program should then print the frequency distribution to the console as a sequence of “word: freq” pairs (one per line).

  • The : Histogram result:
  • Write :
  • a :
  • as :
  • calculates :
  • command :
  • console :
  • distinct :
  • distribution :
  • e :
    • each :
    • file :
    • filename :
    • for :
    • freq :
    • frequencies :
    • frequency :
    • given :
    • i :
    • input :
      • line :
      • number :
      • occurrences :
      • of :
      • one :
      • pairs :
      • per :
      • print :
      • program :
      • sequence :
        • should :
        • text :
        • that :
        • the :
        • then :
        • to :
        • word :

How to produce a stream of words?

1. How do we iterate through the text file, identifying all of the

words?

• Key idea: Define a class (WordScanner) that implements this

interface by reading words from a text file.

public interface Iterator { // returns true if the iteration has more elements public boolean hasNext(); // returns the next element in the iteration public T next(); // Optional: removes last element returned public void remove(); }

Coding: Histogram.java

WordScanner.java

Histogram.java

public class WordScanner implements Iterator { private Reader r; private int c = - 1; // ... } Which combination of the following properties form a useful invariant for the WordScanner fields?

  1. r is not null
  2. r is null if and only if there is no next word A. c is 0 if there is no next word and nonzero otherwise B. c is - 1 if there is no next word and contains the first character of the next word otherwise ANSWER: 1 & B