The quiz as given in class was as follows:
Write Java code for a class named "QuizClass". The class should have one instance variable, named "instanceVar", of a type suitable to hold an integer. The class should also have one method, named "doSomething", which takes in a string parameter named "theParameter" and returns nothing. The method should have a local variable named "localVar" of a type suitable to hold a floating-point number like 3.7524. The method will print out the value of "theParameter", appropriately labelled. It will then set "instanceVar" to be the length of "theParameter", set "localVar" to be the square root of "instanceVar", and print out both of these, also appropriately labelled.
Most of you did really poorly on this quiz, so I'm going to convert it into a step-by-step on-line self-tested lesson. For each step, write down your solution on paper, then follow the link to my solution and comments.
Let's break the problem into the following sequence of steps:
QuizClass
.
My solution instanceVar
, of a type suitable to hold an integer.
My solution doSomething
that
returns nothing, takes no parameters, and does nothing.
My solution theParameter
of a type suitable to hold a character string.
My solution localVar
of a type suitable to hold a floating-point number.
My solution theParameter
.
My solution theParameter
.
My solution instanceVar
to this
value.
My solution instanceVar
.
My solution localVar
to this
value.
My solution instanceVar
.
My solution localVar
.
My solution