Homework #6 CMSC 131
Due Monday April 11, 6:00 pm Object-Oriented Programming I
Type of Homework: Closed Spring 2004

Objective

This homework will give you practice designing object-based solutions to problems. In addition, it will allow you to practice using arrays of references and javadoc documentation.

Warning, please read: This homework requires a significant amount of work and it could be considered the toughest homework assignment of the course. We encourage you to start working on it immediately. Office hours get extremely busy a few days before the project is due and you may not receive the assistance you need if you delay working on this project. Keep in mind that the submit server cannot test your submission instantaneously and in some cases it can take several minutes (or hours) to process the test suite. If you wait until the last minute to submit your project, you may not be able to verify the results generated by your project. Remember that we use the submit server results to compute your project score.

Overview

For this homework you will implement a very simple database system for a Software company. Your program will allow the company to keep track of customers and different types of software the company develops. Unlike previous homework assignments, we will not provide any support infrastructure for this project. You will design and implement all the classes needed to complete the database application. You may want to take a look at the Sample Run section before you read the detailed description.

This homework will be graded as follows: 65% (Implementation), 20% (Design), 10% (Style), 5% (Time log)

Specifications

Program Overview

You will write a program that enables a software company to keep track of the its customers and the software products it develops. The program will handle the following tasks:

What you must implement, in a nutshell

You must design and implement a solution to the database application. The design will include documentation for each of the classes that are part of the application and the methods for each class. You are expected to design your own classes for representing the basic entities that the program manipulates. You will document your design in the design.txt file, which is part of the code distribution. After completing your design, you will implement it. The number of classes you decide to use is up to you; however, you must follow the set of restrictions specified below.

Code Distribution

Before you read these specifications, you should access the files associated with this homework by checking out the project named p6. The code distribution provides you with the following:

Database Representation

The database application will be represented using two lists:

How you represent these lists is part of your design. You may follow any approach you deem necessary as long as it adheres to the specifications of the homework. Note that you will not use any sorting algorithm in this project. For example, you will keep your customer list sorted by inserting elements in the appropriate position in the list.

Required Classes

You must implement and use the following classes:

Customer

This class represents a customer. A customer is identified by a name, email, and an array (list) of Software products licensed to the customer. As is the case for the software products lists (for the overall database application), the customer's software list does not need to be sorted and elements are added to the end. The Customer class should include appropriate instance variables for the name, email, and software products. We leave it up to you as to which methods you must define for the Customer class.

CompanyDatabase

This class represents the database application. Access to the database application made is through this class. The methods' prototypes and behaviors are defined next. You must not change the following methods' prototypes or add any other methods.

  1. Methods (all are public methods)
    1. addSoftware: Adds a software product to the company's software list. Remember that this list is not sorted and new software products are added to the end of the list. The method's prototype is:

      public boolean addSoftware(String name, String version, String code);

      The name parameter represents the software's name. The version parameter provides a version tag and the code parameter represents the code for this software (yes, it is an open software company ☺). The code is simply a collection of characters (any characters representing a computer program), e.g., "int main() { }" This method will return true if the add operation was completed successfully and false otherwise. Keep in mind that a software product is uniquely identified by the combination of name and a version number.

    2. findSoftware: Returns a String with information about a particular software product or null if the software is not part of the database. The method's prototype is:

      public String findSoftware(String name, String version);

      The format of the String to return is:

      SoftwareString "Software Name: " name "|Version: "version"|Code: " code

      where name, version, and code correspond to the software's name, version and code respectively. For example:

      Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }

    3. getSoftwareList: Returns a String with the company software products or null if no products are available. The method's prototype is:

      public String getSoftwareList();

      The format of the String to be returned is a sequence of SoftwareString each on a line by itself. We refer to this list as the SoftwareStringList.

    4. addCustomer: Adds to the database the customer whose name and e-mail address are specified in the parameters. The method's prototype is:

      public boolean addCustomer(String name, String email);

      The collection of customers is kept sorted by customer name (according to the order determined by the Name class). For example, Rose Johnson will appear before Albert Smith. The method will return true if the add operation was successful and false otherwise (e.g., if the customer is already part of the database).

    5. findCustomer: Returns a String with information about a customer or null if the customer is not part of the database. The method's prototype is:

      public String findCustomer(String name);

      The format of the String to return is one of the following:

      CustomerString

        "Name: "name", Email: "address
        "Software List:"
        SoftwareStringList

      OR

      CustomerString

        "Name: "name", Email: "address
        "Software List: None"

    6. removeCustomer: Removes the customer with the specified name from the database. The method's prototype is:

      public boolean removeCustomer(String name);

      Returns true if the remove operation was successful and false otherwise (e.g., the name is not found).

    7. getCustomerList: Returns a String with the customers that are part of the database or null if no customers are present. The method's prototype is:

      public String getCustomerList();

      The format of the String to be returned is a sequence of CustomerString each on a line by itself. We refer to this list as the CustomerStringList.

    8. licenseSoftwareToCustomer: Licenses the specified software to the customer. The software is added to the list of software products the user keeps. The method's prototype is:

      public boolean licenseSoftwareToCustomer(String customerName, String softwareName, String softwareVersion);

      The method returns true if the software is licensed successfully and false otherwise (e.g., the customer doesn't exist or the software is not in the Software Products list).

    9. newSoftwareVersion: Adds the specified software version to the list of software products associated with the company. You can assume that whoever calls this method must verify there is already a previous version of the software in the company's software products list. The method's prototype is:

      public String[] newSoftwareVersion(String name, String version, String code);

      Besides adding the software, the method returns an array of e-mail addresses. These e-mail addresses represent the customers that have previous versions of the software. This mailing list can be used to notify users of the availability of the update. The method will return null if there are no customers to notify. Note: The customers' software is not updated by this method.

    10. toString: Returns a String with the all the software products in the database followed by all the customers in the database. The method's prototype is:

      public String toString();

      The format of the String to return is the following:

      DatabaseString

        "**** Company's Software ****"
        SoftwareStringList
        "**** Company's Customers ****"
        CustomerStringList

      If any of the lists is empty then only the corresponding header will appear.

Additional Classes

As part of your design you will need to define classes in addition to the ones described above. Think carefully about the classes you will need. A good design can simplify dramatically the amount of time you will spend implementing your design. We recommend you implement a class called Software which represents a software product.

Requirements/Assumptions

Design Documentation

Complete the design.txt file you will find in the code description.

As mentioned above, you are to provide javadoc documentation for one of your classes, and will indicate which class in your design.txt file. You should not provide the html files generated by the javadoc utility with your submission. We will generate the files ourselves.

To run Javadoc from Eclipse, select the file, right click, and select "Export → Javadoc". The first time you attempt to do this, Eclipse will ask you to specify the location of your javadoc executable. This file will be located in your Java j2sdk directory, within its bin directory. For example, on a typical Windows machine, this might be:

On a typical Unix/MacOS machine the file will likely just be called "javadoc", and again will be in the Java sdk directory.

Remember to store the javadoc files outside your workspace. When exporting javadoc it will ask you for the "Destination" to store the javadoc documentation files. Please specify a directory that is outside of your Eclipse Workspace, so it does not affect your submission. If you see some directories with the "doc" prefix in your project workspace then you have not specified an appropriate "Destination".

Sample Run

At the end of this page you will find a class ExampleDriver.java and the output that it produces. Access to the database application is through the CompanyDatabase class you will implement. The class ExampleDriver.java can be found in the code distribution.


Challenge Problem

Remember that you are not required to implement the following problem. Please visit the course web page for information regarding challenge problems. IMPORTANT: If you decide to complete the challenge problem you must provide its implementation in the file called Challenge.java. Remember to define a main method in the Challenge class that allow us to run your program.

The challenge problem consists of defining a GUI for the database software application. The GUI should allow a user to complete all the tasks associated with the CompanyDatabase class. Feel free to define your interface as you understand is best. Keep in mind that a GUI based on JOptionPane is considered a valid GUI although you may not receive the maximum number of gold stars.

IMPORTANT: Make sure that your Challenge class has a default constructor.


Submission

Submit your project using the submit project option associated with Eclipse. Make sure that the submit server generates the expected results.


ExampleDriver.java

(This is provided in the code distribution.)

public class ExampleDriver {
	
    public static void addSoftware(CompanyDatabase companyDatabase,
            			   String name, String version, String code) {
        System.out.println("Adding software: \"" + name + "\"");
        companyDatabase.addSoftware(name, version, code); 
        System.out.println(companyDatabase + "\n");
    }
 
    public static void addCustomer(CompanyDatabase companyDatabase,
			   	   String name, String email) {
        System.out.println("Adding customer: " + name);
        companyDatabase.addCustomer(name, email);  
        System.out.println(companyDatabase + "\n");
    }
    
    public static void main(String[] args) {        
        String results = "", info;
        CompanyDatabase companyDatabase = new CompanyDatabase();
        
        /* An empty database */
        System.out.println("Initial database with no data");
        System.out.println(companyDatabase + "\n");
        
        /* Adding some software and printing the database status after each add */
        addSoftware(companyDatabase, "VPNS", "1.0", "int main() {// VPNS implementation }");
        addSoftware(companyDatabase, "Ninux", "2.0", "public static void main(String a){//Ninux implementation}");
        addSoftware(companyDatabase, "FireDog", "1.5", "int main() {// FireDog implementation }");
        
        /* Adding some customers and printing the database status after each add */
        addCustomer(companyDatabase, "Isaac Newton", "gravity@it.falls.com");
        addCustomer(companyDatabase, "Albert Einstein","relativity@physics.smart.out" );
        addCustomer(companyDatabase, "Marie Curie","lovePhysics@great.science.com" );
  
        /* Printing software and customer's lists */
        System.out.println("***Software Collection***\n" + companyDatabase.getSoftwareList() + "\n");
        System.out.println("***Customers ***\n" + companyDatabase.getCustomerList() + "\n");
        
        /* Look up operations */
        System.out.println("***Looking for a \"Ninux\" software");
        if ((info = companyDatabase.findSoftware("Ninux", "2.0")) != null)
            System.out.println(info + "\n");
        
        System.out.println("***Looking for a customer \"Marie Curie\"");
        if ((info = companyDatabase.findCustomer("Marie Curie")) != null)
            System.out.println(info + "\n");
            
        /* Assigning software to customer */
        System.out.println("***Licensing \"Ninux\" software to Isaac Newton");
        companyDatabase.licenseSoftwareToCustomer("Isaac Newton", "Ninux", "2.0");
        System.out.println(companyDatabase + "\n");
        
        System.out.println("***Licensing \"FireDog\" software to Isaac Newton");
        companyDatabase.licenseSoftwareToCustomer("Isaac Newton", "FireDog", "1.5");
        System.out.println(companyDatabase + "\n");
        
        System.out.println("***Licensing \"FireDog\" software to Albert Einstein");
        companyDatabase.licenseSoftwareToCustomer("Albert Einstein", "FireDog", "1.5");
        System.out.println(companyDatabase + "\n");
    
        /* Adding wew software version */
        System.out.println("***Adding new software version for FireDog");
        String[] mailingList = companyDatabase.newSoftwareVersion("FireDog", "2.0", "int main() {// FireDog update implementation }");
        System.out.println(companyDatabase + "\n");
        
        System.out.println("***Update notices for FireDog");
        if (mailingList != null) {
	        System.out.println("Update notices should be sent to:");
			for (int i=0; i<mailingList.length; i++) 
				System.out.println(mailingList[i]);   
			}
    	}
}

 


Output of ExampleDriver.java

Initial database with no data
**** Company's Software ****
**** Company's Customers ****


Adding software: "VPNS"
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
**** Company's Customers ****


Adding software: "Ninux"
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
**** Company's Customers ****


Adding software: "FireDog"
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
**** Company's Customers ****


Adding customer: Isaac Newton
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
**** Company's Customers ****
Name: Isaac Newton, Email: gravity@it.falls.com
Software List: None


Adding customer: Albert Einstein
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
**** Company's Customers ****
Name: Albert Einstein, Email: relativity@physics.smart.out
Software List: None
Name: Isaac Newton, Email: gravity@it.falls.com
Software List: None


Adding customer: Marie Curie
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
**** Company's Customers ****
Name: Marie Curie, Email: lovePhysics@great.science.com
Software List: None
Name: Albert Einstein, Email: relativity@physics.smart.out
Software List: None
Name: Isaac Newton, Email: gravity@it.falls.com
Software List: None


***Software Collection***
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }

***Customers ***
Name: Marie Curie, Email: lovePhysics@great.science.com
Software List: None
Name: Albert Einstein, Email: relativity@physics.smart.out
Software List: None
Name: Isaac Newton, Email: gravity@it.falls.com
Software List: None

***Looking for a "Ninux" software
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}

***Looking for a customer "Marie Curie"
Name: Marie Curie, Email: lovePhysics@great.science.com
Software List: None

***Licensing "Ninux" software to Isaac Newton
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
**** Company's Customers ****
Name: Marie Curie, Email: lovePhysics@great.science.com
Software List: None
Name: Albert Einstein, Email: relativity@physics.smart.out
Software List: None
Name: Isaac Newton, Email: gravity@it.falls.com
Software List:
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}


***Licensing "FireDog" software to Isaac Newton
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
**** Company's Customers ****
Name: Marie Curie, Email: lovePhysics@great.science.com
Software List: None
Name: Albert Einstein, Email: relativity@physics.smart.out
Software List: None
Name: Isaac Newton, Email: gravity@it.falls.com
Software List:
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }


***Licensing "FireDog" software to Albert Einstein
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
**** Company's Customers ****
Name: Marie Curie, Email: lovePhysics@great.science.com
Software List: None
Name: Albert Einstein, Email: relativity@physics.smart.out
Software List:
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
Name: Isaac Newton, Email: gravity@it.falls.com
Software List:
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }


***Adding new software version for FireDog
**** Company's Software ****
Software Name: VPNS|Version: 1.0|Code: int main() {// VPNS implementation }
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
Software Name: FireDog|Version: 2.0|Code: int main() {// FireDog update implementation }
**** Company's Customers ****
Name: Marie Curie, Email: lovePhysics@great.science.com
Software List: None
Name: Albert Einstein, Email: relativity@physics.smart.out
Software List:
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }
Name: Isaac Newton, Email: gravity@it.falls.com
Software List:
Software Name: Ninux|Version: 2.0|Code: public static void main(String a){//Ninux implementation}
Software Name: FireDog|Version: 1.5|Code: int main() {// FireDog implementation }


***Update notices for FireDog
Update notices should be sent to:
relativity@physics.smart.out
gravity@it.falls.com
 

Web Accessibility