Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Athayna/seven-segment-mirror

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Seven Segment Mirror

This simple java program takes a string of up to four digits and prints out the seven segment display representation of the numbers. The program can then mirror that display horizontally or vertically.

Input

The program will promt the user to enter a string of up to four digits. Leading zeros are applied if the digit amount is less than four. The program will then print out the seven segment display representation of the numbers.

After that the program will ask the user if they want to mirror the display horizontally or vertically. The user can enter x for horizontal (x-axis) or y for vertical (y-axis). If the user enters q the program will quit.

Running the program

Simply download the .jar file from the releases section and run it in the command line with

java -jar SevenSegmentMirror.jar

. Make sure you have Java installed on your machine.

Approach for the task

First, I thought about how to best represent the numbers in the console. I considered the different segments of the numbers as pixels. A two-dimensional array was suitable to simulate a display. I then thought about which symbols I wanted to display in the respective cells to achieve an aesthetically pleasing representation. The symbols that came to mind were a horizontal line, a vertical line on the right, a vertical line on the left, vertical lines on both sides, and an empty cell.

Next, I created a small sketch to avoid unnecessary bugs when writing and mirroring the array later. To ensure easy access to the different segments, I placed them in an enum. This way, I could later rearrange the segments when mirroring without having to work with individual characters.

As required in the task, I worked object-oriented and created a Clock class, allowing multiple instances of the clock to be created, so multiple times could be mirrored.

The Clock class is responsible for the representation of the numbers as well as managing the input numbers. It also contains methods for mirroring the numbers and displaying them in the console.

When mirroring, either the rows (x-axis) or the columns (y-axis) are flipped. Additionally, segments with a line on the right are swapped with segments having a line on the left and vice versa, so a true reflection occurs.

The App class contains the main method, which initializes the scanner for the subsequent flow of the application, calls the methods to initialize the clock, and then starts the program loop.

When initializing the clock, the user input is passed to the constructor of the Clock class. This constructor is responsible for validating the input and throws an error if the input is too long or if a character is not a number. In this case, it asks for a valid input again. An exit with "exit" is also possible.

The program loop continuously asks for user input to mirror the clock along the respective axis (x or y). The program can also be exited by entering q. After each reflection, the "screen" of the clock is displayed again to make the changes immediately visible.

About

A simple java program for a recruitment test, which takes a string of up to four digits and prints out the seven segment display representation of the numbers. The program can then mirror that display horizontally or vertically.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages