Project:

Skills:
Type:
Status:
JAVA Implementation of a Simple Program
Modeled by UML

JAVA Basics, UML, Software Engineering Concepts
Software Engineering Assignment 6
Completed on April 2003

Objective:

The aim of the project was to illustrate how UML diagrams are implemented using JAVA. The program keeps track of number of canes and tokens in a "Vending Machine".

Theory and Procedure:

Software engineering has five main steps:

  • Requirement elicitation
  • Analysis
  • System Design
  • Object Design and
  • Implementation.

    For complex programs each step need to be systematically followed. For the simple vending machine program the implementation of its object model is sufficient. Universal Modeling Language(UML) are tools such as diagrams, and standards that model a given program. The UML object diagram for Vending Machine is as follows:


    Class Implementation:
    Class VendingMachine
    {         	
    	public static int totalCans;
    	public static int totalTokens;
    	
    	VendingMachine()     //Constructors
    	{
    	totalCans=10;
    	totalTokens=0;
    	}
    	VendingMachine(int cans)
    	{
    	totalCans=cans;     
    	totalTokens=0;
    	}                             
    	                            
    	void fillUp(int cans)     //Methods
    	{
    	totalCans=totalCans+cans;
    	}
    	
    	void insertToken()
    	{
    	totalCans=totalCans - 1;
    	totalTokens=totalTokens + 1;   
    	}    
    	
    	int getTokenCount()
    	{
    	return totalTokens;      
    	}
    	
    	int getCanCount()
    	{
    	return totalCans;
    	}
    }
    


    Object Implementation:
    class VendingMachineTest
    {  
      	 public static void main(String args[ ])
      	 {           
          	VendingMachine vendingMachine1 = new VendingMachine(0); 
          	vendingMachine1.fillUp(10);    
          	vendingMachine1.insertToken();  
          	vendingMachine1.insertToken();
            	System.out.println("Token count = " + 
    		vendingMachine1.getTokenCount());
            	System.out.println("Can count = " + 
    		vendingMachine1.getCanCount());
         	 }                                             
    }
    


    Result: