Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2010
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Help with Java study guide.

    Im asking for some help with studying for my final that is in the next 2 days.. was just wondering if anyone can take the time to help me complete a study guide.

    first question i had. im asking how could i figure out the value of "a" for bee and zoo after each line with a # in front of it.

    Code:
    public class Trace {
    private int a;
    public Trace(int a){
    	this.a=a;
    	
    }
    public Trace(int a, int b){
    	this.a=a*b;
    }
    
    public int joe(int a){
    	return this.a += a; 
    }
    
    public int liz(int a){
    	return this.a *= a; 
    }
    	public static void main(String[] args) {
    	Trace bee = new Trace(1);
    	#Trace zoo = new Trace(3);
    	#bee.joe(2);
    	#bee.liz(2);
    	#zoo=bee;
    	#bee = new Trace(2,4);
    	#zoo.joe(bee.liz(2));
    	#bee = zoo;
    	#bee.liz(3);
    
    	}
    
    }
    the next question i had is to indicate which lines would cause compile-time errors..explanation to each error if possible..

    Code:
    public static void main(String[] args) {
         Boat b;
         SailBoat s, s2;
         RowBoat r, r2;
         
         s = new SailBoat(28.5, "Ariadne", 6);
         r = new RowBoat(12,"luck");
         
         b=s;
         b=r;
         s2=s;
         r2=s;
         s2=b;
         s.makeItGo();
         b.makeItGo();
         r2.makeItGo();
    		
    		
    	}
    
    }
    thank you
    Last edited by WA; 12-10-2010 at 12:53 AM.

  • #2
    Regular Coder
    Join Date
    Feb 2008
    Location
    Edinburgh - Scotland
    Posts
    107
    Thanks
    0
    Thanked 12 Times in 12 Posts
    Hi.

    First of all do you have NO idea how to work it out - I have no idea if you cannot do any of these problems or just some of them!?!

    The first one is fairly tough and one of the best ways is to work it would be - write down your answer, then run it and print out the value at each point - it will teach you how Java works. Java is a bit confusing sometimes with problems like that.

    The second one is fairllllly simple - is that the only code it gives?! If it was coded sensibly from the Boat object side of things I would expect lines:

    Code:
    s2=s;
    r2=s;
    s2=b;
    The first 2 would give compile errors - wrong object type or something similar - its kind of like saying :

    String myStr = 2;

    because 2 is not a valid string object.

    The last line s2=b would require a cast I think, but may work, again depends on compiler + best way is to just try!

  • Users who have thanked renegadeandy for this post:

    seabass (12-10-2010)

  • #3
    New to the CF scene
    Join Date
    May 2010
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    yea i have no idea how to work it out..
    thanks for the help.

  • #4
    Regular Coder
    Join Date
    Feb 2008
    Location
    Edinburgh - Scotland
    Posts
    107
    Thanks
    0
    Thanked 12 Times in 12 Posts

    Thumbs down

    If you have no idea how to work it out - have you attended any of the classes, they cannot be testing you on something that they havent told or explained to you how to do....that makes 0 sense.


  •  

    Posting Permissions

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