Randy Smith

Ranch Hand
+ Follow
since Mar 27, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Randy Smith

Am I right to say that is because object is created as B, that's why constructor of B is called. appreciate if someone could explain what is going on for this statement



b is the reference but it is declared as Type A, created as instance of B? Now, instance B is type of B or A??
12 years ago
Greetings, appreciate if someone could explain why the answer is not option a?

Assuming these classes are in the appropriate files, what is the output of the following program?



a) A Test
b) A Test B Test
c) B Test <--answer
d) B Test A Test
e) an error occurs

12 years ago

Maneesh Godbole wrote:Why are you even using the loop?
You can access the elements directly by fields[6],fields[7]...fields[n] right?



yes, i am aware that I can access the array directly e.g. fields[n], I need a loop because I have X things in the array.

n is dependent on the X number of items identified in the array



OK..it's NOW FIXED...@_@ thanks anyway...
12 years ago

Maneesh Godbole wrote:So what you are trying to do is (in pseudo code)
1) Ignore 1st 6
2) Take next 4 and process
3) Take next 4 and process

Hint: Array elements can be accessed using an index(which starts with 0)





please help me out, i'm struck
12 years ago
Sorry, I can't think of a better way to describe my problem

I have an array of Strings which I have parse into an array with using delimiter, comma



I know the first 6 array string are things that I don't want

I know there are 2 "humans" in this array and each human has 4 attributes

I know the pattern does not change.

How can I extract the human attributes? e.g.

print first human
name, height, weight, age

print second human
name, height weight, age

I know I need one or two for loop in combination to put this pattern in, but I'm kindna lost right now.
help is appreciated
12 years ago

Harsha Smith wrote:Field check not initialized

Field declared on line 10



thanks mate!
12 years ago
Appreciate if anyone can enlighten me if I'm doing anything wrong? CheckBoxListener is not working..the textboxarea append method is throwing weird errors.


12 years ago

Campbell Ritchie wrote:You are arguing from the particular to the general; that is not valid. You need to go from the general to the particular.

Let’s work out its weakest-precondition transformer effect, to establish z = y, which means the value of y at the end of the program.

[y = y + x; y = y + x]z = y ≡ by the Sequence Rule
[y = y + x][y = y + x]z = y ≡ by the assignment rule on the right
[y = y + x]z = y 〈y \ x + y〉 ≡ by substitution
[y = y + x]z = x + y ≡ by the assignment rule on the left
z = x + y 〈y \ x + y〉 ≡ by substitution
z = x + y + y ≡ by algebra
z = x + 2y       QED

You can now substitute 1 for x and 1 for y and get 3.



I think I have solved it.

y = y + x;
y = y + x; <-assign new value

y = (y + x) + x
y = y + 2x;

Yayyyy!

12 years ago

Harsha Smith wrote:

* Using interface as a type. What is the whole
point of this, why is this legal? Does it
make any sense?*/




Haven't you read the chapters "Inheritance" and "Polymorphism" yet?



yes, I have read them, but I don't know understand the purpose of using interface as a reference type. objects created using interface type can't access methods of the class that implements it. I was thinking objects of interface type should have additional methods instead, but it is the other way around.
12 years ago

Campbell Ritchie wrote:I would prefer to see the method called launchRocket().



when both Car and FighterPlane implement Weapons, all Cars and FighterPlanes can launch rockets, why do we need to use Weapon as a type?
12 years ago
Greetings, I would appreciate if someone could explain the purpose of using interface as a type. And why is it legal? I find it quite confusing, perhaps there is a better example to use interface as a type?

12 years ago

Harsha Smith wrote:second problem, say the value of x = 1 and y =1

now y = y+x // y =2
again y = y+x// 2 +1

System.out.println(y)//prints 3

similary y = y+2*x //1+2*1 = 3


System.out.println(y)//prints 3


Got it?



Hi, it seems that y = x + 2*y yield the same answer?
12 years ago

Campbell Ritchie wrote:Where on earth did you find those questions? They look designed to confuse. You would have to go through the execution of the code with a pencil and paper, and you can write down the values after each operation. With the two nested loops, you can tell that the loops are executed n × m times, but only if both numbers are positive; if either number is negative, you get an output of 0.



these are past year exams questions from my uni, i freak out when I have to work on these kind of questions under exam condition, trying to practise as much as possible. I'm actually quite unhappy that during this age and time, i have to work on programming exams using pencil and paper. I wish we are instead required to complete a small programming project within 2 - 3 hours with an IDE instead.
12 years ago
Here's another one, I have no idea what am I suppose to do, appreciate if someone can explain to me

Assuming x and y are int variables, the statements
y = y + x;
y = y + x;

can be replaced with the assignment statement

A) y = 2*x + 2*y;
B) y = (x + y)/2;
C) y = y + 2*x; (correct answer)
D) y = x + 2*y;

12 years ago
Greetings,

Assume that m and n are declared as valid int variables. What will be the output of the program segment below?



A. m +n
B. m * n (correct answer)
C. m
D. n

Hi guys, I can't figure out how can I work this problem, I get very confused when questions like this comes without any brace. Is there a strategy on working on these type of questions?
12 years ago