Java Network Programming

Assignment 1.

Due: Monday, January 16th at midnight

Submission Instructions

 

Question 1.

Write a program which takes a number and a word on the command line, and then prints out the given word that number of times.

 

      ie:

 

      $> java repeater 5 hi

      hi

      hi

      hi

      hi

      hi

 

      $> java repeater hi 5

      Error: Usage: java repeater number word

 

      You should be using the classes: java.lang.String, java.lang.Integer, and java.lang.NumberFormatException

 

 

Question 2.

 

Part 1.

 

Create a class Person.  Override Object's toString method to print it's name.

Create an interface RPIPerson that has a method getIDNumber();

Create a class Student that extends person and implements RPIPerson. The Student should have a year, that should be printed out when the object is printed using toString().

Create a class Professor that extends person and implements RPIPerson.  The Professor should have a department, represented by a String.

 

Part 2.

Using the main file available here, add the students and professors to a java.util.Vector.  Then, using java.util.Enumeration, go through each element of the Vector and print out information about the students.

Also using Enumeration, print out the id numbers by casting the return of .nextElement() to RPIPerson.

 

Part 3.

 

Have your Person class implement java.lang.Comparable, and order people based on ID Numbers.

Use java.util.Arrays and the Vector you created in Part 2 to print the sorted list.

 

Part 4.

Put your Person, RPIPerson, Studnent, and Professor classes into a package called “people”.  Make the program compile and run again.  Make sure to remove your old .class files for those classes.