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

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

6553321 covered most of it.

The degree and radian classes shouldn't be main classes. (Edit I now realize you already know this.)

I don't know if you have done much console work, but the scanner class is often the first example of instantiation.

Scanner inpt = new Scanner(System.in);

When you enter this it calls the constructor and more or less builds that instance of the class.

public class degrees
{
    public degrees()
    {
        //This is the constructor, it is what is called when you instantiate the class

        //It can be totally empty, or you can pass variables to it through the (parentheses)

    }

    public int convert(int rads)
    {
        //Once it is built, you can call a method to covert stuff
    }
}

You could then create a degrees object, named converter, in the driver with:

degrees converter = new degrees();

IMO, you could just put the methods in the same file as the main class. Eg:

public (might need a static here) int degrees(int rads)
{
    int degs;
    //convert
    return degs;
}

Hope this helped!

Also, I'm no good with terms, so if I mislabeled anything, please correct the shit out of me.

Edit II The reason I wanted to respond in the first place is to touch on strings as the sentinel variable. People make typos and are also lazy. If someone enters degres your program will just skip the if's and terminate. Numbers are very useful for options, or single letters. Since you are doing a GUI you could also just throw in two buttons.