Re: Java Pizza Program Help
The code itself makes little sense, but anyways...
The things I saw in the first 5 seconds:
error#1: char num = size;
You can't initialize char with a string directly. One of many ways to do it would be char num = size.charAt(0); considering you are sure there is at least one char in the string.
error#2: if ((checksize == "Small")||(checksize == "Medium")||(checksize == "Large")), this.getSize()==CompPizza.getSize() and more...
That's a nice one =). This is no JavaScript, you can't compare objects' contents the way you do with primitives. Use equals() method for this (i.e. str1.equals(str2)).
And I am not even talking about algorithm corrections/optimizations... The program will throw basic exceptions almost every line if something goes wrong. Check status of one step before starting the next one.
Re: Java Pizza Program Help
ok number 1 was delt with what do you suggest about error 2... and ye the codes probably incorrect in many ways but please note i am a first year college student with no background in any programming and i am only a month in my object oriented java 1 program
Re: Java Pizza Program Help
Quote:
Originally Posted by
Xeel
The code itself makes little sense, but anyways...
The things I saw in the first 5 seconds:
error#1: char num = size;
You can't initialize char with a string directly. One of many ways to do it would be char num = size.charAt(0); considering you are sure there is at least one char in the string.
error#2: if ((checksize == "Small")||(checksize == "Medium")||(checksize == "Large")), this.getSize()==CompPizza.getSize() and more...
That's a nice one =). This is no JavaScript, you can't compare objects' contents the way you do with primitives. Use equals() method for this (i.e. str1.equals(str2)).
And I am not even talking about algorithm corrections/optimizations... The program will throw basic exceptions almost every line if something goes wrong. Check status of one step before starting the next one.
I want to add a suggestion to the OP and make it more explicit what Xeel is saying. I very seldom see people doing this, and maybe they're just used to it or just followed one bad programmer's example, but consider this when doing string comparisons:
Code:
String s = null;
if(s.equals("Something")) {
// NullPointerException
}
if("Something".equals(s)) {
// Will never NPE
}
Always use the latter approach of comparing a string literal against a reference object when you can.