The Lab and pre-lab assignment for Feb. 15 are now available. As usual, a physical copy of your pre-lab assignment is due at the start of lab on February 15th. This lab has been extended and is due February 29th.
I am confused with what is needed for the constructor for Car.java for Feb 15 lab. In fact, on the lab page, the getVIN() method is listed under "Constructor" instead of "Methods". Can someone help me clarify on this?
What is the purpose of having us create our files with in the edu.unm.cs.cs251spr12...... Is it so that we have to write the program using emacs? or to make sure all the files are in the correct package? Just wondering
If your question is regarding putting your files in the repository, it is so you have a back up of all your files and we don't have to collect your work. Instead, we can check it out at any time to see how you are doing.
im not sure what editor you are using if its eclipse i would say you should use emacs, i came into the course only have used eclipse and though using emacs i feel my basic fundamental programming skills and improved, but thats just me hope the link helps =)
in the spec for Car.java the create car looks like public Car(String name, int maxMPH) but should it also have int maxTires? since to Automobile constructors asks for maxTires?
In the write-up, under Automobile, it states that we have to return the VIN as an int:
getVIN() returns a UNIQUE vehicle identification number for the Automobile as an int
I realize we are going to have to use only ints when we test our code. I'm just curious as to why we wouldn't return a string instead, being that an actual VIN has both numbers and letters.
Generating random VIN Strings would be much harder than returning sequential ints. If you would like to take the challenge of generating unique Strings you can create a new method called getStringVIN().
I have a question about the getMPG() method in the Motorcycle class. It says to use a log function to determine the MPG but this seems to make the MPG increase with the speed which doesn't seem right or the MPG to go to infinity as speed goes to 0 which also does not make sense. Anyone else understand what is meant by this.
I think the point is just to learn to compute basic math functions in Java. You're right that none of these functions is realistic for MPG, which generally increases up to a certain "sweet speed", and then starts decreasing above that.
Tom is correct. Basically, you should have to use the @Override for each of the getMPG methods. However, if you are clever do not need to @Override getMaxMPH.
That's right. "svn add filename" adds it to the repository. Well, actually, just to your working copy. It won't be stored in the actual repository until your next "svn commit" (which hopefully you'll do soon afterwards).
constructor Truck(Stirng name, int mpg) name must be non-null mpg must be in the range [35,100] methods getNumberOfTires(); must always return 4 getMPG(int speed) Uses a quadratic function to determine the MPG must return a value in the range [0, 16]
Does the constructor really take a "int mpg" arg and not "int maxMPH"? This makes no sense if we are to use a quadratic function to calculate a value already defined by the user and passed to the constructor.
I assume the constuctor should be: Truck(String name, int maxMPH){}
Our lab instructor, Taylor Berger, suggested making the Automobile class abstract. Would there be any methods in the Automobile class best served by not being abstract?
I would recommend doing at least the getMPG(int speed) method in each individual class. That way you can specify different functionality for each class that extends Automobile. Also, you would learn the syntax for @Overriding methods and understand what overriding actually does.
However, the Motorcycle class does require you to add an extra method that would not be covered in the abstract class. Also, the semi-truck will have to be looked at differently as well.
Like I said in class though, its not part of the spec, so you don't have to do the lab using an abstract class if you don't want to.
The unique IDs do not need to be sequential. However, you must guarantee that they will be unique. If you just use Random.getNextInt() you do not make this guarantee.
What are the expectations for handling argument constraints? For example, if an object is constructed with an invalid value, should we throw an exception, or print a message and allow the invalid value, or print a message and use a default value to allow execution to continue? What about passing getMPG() a speed greater than maxMPG?
Also, do we need to worry about SemiTruck() access to Automobile() fields like int tires?
Because we have not covered exception yet, you can do whatever you like as long as the value returned by the getters do not go out of the bounds of the constructor and you document it.
Also, you should generally not make any non-private data members. If you need to change the functionality of a subclass you should either @Override a method or make a protected setter.
im not sure how to add a file to my svn the command i am using within my working repository is svn add PATH when i do this it gives an error that PATH is not a working copy
First checkout your entire repo directory to somewhere you'll remember. Just type: 'svn checkout https://svn.cs.unm.edu/cs251s12/yourusernamehere' from inside the directory you want it stored.
Then use "svn add path" to add NEW files to your repo. The root of the path you enter is the current directory you are in, so to add all .java files in your current directory, type: "svn add *.java".
To "save" changes to files which already exist in your repo, type: 'svn commit' or 'svn commit -m "yourLogMessageHere"'.
Here is a decent svn tutorial: http://maverick.inria.fr/~Xavier.Decoret/resources/svn/index.html
Yes... that should work. However, it seems that I can't check out my repository. :( I think it's a problem within the system, however. I'll post anything I find out later, after I talk to Mr. Hayes.
You can't pass an argument to a constructor (or method) that doesn't have it in its signature. However, notice that the boolean argument being passed to the Motorcycle constructor isn't really something that make sense for the Automobile class. Conversely, the "tires" parameter to the Automobile constructor isn't something that needs to be passed to the Motorcycle constructor, because, presumably, we already know how many tires a motorcycle should have.
In short, use the Automobile constructor you have, and think carefully about the roles of the various parameters.
You can't use @Override for the Motorcycle constructor, because constructors are not inherited, and therefore cannot be overridden.
Why do we have to make a getNumberOfTires(){} method for each class? When we call the super constructor, don't we give it the number of tires, making it redundant to @Override the Tires method in every other class? Except for the SemiTruck class, because you can't pass the tires to Truck.
One interpretation of the spec is that you don't HAVE to override the "gNOT" method for the subclasses of Automobile, as long as your implementation ensures that the method always returns the correct value for each class.
If you want to pass the number of tires into a constructor for Truck, you just need to code up such a constructor. However, you need to be careful about this. If you make it public, then you could easily create a lot of 1-wheeled trucks.
We're allowed to make our own constructors for these labs? Won't that mess up the tests you guys run, or would you just not even use our made up constructors to test it?
I am starting to get very frustrated with the svn add function. I have been trying to add and commit but I cant get it to stop telling me '.' is not a working copy. I have a working copy in almost all of my upper level directories now, I am getting so confused. I thought this would be easy :(
Michael, did you checkout your repository? That is the first step. svn checkout repositoryURL workingdirectory Then make a working-copy directory for your current project: cd workingdirectory svn mkdir --parents edu/unn/cs/cs251spr12/username/lab/feb15 Then svn commit -m 'I made a directory!' Then go to that directory and make an Automobile.java and Car.java file. Then svn add Automobile.java svn add Car.java svn commit -m 'Added Auto and Car classes'
I strongly suggest you arrange your schedule so you can come to the office hours.
Hi, not quite sure what to do in the getMPG methods. Are we suppose to be creative in making our equations or do they need to be somehow specific? Also, to determine the MPG doesn't the amount of fuel need to be included? I'm probably just not realizing something...
The spec doesn't say anything regarding the accuracy of the calculation. We just need to create some arbitrary function that has an exponential/logarithm/linear expression in it.
Since we know that the functions must evaluate to set ranges, we can start with (for motorcycles): 80 - C*Log(x), where C is a constant. If x (speed) is zero, then the function evaluates to 80. You could, on paper, use a system of equations (Algebra I) to find the value of C which will never cause the function to evaluate to less than the minimum from the spec. Or, just try different values until satisfied.
Also, the MPG method was removed from the lab so you don't have to worry about it anymore. There *may* be some bonus points awarded for those who had it completed before 9am on Feb. 22nd.
Ok I finished the CarCraft lab but I am having a hard time as to how to turn it in because I've been using the computers that have ubuntu... So to connect from a laptop with windows I must download putty and then from there do a ssh because it isn't letting me do so, so I am confused as to how to turn it in
the title of this got me excited since i read it right after a dragon soul raid....thanks for the post on Saturday
ReplyDeleteI am confused with what is needed for the constructor for Car.java for Feb 15 lab. In fact, on the lab page, the getVIN() method is listed under "Constructor" instead of "Methods". Can someone help me clarify on this?
ReplyDeleteBrandon, you are right to be confused. This is in fact a typo. It should be fixed now.
DeleteWhat is the purpose of having us create our files with in the edu.unm.cs.cs251spr12......
ReplyDeleteIs it so that we have to write the program using emacs? or to make sure all the files are in the correct package? Just wondering
If your question is regarding putting your files in the repository, it is so you have a back up of all your files and we don't have to collect your work. Instead, we can check it out at any time to see how you are doing.
DeleteYou do not have to use emacs.
However, it is highly encouraged that you learn emacs. :)
Deletei have found this very helpful in learning emacs
Deletehttps://ccrma.stanford.edu/guides/package/emacs/emacs.html
im not sure what editor you are using if its eclipse i would say you should use emacs, i came into the course only have used eclipse and though using emacs i feel my basic fundamental programming skills and improved, but thats just me hope the link helps =)
in the spec for Car.java the create car looks like public Car(String name, int maxMPH) but should it also have int maxTires? since to Automobile constructors asks for maxTires?
ReplyDeleteIn the write-up, under Automobile, it states that we have to return the VIN as an int:
ReplyDeletegetVIN() returns a UNIQUE vehicle identification number for the Automobile as an int
I realize we are going to have to use only ints when we test our code. I'm just curious as to why we wouldn't return a string instead, being that an actual VIN has both numbers and letters.
Generating random VIN Strings would be much harder than returning sequential ints. If you would like to take the challenge of generating unique Strings you can create a new method called getStringVIN().
DeleteDean Dominguez:
DeleteDo the VIN numbers have to be sequential, or can they be random? Also, does it matter how many digits they are?
I have a question about the getMPG() method in the Motorcycle class. It says to use a log function to determine the MPG but this seems to make the MPG increase with the speed which doesn't seem right or the MPG to go to infinity as speed goes to 0 which also does not make sense. Anyone else understand what is meant by this.
ReplyDeleteI think the point is just to learn to compute basic math functions in Java. You're right that none of these functions is realistic for MPG, which generally increases up to a certain "sweet speed", and then starts decreasing above that.
DeleteTom is correct. Basically, you should have to use the @Override for each of the getMPG methods. However, if you are clever do not need to @Override getMaxMPH.
Deleteso to add a file to the respotory we just type svn add file
ReplyDeleteor is there more
@Burton,
DeleteThat's right. "svn add filename" adds it to the repository. Well, actually, just to your working copy. It won't be stored in the actual repository until your next "svn commit"
(which hopefully you'll do soon afterwards).
Copied and pasted from the lab website:
ReplyDeleteTruck.java extends Automobile
constructor
Truck(Stirng name, int mpg)
name must be non-null
mpg must be in the range [35,100]
methods
getNumberOfTires(); must always return 4
getMPG(int speed)
Uses a quadratic function to determine the MPG
must return a value in the range [0, 16]
Does the constructor really take a "int mpg" arg and not "int maxMPH"? This makes no sense if we are to use a quadratic function to calculate a value already defined by the user and passed to the constructor.
I assume the constuctor should be:
Truck(String name, int maxMPH){}
It should be maxMPH. Sorry about the confusion.
DeleteDean Dominguez:
DeletePresumably then the line "mpg must be in the range [35, 100]" should read 'MPH' not mpg?
I noticed this too in the Automobile.java portion:
ReplyDelete"getMPG(int speed); returns the cars mileage per gallon at the specified speed. speed must be in the range [0, getMaxMPG]."
I wasn't aware that we had to create a getMaxMPG method, is this supposed to be getMaxMPH, instead?
This should say [0, getMaxMPH]. The spec has been updated. Thanks for catching this.
ReplyDeleteOur lab instructor, Taylor Berger, suggested making the Automobile class abstract. Would there be any methods in the Automobile class best served by not being abstract?
ReplyDeleteI would recommend doing at least the getMPG(int speed) method in each individual class. That way you can specify different functionality for each class that extends Automobile. Also, you would learn the syntax for @Overriding methods and understand what overriding actually does.
DeleteHowever, the Motorcycle class does require you to add an extra method that would not be covered in the abstract class. Also, the semi-truck will have to be looked at differently as well.
Like I said in class though, its not part of the spec, so you don't have to do the lab using an abstract class if you don't want to.
The unique IDs do not need to be sequential. However, you must guarantee that they will be unique. If you just use Random.getNextInt() you do not make this guarantee.
ReplyDeleteWhat are the expectations for handling argument constraints? For example, if an object is constructed with an invalid value, should we throw an exception, or print a message and allow the invalid value, or print a message and use a default value to allow execution to continue? What about passing getMPG() a speed greater than maxMPG?
ReplyDeleteAlso, do we need to worry about SemiTruck() access to Automobile() fields like int tires?
Because we have not covered exception yet, you can do whatever you like as long as the value returned by the getters do not go out of the bounds of the constructor and you document it.
DeleteAlso, you should generally not make any non-private data members. If you need to change the functionality of a subclass you should either @Override a method or make a protected setter.
Dean Dominguez:
ReplyDeleteIs anyone else having a hard time remoting in? Seems every time I try it's busy.
Try connecting using trucks.cs.unm.edu
DeleteI'm having a lot of problems as well with both trucks and moons. The internet has been pretty bad lately on campus.
Deletei have a svn question
ReplyDeleteim not sure how to add a file to my svn
the command i am using within my working repository is
svn add PATH
when i do this it gives an error that PATH is not a working copy
i guess im not sure what a working copy is
Thanks
Derek
First checkout your entire repo directory to somewhere you'll remember. Just type: 'svn checkout https://svn.cs.unm.edu/cs251s12/yourusernamehere' from inside the directory you want it stored.
DeleteThen use "svn add path" to add NEW files to your repo. The root of the path you enter is the current directory you are in, so to add all .java files in your current directory, type: "svn add *.java".
To "save" changes to files which already exist in your repo, type: 'svn commit' or 'svn commit -m "yourLogMessageHere"'.
Here is a decent svn tutorial: http://maverick.inria.fr/~Xavier.Decoret/resources/svn/index.html
Yes... that should work. However, it seems that I can't check out my repository. :( I think it's a problem within the system, however. I'll post anything I find out later, after I talk to Mr. Hayes.
DeleteI'm also having trouble checking out/adding anything to my repository. Anyone else having problems?
DeleteI'm having trouble passing the information from the Motorcycle class to the Automobile superclass.
ReplyDeleteHow do we pass a boolean to a superclass constructor that doesn't allow for one? Do we need use a @Override for the Motorcycle constructor?
You can't pass an argument to a constructor (or method) that doesn't have it in its signature. However, notice that the boolean argument being passed to the Motorcycle constructor isn't really something that make sense for the Automobile class. Conversely, the "tires" parameter to the Automobile constructor isn't something that needs to be passed to the Motorcycle constructor, because, presumably, we already know how many tires a motorcycle should have.
DeleteIn short, use the Automobile constructor you have, and think carefully about the roles of the various parameters.
You can't use @Override for the Motorcycle constructor, because constructors are not inherited, and therefore cannot be overridden.
Ok, this makes more sense. I was under the impression that we HAD to send the 'isCrotchRocket' data to the super-class.
DeleteWhy do we have to make a getNumberOfTires(){} method for each class? When we call the super constructor, don't we give it the number of tires, making it redundant to @Override the Tires method in every other class? Except for the SemiTruck class, because you can't pass the tires to Truck.
ReplyDeleteOne interpretation of the spec is that you don't HAVE to override the "gNOT" method for the subclasses of Automobile, as long as your implementation ensures that the method always returns the correct value for each class.
DeleteIf you want to pass the number of tires into a constructor for Truck, you just need to code up such a constructor. However, you need to be careful about this. If you make it public, then you could easily create a lot of 1-wheeled trucks.
We're allowed to make our own constructors for these labs? Won't that mess up the tests you guys run, or would you just not even use our made up constructors to test it?
DeleteDean Dominguez:
DeleteJust to be clear, we DO NOT have to include gNOT methods in the subclasses. We wont get dinged on the requirements, if we just use the super class?
I am starting to get very frustrated with the svn add function. I have been trying to add and commit but I cant get it to stop telling me '.' is not a working copy. I have a working copy in almost all of my upper level directories now, I am getting so confused. I thought this would be easy :(
ReplyDeleteMichael, did you checkout your repository? That is the first step.
Deletesvn checkout repositoryURL workingdirectory
Then make a working-copy directory for your current project:
cd workingdirectory
svn mkdir --parents edu/unn/cs/cs251spr12/username/lab/feb15
Then
svn commit -m 'I made a directory!'
Then go to that directory and make an Automobile.java and Car.java file. Then
svn add Automobile.java
svn add Car.java
svn commit -m 'Added Auto and Car classes'
I strongly suggest you arrange your schedule so you can come to the office hours.
Just an FYI, I have tutoring hours from 3pm to 6pm tomorrow. You should try to come by.
DeleteHi, not quite sure what to do in the getMPG methods. Are we suppose to be creative in making our equations or do they need to be somehow specific? Also, to determine the MPG doesn't the amount of fuel need to be included? I'm probably just not realizing something...
ReplyDeleteI have the same problem.....
ReplyDeleteThe spec doesn't say anything regarding the accuracy of the calculation. We just need to create some arbitrary function that has an exponential/logarithm/linear expression in it.
ReplyDeleteSince we know that the functions must evaluate to set ranges, we can start with (for motorcycles): 80 - C*Log(x), where C is a constant. If x (speed) is zero, then the function evaluates to 80. You could, on paper, use a system of equations (Algebra I) to find the value of C which will never cause the function to evaluate to less than the minimum from the spec. Or, just try different values until satisfied.
Also, the MPG method was removed from the lab so you don't have to worry about it anymore. There *may* be some bonus points awarded for those who had it completed before 9am on Feb. 22nd.
DeleteOk I finished the CarCraft lab but I am having a hard time as to how to turn it in because I've been using the computers that have ubuntu... So to connect from a laptop with windows I must download putty and then from there do a ssh because it isn't letting me do so, so I am confused as to how to turn it in
ReplyDelete