Originally Posted by
Mr.Greedy
...What would you expect one should know regarding calculators after 50 hours?
Perhaps a more important question (for some of us) would be "What would you expect one should know regarding
Java after spending 50 hours in the classroom (or spending the on-line equivalent of 50 classroom hours) of a Java course?"
The answer is, of course: "It depends." It depends on the reason that the course is offered in the first place, and it depends on the expectations of the instructor and it depends on the expectations of the "clients." (I hesitate to call them "students" until I know a little more about their collective agenda.)
Anyhow, I don't usually like to do homework for people, but, being kind of new to Java, I used a search engine to look for Java Beginning Calculator Tutorials.
Crap! Some of those things are hundreds and hundreds of lines long, and the ones with fewer than a thousand lines or so don't implement a very elaborate calculator. (A four-banger with square root in "only" 649 lines? Man, that's almost like work! That's not what we are here for, right?)
So I tried to come up with the simplest Java program (one that requires what I consider an absolute minimal knowledge of Java) that implements a somewhat fancier calculator.
So, as I said already, I don't usually like to do homework for others (not without getting paid), and I will probably get in trouble with Forum admins, but here is what I came up with:
// A very small Java program for
// a very elaborate calculator.
//
// For Linux systems you must have a
// calculator program gcalctool.
//
// Execute "gcalctool" from a command line
// to see whether you can expect success
// from this program.
//
// If there is no such program, then RedHat
// and Centos users can get it up and running
// by executing the following from a command
// line:
// sudo yum install gcalctool
//
// Then this little program is ready to run!
// It's a Great, Great calculator. Really!
//
// N.B.
// Windows XP users probably have something
// called calc.exe in their C:\Windows\system32
// directory. Try changing the name
// in the exec() argument to calc.exe
// or some such thing. (I don't have
// any way to test Windows stuff just now.)
//
// Zaphod_b
//
//
import java.io.*; // Gotta learn what this is all about.
public class SysCmd // Gotta learn what this is all about.
{
public static void main(String [] args) // Gotta learn what this is all about.
{
try // Gotta learn what this is all about
{
Process calc = Runtime.getRuntime().exec("gcalctool"); // Gotta learn what this is all about.
calc.waitFor(); // Gotta learn what this is all about.
}
// In order to understand the following two, you have
// to read up on exceptions. It is actually possible
// to make the "catch" stuff actually do something
// meaningful, but since that has nothing to do with
// calculators, why bother? Just leave them empty
// for now.
//
catch(IOException e){}
catch(InterruptedException e){}
System.out.println("Tttttthat's all, Folks!"); // Indicate normal exit from the above stuff
}
}
(Copy it quick! They may take it down and impose a lifetime ban yours truly at any moment.)
Something like nine lines of Java, not counting the {} braces. (Doesn't really need the parting message, but I always like to put in something to indicate a normal exit from a program.)
Cheers!
Z