Software Engineering Design and Analysis-ITECH3201

ITECH3201 –

Assignment Requirements

Step 1 – Rename the base code

1. Download the code from Moodle and unzip it in the filesystem

2. Rename the base folder to “Assignment 1 – yourid” (your id equals your student number)

3. Open the solution up in Visual Studio right click on the Solution and rename it as per (2)

4. Build the solution and inspect the output. Spend some time becoming familiar with the code before you do anything else.

Step 2 – Identify “code smells”

Open up a new document in Word (or equivalent), start documenting any code smells you identify in the code in point form. You might want to cut and paste the code into Word to illustrate the problems.

Step 3 – Create a class diagram of the initial code.

Do this in Enterprise Architect and copy the resultant diagram into your Word file. Ensure your EA file is saved and labelled as “starting code base”.

Step 4 – Refactor and unit test code

Ensure that your starting code and EA file is backed up. Once this is done, commence refactoring the code in Visual Studio. Document each change you make and provide an explanation of why you have done so.

Your final code should be fully refactored and have unit tests developed for every method (other than ToString and Get and Set methods). These unit tests should be documented to demonstrate the results before and after the changes to confirm that the functionality of the code has not changed.

Step 5 – Add additional functionality

Add and unit test new functionality to the application as per the description below.

1) ShowBiz Inc offers membership discounts on the performance fees to members of its VIP club. These discounts are:

 Annual Members: 10%

 Corporate Sponsors: 15%

 Life Members: 20%

Update the code base to implement this functionality. No discount is offered to clients who are not members of the VIP club.

Step 6 – Create diagrams of the final code.

Do this in Enterprise Architect and copy the resultant diagram into your Word file. Create a class diagram of the final code, and a sequence diagram showing how a new ticket reservation request is processed in the final code. Ensure your EA file is saved and labelled as “final code base”.

Software engineering design and analysis

Student ID:

Student Name:

University Name:

1. Indentifying the code smells

The indentified code smells are listed below according to their criteria.

Long method in class ShowBizInc:

public void setupLocation()

        {

            thisVenue = new Venue(“Arts Centre Ballarat”);

            ArrayList newShow1 = new ArrayList();

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(80, “A” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(80, “B” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(80, “C” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(60, “D” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(60, “E” + i));

            }

            ArrayList newShow2 = new ArrayList();

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(75, “A” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(75, “B” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(60, “C” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(50, “D” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(50, “E” + i));

            }

            ArrayList newShow3 = new ArrayList();

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(100, “A” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(80, “B” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(80, “C” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(70, “D” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(70, “E” + i));

            }

            ArrayList newShow4 = new ArrayList();

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(75, “A” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(75, “B” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(50, “C” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(50, “D” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(40, “E” + i));

            }

            ArrayList newShow5 = new ArrayList();

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(80, “A” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(80, “B” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(80, “C” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(60, “D” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(60, “E” + i));

            }

            ArrayList newShow6 = new ArrayList();

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(100, “A” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(100, “B” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(80, “C” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(80, “D” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(80, “E” + i));

            }

            ArrayList newShow7 = new ArrayList();

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(60, “A” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(60, “B” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(50, “C” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(50, “D” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(50, “E” + i));

            }

            thisVenue.addPerformance(“Mary Poppins Jan 16 8pm”, newShow1);

            thisVenue.addPerformance(“The Sound of Music Jan 17 8pm”, newShow2);

            thisVenue.addPerformance(“Grease Jan 19 2pm”, newShow3);

            thisVenue.addPerformance(“Camp Rock Jan 20 2pm”, newShow4);

            thisVenue.addPerformance(“Oklahoma Jan 20 8pm”, newShow5);

            thisVenue.addPerformance(“Symphony Orchestra Jan 21 2pm”, newShow6);

            thisVenue.addPerformance(“Comedy Festival Jan 22 7pm”, newShow7);

        }

Complex if-Else:

            ArrayList performances;

  if (performance.Equals(“Mary Poppins Jan 16 8pm”,  StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Mary Poppins Jan 16 8pm”);

else if (performance.Equals(“The Sound of Music Jan 17 8pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“The Sound of Music Jan 17 8pm”);

 else if (performance.Equals(“Grease Jan 19 2pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Grease Jan 19 2pm”);

 else if (performance.Equals(“Camp Rock Jan 20 2pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Camp Rock Jan 20 2pm”);

 else if (performance.Equals(“Oklahoma Jan 20 8pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Oklahoma Jan 20 8pm”);

 else if (performance.Equals(“Symphony Orchestra Jan 21 2pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Symphony Orchestra Jan 21 2pm”);

 else if (performance.Equals(“Comedy Festival Jan 22 7pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Comedy Festival Jan 22 7pm”);

  else

                performances = thisVenue.getPerformance(“Mary Poppins Jan 16 8pm”);

Class diagram of initial code

3. The refractor and unit test

3.0 Code before changes:

public void setupLocation()

        {

            thisVenue = new Venue(“Arts Centre Ballarat”);

            ArrayList newShow1 = new ArrayList();

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(80, “A” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(80, “B” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(80, “C” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(60, “D” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow1.Add(new Seat(60, “E” + i));

            }

            ArrayList newShow2 = new ArrayList();

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(75, “A” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(75, “B” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(60, “C” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(50, “D” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow2.Add(new Seat(50, “E” + i));

            }

            ArrayList newShow3 = new ArrayList();

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(100, “A” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(80, “B” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(80, “C” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(70, “D” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow3.Add(new Seat(70, “E” + i));

            }

            ArrayList newShow4 = new ArrayList();

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(75, “A” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(75, “B” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(50, “C” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(50, “D” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow4.Add(new Seat(40, “E” + i));

            }

            ArrayList newShow5 = new ArrayList();

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(80, “A” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(80, “B” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(80, “C” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(60, “D” + i));

            }

            for (int i = 0; i < 10; i++)

            {

                newShow5.Add(new Seat(60, “E” + i));

            }

            ArrayList newShow6 = new ArrayList();

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(100, “A” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(100, “B” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(80, “C” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(80, “D” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow6.Add(new Seat(80, “E” + i));

            }

            ArrayList newShow7 = new ArrayList();

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(60, “A” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(60, “B” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(50, “C” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(50, “D” + i));

            }

            for (int i = 0; i < 15; i++)

            {

                newShow7.Add(new Seat(50, “E” + i));

            }

            thisVenue.addPerformance(“Mary Poppins Jan 16 8pm”, newShow1);

            thisVenue.addPerformance(“The Sound of Music Jan 17 8pm”, newShow2);

            thisVenue.addPerformance(“Grease Jan 19 2pm”, newShow3);

            thisVenue.addPerformance(“Camp Rock Jan 20 2pm”, newShow4);

            thisVenue.addPerformance(“Oklahoma Jan 20 8pm”, newShow5);

            thisVenue.addPerformance(“Symphony Orchestra Jan 21 2pm”, newShow6);

            thisVenue.addPerformance(“Comedy Festival Jan 22 7pm”, newShow7);

        }

3.0 Code after changes:

            while (c<7)

            {

            for (int i = 0; i < 5; i++)

            {

                for (int j = 0; j < 10; j++)

                {

                    ArrayList co =(ArrayList) collection[c];

                    co.Add(new Seat(numbers[c,i], names[i] + j));

                }

            }

            c++;

            }

3.0 Justification:

The long methods are very complicated and it’s have duplicate codes more easily than small methods. Therefore it is better to have many small methods instead of long methods. Small methods are more descriptive names and it’s very much easier to understand at a quick look. The small methods are not more than 10 lines in this block of code. Therefore it’s better to break this method into several small methods.

Output before changes

Output after Changes

3.1 Code before changes:

            ArrayList performances;

  if (performance.Equals(“Mary Poppins Jan 16 8pm”,  StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Mary Poppins Jan 16 8pm”);

else if (performance.Equals(“The Sound of Music Jan 17 8pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“The Sound of Music Jan 17 8pm”);

 else if (performance.Equals(“Grease Jan 19 2pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Grease Jan 19 2pm”);

 else if (performance.Equals(“Camp Rock Jan 20 2pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Camp Rock Jan 20 2pm”);

 else if (performance.Equals(“Oklahoma Jan 20 8pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Oklahoma Jan 20 8pm”);

 else if (performance.Equals(“Symphony Orchestra Jan 21 2pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Symphony Orchestra Jan 21 2pm”);

 else if (performance.Equals(“Comedy Festival Jan 22 7pm”, StringComparison.OrdinalIgnoreCase))

                performances = thisVenue.getPerformance(“Comedy Festival Jan 22 7pm”);

  else

                performances = thisVenue.getPerformance(“Mary Poppins Jan 16 8pm”);

3.1 Code after changes:

            switch(performance)

            {

       case “Mary Poppins Jan 16 8pm”: performances = thisVenue.getPerformance(“Mary Poppins Jan 16 8pm”);

       break;

       case “The Sound of Music Jan 17 8pm”: performances = thisVenue.getPerformance(“The Sound of Music Jan 17 8pm”);

       break;

       case “Grease Jan 19 2pm”: performances = thisVenue.getPerformance(“Grease Jan 19 2pm”);

        break;

        case “Camp Rock Jan 20 2pm”: performances = thisVenue.getPerformance(“Camp Rock Jan 20 2pm”);

        break;

        case “Oklahoma Jan 20 8pm”: performances = thisVenue.getPerformance(“Oklahoma Jan 20 8pm”);

        break;

        case “Symphony Orchestra Jan 21 2pm”: performances = thisVenue.getPerformance(“Symphony Orchestra Jan 21 2pm”);

        break;

        case “Comedy Festival Jan 22 7pm”: performances = thisVenue.getPerformance(“Comedy Festival Jan 22 7pm”);

         break;

         default:performances = thisVenue.getPerformance(“Mary Poppins Jan 16 8pm”);

                    break;

            }

3.1 Justification:

A complex if-elseif-elseif-else sometimes creates some issues and its very complex pattern the same things use over and over. There are two techniques to eliminate this code smell switch case or delegate mapping.

Output before changes1

Output after Changes1

4. Additional functionality

if (available(performances, number))

            {

                ArrayList reservedTickets = new ArrayList();

                int currentSeat = 0;

                int reservationFee = 0;

                while (number > 0)

                {

                    Seat thisSeat = (Seat)performances[currentSeat];

                    if (!thisSeat.reserved)

                    {

                        reservedTickets.Add(thisSeat);

                        reservationFee += thisSeat.ticketPrice;

                        thisSeat.reserved = true;

                        number–;

                    }

                    currentSeat++;

                }

                return new Reservation(theClient, reservationFee, reservedTickets);

            }

            else

            {

                return new Reservation(theClient, false);

            }

        }

        public Boolean available(ArrayList performances, int number)

        {

            int availableCount = 0;

            for (int i = 0; i < performances.Count; i++)

            {

                if (!((Seat)performances[i]).reserved)

                    availableCount++;

            }

            return number <= availableCount;

        }

        public void memberDiscount(Client c)

        {

            Client obj = new Client();

        }

Class diagram of the final code

Sequence diagram of the ticket reservation system

new

new1

Bibliography

Ahlawat, A. (2015). Implementing SAAS: Cloud Computing and Android Based Application Framework for .NET Programming.

Ali, R. (2015). C#: C# For Beginners Crash Course Master C# Programming Fast and Easy Today.

Batool, A., ur Rehman, M. H., Khan, A., & Azeem, A. (2015). Impact and Comparison of Programming Constructs on JAVA and C# Source Code Readability.

Beebe, N. H. (2015). A Bibliography of Publications about the C# Programming Language.

Cui, Y., Lu, Z., Lu, H., Li, J., Wang, Y., & Huang, L. (2015). A Parallel Processing Strategy of Large GNSS Data Based on Precise Point Positioning Model. In China Satellite Navigation Conference (CSNC) 2015 Proceedings: Volume III (pp. 139-147). Springer Berlin Heidelberg.

D’Angelo, J. N., Dey, S., Gorski, J., Moyer, E. T., Mackenna, A., & Strawn, R. (2016). The CREATE Program: Design and Analysis Tools for DoD Weapon Systems.

Fougères, A. J., & Ostrosi, E. (2016). Multiple Fuzzy Roles: Analysis of Their Evolution in a Fuzzy Agent-Based Collaborative Design Platform. InComputational Intelligence (pp. 207-225). Springer International Publishing.

Gabsi, W., & Zalila, B. (2016). Towards a Model Level Replication Technique for Fault Tolerant Systems Using AADL. In Software Engineering, Artificial Intelligence, Networking and Parallel/Distributed Computing 2015 (pp. 159-175). Springer International Publishing.

Garousi, V., Coşkunçay, A., Demirörs, O., & Yazici, A. (2016). Cross-factor analysis of software engineering practices versus practitioner demographics: An exploratory study in Turkey. Journal of Systems and Software111, 49-73.

Graves, D. (2015). Promoting Computer Science with Video Games: Teaching Object-Oriented Programming through Unity (Doctoral dissertation, California Polytechnic State University San Luis Obispo, CA).

Heaton, J. (2015). Encog: Library of Interchangeable Machine Learning Models for Java and C#. arXiv preprint arXiv:1506.04776.

Hurlburt, G., & Voas, J. (2016). Software is Driving Software Engineering?.Software, IEEE33(1), 101-104.

Johnson, A., Kong, X., & Ritchie, J. (2016). Determination of the Workspace of a Three-Degrees-of-Freedom Parallel Manipulator Using a Three-Dimensional Computer-Aided-Design Software Package and the Concept of Virtual Chains. Journal of Mechanisms and Robotics8(2), 024501.

Kang, H., Wang, Y., & Zhou, S. (2015, April). Fuzzy Optimization Research of Product Design Improvement Based on C#. In 2015 International Conference on Advances in Mechanical Engineering and Industrial Informatics. Atlantis Press.

Kushal, K. S., Nanda, M., & Jayanthi, J. (2016). Resource Management and Performance Analysis of Model-Based Control System Software Engineering Using AADL. In Computational Intelligence in Data Mining—Volume 2 (pp. 81-96). Springer India.

Maozeng, X., & Guoyin, Y. (2015). Implementation of Logistics Demand Forecasting System Based on Hybrid Programming with C# and MATLAB.Journal of Chongqing Jiaotong University (Natural Science)4, 025.

Post, D. E., Atwood, C. A., Newmeyer, K. P., Meakin, R. L., Hurwitz, M. M., Dey, S., … & Goldfarb, O. A. (2016). CREATE: Software Engineering Applications for the Design and Analysis of Air Vehicles, Naval Vessels, and Radio Frequency Antennas. Computing in Science & Engineering18(1), 14-24.

Potena, P., Crnkovic, I., Marinelli, F., & Cortellessa, V. (2016). Software Architecture Quality of Service Analysis Based on Optimization Models. InIntelligent Decision Making in Quality Management (pp. 421-446). Springer International Publishing.

Ramírez, C. S., Hernández, G. A., Alcaraz, J. L. G., & Mendoza, D. A. T. (2016). The Use of Simulation Software for the Improving the Supply Chain: The Case of Automotive Sector. In Trends and Applications in Software Engineering (pp. 213-222). Springer International Publishing.

Shaukat, K., Akram, H. J., Tariq, S., Ali, S., & Ghani, U. (2015). Web Based Programming Languages that Support SELENIUM Testing. International Journal of Applied Sciences and Innovation2015(1).

Zuo, Z. K., Wang, C. J., Shi, H. H., You, Z., Xie, W. P., & Lu, J. X. (2015, July). Research on a New Abstract Programming Language for Generic Constraints. In 2015 International Conference on Artificial Intelligence and Industrial Engineering. Atlantis Press.