Skip to content

Update TemperatureConverter.java - #22

Open
CodeAKB wants to merge 1 commit into
Kalutu:mainfrom
CodeAKB:main
Open

CodeAKB wants to merge 1 commit into
Kalutu:mainfrom
CodeAKB:main

Conversation

@CodeAKB

@CodeAKB CodeAKB commented Jun 21, 2026

Copy link
Copy Markdown

In this updated version i basically re-structured the program and try to implement the DRY principle.

In this updated version i basically re-structured the program and try to implement the DRY principle.
@CodeAKB

CodeAKB commented Jun 21, 2026

Copy link
Copy Markdown
Author

In this updated version I basically re-structured the program and try to implement the DRY principle. and made the code more easy to understandable.

@irenemrtinez irenemrtinez left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @CodeAKB :)

Thanks for submitting this PR! I have reviewed the changes, and I have a few observations and suggestions:

1. DRY Principle & Code Duplication

  • Refactoring Logic: While moving from a switch statement to Character.toLowerCase() reduces case-sensitivity boilerplate, the overall structure remains similar. The System.out.printf calls are still repeated across all conditional branches.
  • Legacy Duplication: Notice that in both the original code and this PR, the core issue of repeating the formatting logic 6 times remains.
  • Suggestion: To make it truly DRY, we could first normalize any input temperature to a single base unit (like Celsius). From there, we can compute and print the converted values from a single place without repeating printf statements.

2. Existing Issues Carried Over (Legacy Code)

(These issues were present in the original codebase as well, but it might be worth addressing them if we are refactoring this class)

  • Naming Conventions: Method names like RunTemperatureConverter() start with a capital letter. In Java, standard conventions use camelCase (e.g., runTemperatureConverter()).
  • Input Validation & Exception Handling: If a user inputs a non-numeric value, the program throws an unhandled InputMismatchException.
  • Physical Limits: The program currently accepts temperatures below Absolute Zero ($0\text{ K}$ or $-273.15^\circ\text{C}$). Adding a quick validation check would make the converter much more robust.

I hope this was a useful review! If you make any changes, I would be happy to review them again. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants