A simple program in the console that display menu of the script. The menu has six selection with five different scripts and one exit.

I am using Factory pattern because in one of the best ways to create an object. This create object without exposing the creation logic using common interface and by overriding.

MidTermUI –> SelectMenu –> (interface) [MidTerm <– (ProgramA, ProgramB, ProgramC, ProgramE, and ProgramF) ]

The Class Diagram

Factory Patter Diagram in Java Object Oriented Programming

Step 1

Create an interface. MidTerm.java

Step 2

Create concrete classes implementing the same interface.

ProgramA.java Accept and display the content of an array

ProgramB.java Finding the sum of an array.

ProgramC.java Displaying the reverse order

ProgramD.java Counting the characters of a given string.

ProgramE.java Displaying highest to lowest and lowest to highest order

ProgramF.java Default and invalid selection.

Step 3

Create a Factory to generate object of concrete class based on given information.

SelectProgram.java

Step 4

Use the Factory to get object of concrete class by passing an information such as type.

MidTermUI.java

The Output

Enter the number to select the menu.

1: Accept and display the content of an array.
2: The sum of an array.
3: Display the reverse order of an array.
4: Counting the characters of a given string.
5: Arrange from highest-lowest and lowest-highest.
6: To end the program.

Enter Option:

Output on option number 1
——————————————-

Accept and display the content of an array
Enter Five Names:
anne
joy
mary
sharina
dangal

——————————————

You had enter the following names:
anne, joy, mary, sharina, dangal
——————————————-

Press enter to go to main menu

Output on option number 2
——————————————-

Finding the sum of an array.
Enter Five Numbers:
1
2
3
4
5

——————————————-

The Sum of the numbers is : 15

——————————————-

Press enter to go to main menu

Output on option number 3
——————————————-

Displaying the reverse order.
Enter Five Names:
1
2
3
4
5

——————————————-

You had enter : 1, 2, 3, 4, 5
The reverse order is : 5, 4, 3, 2, 1
——————————————-

Press enter to go to main menu

Output on option number 4
——————————————-

Counting the characters of a given string.
Enter keywords:
bahay kubo

——————————————-

The keyword "bahay kubo" you enter has : 10 characters inlcuding space.
——————————————-

Press enter to go to main menu

Output on option number 5
——————————————-

Displaying highest to lowest and lowest to highest order.
Enter five numbers:
2
8
4
6
9

——————————————-

You had enter : 2, 8, 4, 6, 9
The order from lowest to highest is : 2, 4, 6, 8, 9
The order from highest to lowest is : 9, 8, 6, 4, 2
——————————————-

Press enter to go to main menu

Output on option number 6

Good Bye

By | 2017-01-24T10:02:00+00:00 January 13th, 2017|Categories: Uncategorized|0 Comments

About the Author: