Project #6 CMSC 131
Due Saturday 4/15/06 at 11:00 PM Object-Oriented Programming I
Type of Project: Closed Spring 2006

Objective

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

Overview

For this project 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. 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 project will be graded as follows: 70% (Implementation), 20% (Design), 10% (Style)

Specifications

Program Overview

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

The Name class

We wrote this class for you.  Please familiarize yourself with the implementation, provided.  You will certainly make use of the following methods:

What you must implement, in a nutshell

You must design and implement a working solution to this problem!  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.  (More specific instructions are in that file.)  Don't forget to complete the design.txt file -- this is 20% of your grade on the project!  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 project 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 project. 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. 

Hint:  Your CompanyDatabase class should have two private fields:  One for the list of customers, and one for the list of software products.  THESE FIELDS SHOULD NOT BE ARRAYS.  It is strongly recommended that you write one or more list classes -- see the example below.

Example:

/*  OKAY IMPLEMENTATION */

 

class CompanyDatabase {

   private CustomerList customers;    // The CustomerList class contains an array

   ...                                // of Customer objects.

}
 

          /*  INCORRECT IMPLEMENTATION */

class CompanyDatabase {

   private Customer[] customers;     // Do NOT do this!

   ...

}

 

Required Classes

You must implement and use the following classes:

Customer

This class represents a customer. A customer is identified by a name, email address, and an array 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 address, and software products. We leave it up to you as to which methods you must define for the Customer class.  (You must use the Name class to store the names of the customers.)

CompanyDatabase

This class represents the database.  The methods' prototypes and behaviors are defined next. You must not change the following methods' prototypes or add any other public 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 if the software product was already in the database.  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. So that we can refer to this list later, we'll call this list 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 in the case where the customer's software list is empty:

      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 new line. We refer to this list as the CustomerStringList (we'll refer to it again later by this name).

    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 other versions of the software.  (The idea is that the company could use this mailing list 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.  For example, we recommend you implement a class called Software which represents a software product, and as mentioned previously, you should be writing one or more "list classes" to hold customers and/or software products.

Requirements/Assumptions

Design Documentation

Complete the design.txt file you will find in the code description.  (Specific instructions can be found in that file.)

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.


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