Glenn Valenta wrote:
> I'm new to Java and have taken a course at CU Denver in Java
> Programming. The course outline states (ironically) that you must
> have W95 or a Mac to take the course. I have entered it using
> Linux. All has been fine up till I turned in my first code. The
> following code compiles and runs on my machine without error but
> the instructor stated that when he compiled and ran my code, he
> got an error.
>
> "I get an IO exception on any input to sreport.java. Let
> me know if you are seeing a different behavior."
>
i can also get this error on nt, but your code works ok on
solaris with jdk1.2beta3. my linux machine is not accesible
at the moment, however.
> Why would this code work fine on Linux and not on his Mac?
> Could someone be so kind as to compile and confirm my results?
>
he has a mac? well i don't know enough about macs to be sure,
but i have good reason to believe that it doesn't work on windows
because pressing "enter" on a windows machine generates
"carriage return/line feed" whereas on a linux machine it generates
"carriage return". by slightly modifying your code, i was able to
make it work on windows, but then it didn't work properly
on solaris. now i could just *tell* you what i did, but i wouldn't
want to spoil the fun by doing your homework for you now would i? ;-)
but here's a few hints:
> (I'm unsure of what version he is running.)
> My version is JDK_1.1.5 on RH5.0 using kernal 2.0.33
>
> //////////////////sreport.java/////////////////////
> // a cheesy program to demonstrate IO //
> // Program will add sales items and calculate //
> // Salesman's commistion //
>
you spelled commission ^^^^^^ wrong up there
> import java.io.*;
>
> public class sreport {
> public static void main(String args[]) throws IOException
> {
> double _total=200; //var init to base salary
> final double _PC=0.09; //percent commission
>
> final double _A=239.99*_PC;
> final double _B=129.75*_PC; //commission on cost of
> final double _C=99.95*_PC; //each Item
> final double _D=350.89*_PC; //itemcost * percent-commission
>
> char prod=0;
> do
> {
> System.out.println("Enter the Product Sold ( A->D ). X to Exit");
> prod=(char)System.in.read();
> switch(prod)
> {
> case'a':case'A':
> _total+=_A;
> break;
> case'b':case'B':
> _total+=_B;
> break;
> case'c':case'C':
> _total+=_C;
> break;
> case'd':case'D':
> _total+=_D;
^^^^^^^^you don't have a default for your switch statement, so i can put in
products E through Z or even a-z, 0-9, !@#$%^&*()_{}:"';\/. if i want to.
(not that this is in any way related to your problem of course).
> }
> System.in.skip(1); //remove nl
> }while(prod!='x'&&prod!='X');
> System.out.println("Total Weekly Pay is $"+_total);
> }
> }
>
maybe one of these last lines needs to change a little bit?
if you are really close to a deadline i can tell you the answer,
but the problem basically is that this command line stuff is
not portable across architectures. pay close attention to
the different values returned by windows and unix pressing
the enter key, and the answer will leap out and byte you.
see your instructor and ask for only graphical assignments,
then you should be ok. if your deadline fast approaches,
i can tell you the answer in return for copious amounts of
beer. ;-)
hope this helps,
kanpai!
pat