Projects and other stuff

Projects and other stuff

Re: Nero’s JCalculator

rs06player:

Just wanted to share,

Nero’s JCalculator, download open-source here.

Information: Nero’s JCalculator is a simple open-source Calculator made by Nero using Java.

Version: 1.0 [ALPHA]

Future of the project: At last, this will be released to the public for learning purpose, also, I’m developing this just for getting knowledge in Java, the full release will contain a nice GUI and these stuffs, but I’m still learning anyway :D.

I discovered your post while searching through the tumblr tags for Java and decided to give it a try.

1. It’s compressed using a propitiatory archive format (.rar) which alienates people running Linux-based operation systems (Ubuntu, Fedora, etc). It took me awhile to open the archive because I had to find the right packages to install, which can be time-consuming. You should really use the .tar.gz archive format instead because it works on virtually every file manager without having to install any additional content.

2. You included a .bat script in your archive, which only works on the Windows operating system. Users running Mac OSX or Linux will either have to use the command line to run the program (a lot of people don’t know how to do this ) or import the src folder into Eclipse (or another IDE) and run it from there. Instead, you should compress the program into a .jar file, which is supported by every operating system with a JVM.

3. You shouldn’t call any of your classes “Main”. I know what you’re getting at, it’s the class containing the main method, but the name simply isn’t descriptive and doesn’t provide the programmer with any useful information. Once you start having projects with dozens or even hundreds of different classes, it’ll be really confusing what Main is or why it’s important.

4. You seem to break up the program into four separate classes that don’t do anything on their own. Instead, you should create a class called “Calculator,” code any methods that you need, and put it together in the main method. It’ll be much easier to read and less confusing for other programmers. You should only start a new class if you need a separate body of similar methods that accomplish a part of your task efficiently and can be re-used for later projects.

5. The comments aren’t very helpful in explaining what you’re trying to do in the class. Typing:

    // Objects
    public static Scanner s = new Scanner(System.in);
    // variables
    public static double FirstNumber;
    public static double SecondNumber;
    public static String type;

doesn’t tell us anything new; we know what objects and variables are. You should get into the habit of writing verbose descriptions before major chunks of your code so that programmers reading your code have a basic idea of what’s going on before they delve into the code; it’ll make their lives much easier.

6. Too many if-then-else statements; get into the habit of using switch. Trust me, it’s easier to read. Instead of typing:

if(ask.type.equalsIgnoreCase(“Sum”)){
            Result = ask.FirstNumber + ask.SecondNumber;
        }else if(ask.type.equalsIgnoreCase(“Minus”)){
            Result = ask.FirstNumber - ask.SecondNumber;
        }else if(ask.type.equalsIgnoreCase(“Multiplay”)){
            Result = ask.FirstNumber * ask.SecondNumber;
        }else if(ask.type.equalsIgnoreCase(“Division”)){
            Result = ask.FirstNumber / ask.SecondNumber;
        }   

you should type:

switch (ask.type) {

case “sum”: Result = ask.FirstNumber + ask.SecondNumber;

break;

// … etc

}

Note: above only works if using a Java 7 compiler.

6. Attempting to divide by zero returns the result “Infinity.” Although this is a problem with Java’s implementation of float and double variables, you should really make an effort to prevent this.

7. Entering a letter or a number that doesn’t exist such as “j” or “4x” will return a InputMismatchException. You can fix this by surrounding the piece of offending code into a try-catch block that informs the user of the invalid input.

8. Lastly, you should make the program loop until the user tells it to stop. It can be annoying to the user if they have to launch the program every time they want to make a new calculation.

Hope this helps! If you need any other help, feel free to ask.

(via rs06player-deactivated20120405)

Top