Skip to content

baconian.java : fixed syntax error and improved code #3548

Open
christianbender wants to merge 2 commits intoOpenGenus:masterfrom
christianbender:changed_baconian_JAVA
Open

baconian.java : fixed syntax error and improved code #3548
christianbender wants to merge 2 commits intoOpenGenus:masterfrom
christianbender:changed_baconian_JAVA

Conversation

@christianbender
Copy link

Fixes issue:

  • Syntax error because filename don't match class name.

Changes:

  • I fixed the bug (syntax error) above.
  • I added a main method for testing.
  • I changed the methods:
    • getKeyFromValue(...)
    • encode(...)
    • decode(...)
  • Removed StringBuilder and used String instead.


public String encode(String word) {
StringBuilder results = new StringBuilder();
String results = "";
Copy link
Member

Choose a reason for hiding this comment

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

I feel like the assignment isn't necessary.

Copy link
Author

Choose a reason for hiding this comment

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

@arnavb In Java variables must be initalized otherwise the compiler complains

word = word.toLowerCase();
for (int start = 0; start < word.length() / 5; ++start) {
StringBuilder code = new StringBuilder();
String code = "";
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Copy link
Author

Choose a reason for hiding this comment

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

See my comment above.

public static void main(String [] args) {
Baconian bac = new Baconian();
System.out.println(bac.encode("Wikipedia"));
System.out.println(bac.decode("babbaabaaaababaabaaaabbbbaabaaaaabbabaaaaaaaa"));
Copy link
Member

Choose a reason for hiding this comment

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

Add comment for expected outputs.

@christianbender
Copy link
Author

@arnavb Changed the code as requested

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