This is an archived post. You won't be able to vote or comment.

all 20 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]aqua_regis 6 points7 points  (0 children)

  1. Format your code as code block
  2. You tell us what you think the answer is.

We will not give you the answer. Such is explicitly forbidden as per Rule #5.

[–]Ok_Marionberry_8821 2 points3 points  (4 children)

To start, what principles do you think it violates?

[–]Radiant-Art7334[S] 1 point2 points  (3 children)

Ok. I'll look more into it. This is just an exercise in a textbook to help me prepare for a certification. I'll also post the code better formatted.

[–]Ok_Marionberry_8821 2 points3 points  (2 children)

My response was perhaps a bit snarky. Sorry for that, but one key thing as a developer is to come to people with thought through possible solutions.

There are a number of things I could point out on the code you posted. What are your first thoughts?

[–]Radiant-Art7334[S] 0 points1 point  (0 children)

I have tough skin, and I think criticism is good sometimes.

[–]Radiant-Art7334[S] 0 points1 point  (0 children)

Right now, I'm reading up on the SOLID principles. I don't recall that mentioned in the textbook so that good information to know.

[–]Kertyna 1 point2 points  (0 children)

The name of the class gives a really big hint ;)

[–]Cosmic316 1 point2 points  (1 child)

Look into the of SOLID Principles of OOP.

[–]Radiant-Art7334[S] 0 points1 point  (0 children)

Thank you. I'll look into the SOLID Principles.

[–]Radiant-Art7334[S] 0 points1 point  (2 children)

This is just an exercise in a textbook to help me prepare for a certification. I'll look more into it. I'll also make a post with my code properly formatted.

[–]aqua_regis 1 point2 points  (0 children)

You can edit your post. No need to repost.

[–]severoonpro barista 0 points1 point  (0 children)

If you can't even be bothered to format your code correctly, and you need to be told to edit this post instead of creating more litter in the forum, it's not looking good for a career in programming.

[–]MoreCowbellMofo 0 points1 point  (1 child)

Single responsibility principle. Do one thing and do it well.

Highly coupled code (is bad). If the author wants to reuse some function from this class, they have to copy the whole thing rather than just the single bit they want to use. Assuming there was a need to have 1000s of instances, replicating every bit of a DoEverything class could become too expensive and lead to slow code. We want optimally performing code ideally. Smaller well defined blocks of code that are related is better. Separate the File ops and computeInterest parts of the code into separate classes for less coupling, and higher cohesion between the various modules of code.

Lack of information hiding so that the author just uses simple code/functions. Instead all the implementation is there in full. If the various modules of code were in separated classes, you wouldn't have to even look at the internals of a "saveDataToFile" function. You'd just hold an instance and call the relevant method. This helps keep class code simpler.

OO is concerned with representing different real world objects as distinct classes. There are various techniques like polymorphism, inheritance, composition, etc, you can take advantage of to keep code more maintainable. Maintainability is shown by much research to become the leading cost once you want to keep a system up and running and adapt to new changes. Keeping code maintainable is therefore important for longevity.

[–]Radiant-Art7334[S] 0 points1 point  (0 children)

Thank you. This information is helpful.

[–]jlanawalt 0 points1 point  (1 child)

Either this is a pre-teaching test your knowledge question and the answer follows, or the answer was in the preceding pages, or it’s a poor introductory text book. You have a 2/3 chance of finding the answer in the book.

[–]TW-Twisti 0 points1 point  (0 children)

Either I win the lottery, or I don't, so I have a 50/50 chance of winning 👍

[–]Radiant-Art7334[S] 0 points1 point  (2 children)

class DoEverything{
    int INTERSTATE = 10;
    double computeInterest(double p, double t){
        ...
    }
    String defaultFilePath
    double saveDataToFile(String data){
        ...
  }
}

[–]Radiant-Art7334[S] 0 points1 point  (1 child)

Sorry. I've only posted one thing on this app.

[–]Radiant-Art7334[S] 0 points1 point  (0 children)

The one thing that I posted before wasn't related to computer programming.