Saturday, February 4, 2012

Discussion for Computer Composition Lab

The Lab and pre-lab assignment are now available. As usual, a physical copy of your pre-lab assignment is due at the start of lab on February 8th.


Please post your questions and comments here.

Have a great weekend!

29 comments:

  1. The package edu.unm.cs.cs251spr12.lab.feb8 does not exist. I checked out the entire public svn repo a few minutes ago and there is no cs251spr12 or feb8 directory. No Vehicle.java, Engine.java, Tire.java, or VehicleDemo.java files either.

    I've noticed that there exist duplicate nested copies of some parts of the repo. There also appear to be entire duplicates of the feb1 package...

    ReplyDelete
    Replies
    1. The package edu.unm.cs.cs251spr12.lab.feb8 does exist in the repo. I just double checked. Did you update your svn to the latest version? It should be revision 70.

      Delete
    2. Thanks Joe, but I'm a bit confused now. At times I've used "svn update" when logged into my CS account to get the latest revision of the entire class repo, but usually I use WinSCP to browse to Hayes' pub-svn directory and then copy just the files I want directly to my primary computer.

      Using "svn update" I know have the feb8 lab files, but these are nowhere to be found in Hayes' pub-svn directory. I'm curious as to why this is.

      Anyways, obvious solution: use "svn update" from within your CS account.

      Delete
    3. The directory that the SVN is located in contains information on all of the data that has been committed and changed. You shouldn't browse this directory to check things out. This directory acts more like a database keeping track of changes.

      Basically, just use the svn from your own directory that you have checked out.

      Delete
    4. I have revision 72 and the files aren't there. Is there another place I can get them?

      Delete
  2. I was reading over the requirements for the next lab and have thought about throwing exceptions when any negative numbers are entered that are not valid to specify the size of the RAM or hard drive space. However, I cannot find any such exception in the Java API. Would I have to someway have to create an exception of my own to accomplish on the composition?

    ReplyDelete
  3. hello,
    the issue i am having i believe is with my classpath or package. All my .class files are in the same folder "feb8" and they are all in the same package, but when i go to compile my driver class it cannot find the symbol of say the hard drive class

    i guess im just not clear on how to set the hierarchy right any help on this would be great

    thanks

    ReplyDelete
  4. ok i got the code to compile, but when i try to run the program through my Driver class i get a class not found exception. the class and the driver are in the same directory so i am not sure how to approach this exception

    ReplyDelete
    Replies
    1. I believe we talked about this after class. Basically, you must have everything in the correct directory. For example, if you have the package edu.unm.cs.jcollard you will have 4 directories. edu/, edu/unm, edu/unm/cs, edu/unm/cs/jcollard. You place all your files in the directory furthest down. This is the package. Finally, when you go to run, you *must* use the fully qualified name from the root directory. For example, if I am in /home/jcollard/workspace/edu/unm/cs/jcollard, I need to run the java command from the workspace directory.

      I would type: java edu.unm.cs.jcollard.Driver

      This would tell it to look in the folder edu/unm/cs/jcollard for a file called Driver.class. The class *must* contain the package declaration edu.unm.cs.jcollard to work this way.

      Hope this helps!

      Delete
    2. This comment has been removed by the author.

      Delete
  5. i must be missing something very simple here

    this is my directory as shown in my term
    compy386@ubuntu:~/edu/unm/cs/cs251spr12/green4g63/lab/feb8$ ls
    Driver.class Driver.java~ HardDrive.class~
    Driver.java HardDrive.class HardDrive.java

    and here is my package for the classes
    package edu.unm.cs.cs251spr12.green4g63.lab.feb8;

    public class HardDrive{

    package edu.unm.cs.cs251spr12.green4g63.lab.feb8;

    public class Driver{


    and it still will not find a main class when a main method is in the Driver class sorry to be a pain but i just cant figure this out

    ReplyDelete
    Replies
    1. Are you sure your main method has been declared correctly? If the stub is not exactly correct it won't be able to launch it. If you are still having troubles, you should email me directly with your source code attached so I can help you trouble shoot.

      Delete
  6. So I made a Usage method for bad arguments, but can't get it to play nicely across the package. Is this normal?

    ReplyDelete
    Replies
    1. It really depends on what you are trying to do. Could you give a detailed description of your problem?

      Delete
    2. I had tried:
      public/protected/default void Usage(){stuff}

      I was under the impression that public/protected methods could be seen and used by package members, but I'm getting compiler errors when trying to call it from outside the class it was made in.

      My interim solution is having each class contain an identical Usage() method, which seems like it's probably redundant.

      I'm obviously missing something...

      Delete
    3. Is it a static method? If it is a non-static method, you need an instance of the class to use it.

      Delete
    4. Tried setting to static. No luck. I might be able to make it to the back half of your office hours tomorrow. If not I'll be redundant.

      Delete
  7. Are we allowed to make any of the required methods static?

    ReplyDelete
    Replies
    1. No, if you make them static, it implies that there is only one value that can be returned. What if you wanted to make multiple different instances of Computer each of which had their own MotherBoard, CPU, and HardDrive? You would not be able to accomplish this if those methods were static.

      Delete
    2. That makes sense. However, I've run into another issue. All of my .java files are in the package:

      'package edu.unm.cs.cs251spr12.batch.lab.feb8;'

      When trying to compile my code to generate the .class files, I'm getting the error "cannot find symbol' for almost every one. My code for HardDrive.java and CPU.java compiled fine.

      Any idea of what may be causing this?

      Delete
    3. Try

      import edu.unm.cs.cs251spr12.batch.lab.feb8.*;

      Delete
    4. Oh, also, HardDrive.java and CPU.java are compiling because they don't call anything from another class, if I remember correctly.

      Delete
    5. Thanks for the tip, sir. Unfortunately, it still will not compile.
      At the top of each .java file, I have the following code:

      package edu.unm.cs.cs251spr12.batch.lab.feb8;

      import edu.unm.cs.cs251spr12.batch.lab.feb8.*;

      I tried running my code in eclipse and it worked flawlessly; not sure where I'm going wrong...

      Delete
    6. When you compile you need to either type in the whole filepath or cd up to the package directory and compile from there. For example: javac feb8/*.java

      If you have your package named correctly in each file they should compile without errors (of the class not found variety - can't guarantee coding quality ;)

      Delete
    7. That worked like a charm! Thanks for the help, Zane.

      Delete
  8. So at the top of all our java files we should have "package edu.unm.cs.cs251spr12.batch.lab.feb8;"???

    ReplyDelete
    Replies
    1. Yes. Except you should have your username not necessarily "batch".

      Delete