Results 1 to 6 of 6
  1. #1
    Julie is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default 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:

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    We try NOT to do other's homework. So why don't you show your answers and ask some questions about them.

  3. #3
    Julie is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default 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 :)

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,266
    Rep Power
    25

    Default

    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.

  5. #5
    Julie is offline Member
    Join Date
    Sep 2008
    Posts
    3
    Rep Power
    0

    Default 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 :)

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    19

    Default

    Quote Originally Posted by Julie View Post
    Question 2 is still annoying me a bit though, would this be correct:
    double cost;
    public void calc(double x){
    cost = x;
    }

    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

  1. Row level locking........
    By jithan in forum New To Java
    Replies: 0
    Last Post: 09-02-2008, 07:09 AM
  2. row level locking
    By jithan in forum New To Java
    Replies: 1
    Last Post: 08-28-2008, 06:42 PM
  3. Field Level Security
    By narayanasgs in forum Web Frameworks
    Replies: 0
    Last Post: 05-30-2008, 08:34 AM
  4. Java Debug Level
    By keshari in forum New To Java
    Replies: 1
    Last Post: 05-26-2008, 08:23 AM
  5. Replies: 0
    Last Post: 04-05-2008, 12:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •