-
Notifications
You must be signed in to change notification settings - Fork 21
Module 2 Implementation
Add unit test cases for all the programs. Create a text file for each program.
The file should contain all possible types of test cases with inputs and outputs.
Write a program to count words in web page content.
- List of URLs (select your own URLs for testing) provided in a text file, e.g. urls.txt
- List of words (select your own words for testing) provided in a text file, e.g. words.txt
- Place the files above in such a way that the reviewer can himself get your code and just run without having to alter the source code to adjust the path. In other words, don’t use a hardcoded path particular to your machine, instead derive the path.
- For each URL, print:
- the top 3 words on the given list
- the number of occurrences of each word
- List the words sorted by the number of occurrences in descending order.
- For each word on the given list, print the total number of occurrences across all the specified URLs. List the words sorted by the total number in descending order.
Output #1
========
cat - 12
dog - 9
bear - 7
lion - 14
tiger - 8
bear - 3
==============================
Output #2
========
lion - 14
cat - 12
bear - 10
dog - 9
tiger – 8
Write a program to implement searching and sorting operations on Employee class objects.
- Create a class Employee with following properties. The class should follow javabean standards..
- Name
- Email Address
- Age
- Date Of Birth
- Start with a large amount of comma separated data stored in a text file (employees.txt) and provide menu options on console like below -
- Add
- If selected/entered, provide following menu options for creating an employee -
- Name
- Email Address
- Age
- DOB
- Pressing enter should create a record in the file and file should be updated.
- If selected/entered, provide following menu options for creating an employee -
- Delete
- If selected, prompt to enter the employee ID that needs to be deleted. If employee ID exists, delete it from the TXT file.
- Search
- If selected, prompt for the following -
- Query (text to search)
- Sort (Order By)
- Direction (ascending or descending)
- Pressing enter should search based on the criteria and display the result on the console.
- If selected, prompt for the following -
- Add
- Use appropriate Collection classes wherever necessary and in order to perform faster search, load up all data in the Collection and perform searching/sorting operations on the Collection instead of File.
885
Write a multi threaded program that simulates bank withdrawal process by two individuals. The program should first demonstrate that the account will run overdraw if thread safety is not taken into account and then the thread safe version should demonstrate the measures taken that help protect the account balance integrity.
- Create a class Account with properties name and balance. Initialize balance with 1000 indicating the current balance in the account. Also create a method named “withdraw” that deducts passed withdrawal amount from the account balance.
- Create another class AccountOverdrawDemo with main method and demonstrate that if two threads (indicating two joint account holders with separate ATM cards) access the Account class at the same time and try to make withdrawal (call withdraw method) at the same time, account will overdraw at one point if both account holders keep withdrawing at the same time.
- Create another class AccountOverdrawSafeDemo that fixes this problem. You need to clearly demonstrate that both threads are accessing the same account at the same time and thread safety measures keep the account from overdrawing.
- Use System.out.println statements to your effect for demonstrating various information about Threads and showing the action that is being performed.
Write a program that serializes and deserializes a Student class according to the following criteria -
- Write a class Student.class with the following properties/fields -
- firstName (String)
- dateOfBirth (String)
- address (represents instance of Address class)
- Write a class Address.class with following properties/fields -
- city (String)
- State (String)
- pinCode (Integer)
- country (String)
- Write appropriate constructors for both Address.class and Student.class classes.
- Write a separate class, SerializationTest, that constructs four different Student objects, places them in a List, and then serializes the result to a file specified as command line argument. Run the program twice with different files specified (output1.ser and output2.ser)
- Write another program, DeserializationTest, that reads files containing a serialized list of Students created in previous steps and prints the serialized list of Students.. Files to be read are again specified as command line arguments (output1.ser and output2.ser).
- Change dateOfBirth type from java.lang.String to java.util.Date and change the constructor implementation accordingly. Don’t change the signature of the constructor. Just use a single parameter constructor of the Date class to assign the passed String Date to “dateOfBirth”.
- After recompiling Person, at this point you should verify the following:
- If you run DeserializationTest on either output1.ser or output2.ser you should get a runtime exception.
- If you run SerializationTest and regenerate output2.ser you will be able to read it back with DeserializationTest, but since output1.ser is in the old format, you won't be able to read that file.
- Important - Revise the Student class such that if you rerun SerializationTest to regenerate output 2.ser using the new Student format, BUT LEAVE output1.ser IN THE OLD FORMAT, you will still be able to run DeserializationTest for both files as was done before, even though there are two different Student formats.
- While implementing this part, you are only allowed to rewrite and recompile only Student class.