This won't compile.Christian Staves wrote: Its getting easier as I do more, wrote this in about 30-40mins.
David Newton wrote:
I'm not sure what you mean when you ask if you're "using toUpperCase" correctly; number one, I don't see you using it anywhere, and number two, you're not defining a method where you believe you are:I mean, you should be getting a wide variety of compilation errors for this code.
How about write one little tiny bit at a time, see if it works, *then* add on more code? Why try to fix everything at once?!
Tom Reilly wrote:I agree with Mr. Newton. You have over 20 compiler errors. Look at the following:
1. As to your mutators, you cannot assign a method name to a variable. You need the mutator to accept a parameter and then assign the parameter to the variable.
2. In your switch statement, the variable on which you switch must be defined. Also, in the case part, you must assign your numbers to a variable. Finally, the method that holds your switch statement expects you to return a double. Therefore, return a double at the end of the method.
3. You also have a typo for one of your variables in your mutators
Tom Reilly wrote:As to the upper case issue, take a look at java.lang.Character. There is a static function that does what you need.
Take a look at the rest of your methods. Do any just end with a semicolon? Hint: you must actually process the input parameter and return a char that is in upper case. Double hint: think about using java.lang.Character.toUpperCase() to process your input. Or, as David suggests, don't just define a static method, have your code that would typically call your static method call Character.toUpperCase() instead. (Which is a static method and therefore conforms to what your professor told you to do.)This method requires a body instead of a semicolon
David Newton wrote:You're not "using" anything there--you're (sort of) defining a new method or something, but incorrectly.
If you're trying to *use* a static method from somewhere, pick where you're going to use it (not in the middle of a class definition) and use the normal syntax for calling a static method; NameOfClass.nameOfStaticMethod(methodParams).
This means that whenever you set the rating key variable, you need to convert it to upper case. The rating key is set in two places; in the constructor and in the mutator. I see you edited your original post to update the code. You almost got the mutator right. You still need to get the constructor right. See my previous post on how to fix your static toUpperCase() method. In your mutator, try something like this:orTo deal with this uppercase/lowercase problem: When you store the rating key – both in the
constructor and in the respective mutator – convert it to uppercase. This has the nice effect
that in computeDailyFee() you can be sure that it's uppercase and you don't have to worry
about this anymore*/
Tom Reilly wrote:By editing your original posts, you have committed a JavaRanch faux pas. I'm sure the Java Ranch ambassadors can explain it better but now the replies to the original post don't make sense. Anyone reading the thread will not understand the responses. IMO, editing should be reserved to fixing spelling or grammatical errors or, for example, when I edited my response because I missed a "]" in the response and therefore my reply became part of the quote to which I was responding.
What is the actual outcome? You don't specify what is wrong.*** double fee = Math.round(((daily*ratingKey)*100.0))/100.0; ***is not working correctly any ideas?
It should work, I did it by hand and it comes out. When I do it like so, daily(92.76) * 100, then * by the factor say 1.6 = 14841.6/ by 100= 148.416 and then round would be a 2 digit number, but my java formula no matter how I write it wont come out like this
CarRental() is called a default constructor (no parameters). You don't have one of these. You have a constructor that requires three parameters:So you need to pass the three values to the constructor.So, You just have to create one instance of CarRental, give it a customer name, a make and the
first key, print customer, key and daily fee.
CarRentalTester.java:28: cannot find symbol
symbol : constructor CarRental()
location: class CarRental
CarRental myCar1 = new CarRental();
^
1 error]
Tom Reilly wrote:
What is the actual outcome? You don't specify what is wrong.*** double fee = Math.round(((daily*ratingKey)*100.0))/100.0; ***is not working correctly any ideas?
It should work, I did it by hand and it comes out. When I do it like so, daily(92.76) * 100, then * by the factor say 1.6 = 14841.6/ by 100= 148.416 and then round would be a 2 digit number, but my java formula no matter how I write it wont come out like this
CarRental() is called a default constructor (no parameters). You don't have one of these. You have a constructor that requires three parameters:So you need to pass the three values to the constructor.So, You just have to create one instance of CarRental, give it a customer name, a make and the
first key, print customer, key and daily fee.
CarRentalTester.java:28: cannot find symbol
symbol : constructor CarRental()
location: class CarRental
CarRental myCar1 = new CarRental();
^
1 error]
David Newton wrote:Are Chris and Tarus variables? Or are you trying to pass in string literals? What book are you using? What web resources are you looking at to understand basic syntactical questions?
Campbell Ritchie wrote:You are also making the mistake of writing too much code at a time. Write one method at a time, compiling your code and testing the method every time. That way you only have about 5-10 new lines to add errors, and errors become much easier to sort out.
Shows how dangerous it is to try hard programming when tired. That is why a good company will avoid lots of overtime.Christian Staves wrote: . . . I was tired . . .
Uh oh, we're definitely being carded. Here, show him this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|