Results 1 to 6 of 6
 09032008, 12:35 AM #1Member
 Join Date
 Sep 2008
 Posts
 3
 Rep Power
 0
Some Questions  from old test papers 100 level
Ekk... I have a test tonight and am trying to make sense of all this:
Some questions that I'm not sure about are:
1. For each part (and each sub part) of this question assume:
int i = 8;
double d = 3.9;
char c = 'x' , k;
Show the value stored in the left hand side of the assignment statements below:
k = c;
k = 'c';
Write a boolean assignment statement that sets b to true when (and only when): c is not 'i' or 'o' or 'u'
2. Assume that calc is in a class that has a double data field cost, write the method so that it returns nothing, but instead stores the result in the data field.
3. Assume that calc is in a class which has double data fields called a and b. Write this method so that it takes no input, but returns the sum of the data fields multiplied by 10.
Some help (pref before tonight) would be very much appreciated.:confused:
 09032008, 01:51 AM #2
We try NOT to do other's homework. So why don't you show your answers and ask some questions about them.
 09032008, 02:29 AM #3Member
 Join Date
 Sep 2008
 Posts
 3
 Rep Power
 0
ok.. np, these are what I think the answers might be?
1. For each part (and each sub part) of this question assume:
int i = 8;
double d = 3.9;
char c = 'x' , k;
Show the value stored in the left hand side of the assignment statements below:
k = c; > I think this gives reference to the corresponding uni number for c?
so k = that number (what ever it might be?)
k = 'c'; > here I think c is stored in k so k = c?
Write a boolean assignment statement that sets b to true when (and only when): c is not 'i' or 'o' or 'u' > boolean b = true (c != 'i'  c != 'o'  c != 'u') Here I wasn't sure about using the  twice inside the expression??
2. Assume that calc is in a class that has a double data field cost, write the method so that it returns nothing, but instead stores the result in the data field.
Here I'm really unsure:
Assume: double cost;
public void calc(){ //void as it returns nothing?? is that right?
double cost // but how do I write this so it stores the result in the data field?
Any hints would be appreciated
3. Assume that calc is in a class which has double data fields called a and b. Write this method so that it takes no input, but returns the sum of the data fields multiplied by 10.
Assume:
double a;
double b;
public double calc() {
return 10*(a+b);
} // any pointers here if this is wrong would be appreciated
Thanks :)
 09032008, 04:09 AM #4
Do you have a java compiler? If so, you should create a small program with these statements and after each of the put a System.out.println() to show the values of the variables.
1. For each part (and each sub part) of this question assume:
int i = 8;
double d = 3.9;
char c = 'x' , k;
Show the value stored in the left hand side of the assignment statements below:
k = c; > I think this gives reference to the corresponding uni number for c?
so k = that number (what ever it might be?)
>>> k anc c are variables. c has been given the value 'x' a char
>>> k = c; will give the same value to k as c has (ie 'x')
k = 'c'; > here I think c is stored in k so k = c?
>>> No k is given the value 'c', not the value of the variable c
Write a boolean assignment statement that sets b to true when (and only when): c is not 'i' or 'o' or 'u' > boolean b = true (c != 'i'  c != 'o'  c != 'u') Here I wasn't sure about using the  twice inside the expression??
All the conditions need to be true here, not just one of them.
An or test will quit as soon as one condition is true.
An and test requires all the conditions to be true.
You are use or so it c has the value 'u', then the first test is true: c is not equal to 'i' and the full expression would return true.
2. Assume that calc is in a class that has a double data field cost, write the method so that it returns nothing, but instead stores the result in the data field.
Here I'm really unsure:
Assume: double cost;
public void calc(){ //void as it returns nothing?? is that right?
double cost // but how do I write this so it stores the result in the data field?
Any hints would be appreciated
>>> Store means to assign the value passed as an arg in a class variable.
>>> pass a double as an arg and assign it to the class variable
3. Assume that calc is in a class which has double data fields called a and b. Write this method so that it takes no input, but returns the sum of the data fields multiplied by 10.
Assume:
double a;
double b;
public double calc() {
return 10*(a+b);
>>> looks about right. Needs closing } Again write a small test program to see.
 09032008, 05:07 AM #5Member
 Join Date
 Sep 2008
 Posts
 3
 Rep Power
 0
Thank you!
Hi Norm,
Thanks, I have gone over my notes again, and this time understood them a little better.
Question 2 is still annoying me a bit though, would this be correct:
double cost;
public void calc(double x){
cost = x;
}
I don't have a compiler here at home; but in class we are using drJava.
 one day I hope this all makes sense: this is my 1st time programming!
Thanks again Norm :)
 09032008, 07:20 AM #6
 Join Date
 Jul 2007
 Location
 Colombo, Sri Lanka
 Posts
 11,371
 Blog Entries
 1
 Rep Power
 20
I hope you know the basis in Java, if so no need to worry about this code segment.
In first line, you have declared a double type variable, named as cost. Is that clear?
On next three lines you have define a method name calc, which pass a double type variable. In the method assign a value to cost variable. That's it.
So where are are tuck with, better to be specific on your question.
Similar Threads

Row level locking........
By jithan in forum New To JavaReplies: 0Last Post: 09022008, 08:09 AM 
row level locking
By jithan in forum New To JavaReplies: 1Last Post: 08282008, 07:42 PM 
Field Level Security
By narayanasgs in forum Web FrameworksReplies: 0Last Post: 05302008, 09:34 AM 
Java Debug Level
By keshari in forum New To JavaReplies: 1Last Post: 05262008, 09:23 AM 
Test Advisory PanelTelecommute Test your Java skills + share insights on Java tests
By michelle in forum Jobs OfferedReplies: 0Last Post: 04052008, 01:38 AM
Bookmarks