I’m going to extend the deadline for Zork++ phase 3 to Monday at midnight, just because I’m in a good mood today and somebody asked me so nicely.
-
Zork++ phase 3
-
Quiz #5 code posted
Here’s the code to the Composite pattern problem from quiz #5, in case you want to play around with it:
The complete and correct output is:
It's moving day! A 10-item cardboard box A 2-item plastic perishable box A 2-item cardboard perishable box A 2-item wooden perishable box We're hauling 991 lbs
-
Office hours canceled tomorrow
Alas, I’m not going to make it to campus at all tomorrow (Thursday, Apr 25). Send questions over email!
-
Last quiz
As promised, quiz #6 has been posted and is due Monday at midnight.
Apologies for taking so long to get quiz #5 graded; it’s coming soon.
-
Spend your summer wisely
Like marathon running or piano playing, I promise your programming skills will atrophy down to virtually nothing if not exercised regularly. Here are some ideas for how to spend your summer profitably and keep your skills up to date!
For marathon running, I recommend running 5 hours a week, taking a day off every three days. For piano playing, I recommend playing an hour each and every day. For programming, I recommend coding at least a half hour each and every day.
-
Office hours truncated today
Today my office hours will only be from 3:15-4pm, as I have an honors defense I need to attend.
-
Parallelism demo code (Cheerleader) posted
From today’s class, the Cheerleader example.
-
The coup de grâce!
You knew it was coming! Now’s your chance to fully realize all your hopes and dreams. Can’t wait to play everyone’s exciting adventures!
-
Decorator example code posted
The decorator pattern example from today’s class, in case you’d like to review it or run it yourself:
- Armor.java
- Character.java
- Combatant.java
- Fighter.java
- FireShield.java
- Lotr.java
- MagicUser.java
- NonPlayerCharacter.java
- Orc.java
- ProtectionDevice.java
- Zombie.java
The correct output, again, was:
Orc #1 dead after two attacks. Huzzah, Saruman hath been slain! Huzzah, Saruman hath been slain! Gimli appears impervious to attack. The zombie is dead!
-
LOL miscommunication
I intended to start the parallelism and concurrency material today after the activity, but apparently some people thought (understandably, actually) that class was over, and left. So I didn’t feel like starting it with half the people missing the class because of a miscommunication.
So. For those in the afternoon section, you can know that we’ll be done after just one hour today, rather than doing our normal two-hour Wednesday.
-
About Quiz #5
To save as much remaining class time as possible, Quiz #5 will be a “take on your own” affair. It will open Friday at 11am, and be due Sunday at midnight. You may take it any time between now and then. It is timed at 60 minutes, and must be Honor pledged (the last question).
-
IMPORTANT!!
From this point on, and unless/until you hear otherwise, please do NOT use:
$ javac *.java
to compile your code. Instead, use:
$ /usr/bin/javac *.java
to compile your code.
That’s it!
-
Strategy example code posted
The strategy pattern example from today’s class, in case you’d like to review it or run it yourself:
- Book.java
- DefaultPricingStrategy.java
- DiscountPerishablePricingStrategy.java
- FixedDiscountPricingStrategy.java
- Foodstuff.java
- Item.java
- Main.java
- PricingStrategy.java
- ShoppingCart.java
- User.java
The correct output, again, was:
A 3-item, $30.0 cart owned by Dwayne A 4-item, $28.8 cart owned by Robyn A 31-item, $38.4 cart owned by Robyn The holiday season is here! A 3-item, $30.0 cart owned by Dwayne A 4-item, $36.0 cart owned by Robyn A 31-item, $24.0 cart owned by Robyn
-
Iterator pattern sample code posted
From today’s class, the Iterator pattern example.
-
Recommended reading
For the design patterns unit of the course, I recommend the Wikipedia articles on each pattern. Just search Wikipedia for Strategy pattern, Decorator pattern, Composite pattern, Iterator pattern, and Observer pattern.
-
Stephen’s tattoos
Here’s my solution to SWYK check #6:
-
My art solution
A couple people asked to see my solution from last week’s SWYK check, so here it is:
-
Zork++ phase 2 posted!
No surprises with Zork++ phase 2! Build that thing! (Standard features only, please.) It’s due midnight Wednesday April 17th.
-
Actual due date for Zork++ phase 1
I’m a late sleeper, and will probably roll in to the office about 11am tomorrow. Anything that’s in my 240 manila envelope (or under my door) at that time will be counted as on time.
-
Another office hours switch
I need to move my office hours for tomorrow (Thu Apr 4) to 3:30-4:30pm instead of their regularly scheduled 11-2pm. I apologize for any inconvenience.
-
Sample PUML file for sequence diagrams
You can look at the source code for the Zork v1 sequence diagram I originally posted.
-
Class canceled Monday
We won’t have class on Monday, since many people want to watch the eclipse at a place of their choosing. (I’m told it will last from about 2:00pm-4:30pm in Fredericksburg, with the maximum eclipse at 3:19pm.) I plan on office hours at the usual time.
-
Office hours switch
I need to move my office hours for tomorrow (Wed Apr 3) to 4-5pm instead of their regularly scheduled 10-11am. I apologize for any inconvenience.
-
Using PlantUML
Again, let me reiterate that your team can use any drawing tool y’all like to draw the UML diagrams. (Do please agree on a single tool within your team, however.)
If you’d like to use PlantUML as I briefly demo’d in class today, there are a couple of options:
- There’s a Web-based version of PlantUML that allows you to copy/paste PlantUML “code” and press a button to get the rendered diagram. You can reach this by clicking “Online server” on the left menu of the plantuml.com landing page.
- Ian has installed PlantUML globally on the cpsc server. All you need to do is write your PlantUML file using vim, then type: “$ plantuml nameOfYourDesignFile.puml“, and it will produce a nameOfYourDesignFile.png file that you can download (using Filezilla, etc) and view.
-
Stephen’s solution to sample SWYK check posted
Here’s my solution to the cell phone SWYK check:
-
Zork++ (team project!) assigned!
The next phase of your Zork saga has been posted, and is due a week from Monday. I’m sure I don’t even need to mention that your team should be thinking about this and meeting about it early! Like, how about arranging a meeting time right now?
-
Running late
If I’m not there on time, please just take the quiz at the usual time and in the usual way! Be there as quick as I can.
-
Next SWYK check
As determined by various discussions and a secret ballot today, the next SWYK check will be:
- Next Wednesday, April 3rd, during the second half of class (namely, noon for the morning section and 3pm for the afternoon section)
- Individual, not paired
-
Another practice SWYK check
Here’s another practice SWYK check which I’d encourage you to do before our next for-reals SWYK check, which will be April 5th.
-
Making the LookCommand work
A couple teams have asked how they can return the full description of a room even if it’s already been visited. There’s a couple different ways to do that, all of which are a little awkward. One way is to add a method like “.unvisit()” to the GameState class, which you can call to briefly “unvisit” a room before you re-visit it. Another way is to add a second “describe-type” method; perhaps “.describeFull()” which always returns the full description no matter what.
-
Class/OH on Zoom Monday
I strained my back pretty badly this weekend, and I think I need to give it another day’s rest before I consider leaving the house or walking anywhere. So I will see you guys on Zoom at 11am/2pm tomorrow. Office hours will be virtual as well; same Zoom link as always (see the announcements in Canvas).
-
Stephen’s SWYK check 4 solution
Here’s my solution to today’s SWYK check:
-
Thursday office hours are 1-2pm for realsies
There was some confusion (my fault) about when my Thursday office hours would normally be. So I hereby state for the record that from now on this semester, they will be at 1-2pm. Sorry for the mixup about this!
-
Please read
A startling number of students (six, by my count) apparently decided to drop this class without informing me or even their teammates, which has led to several teams being abandoned without warning halfway through the Zork III development cycle. (As an aside, I would encourage you to very much consider not doing things like this in life. Acting in selfish ways that negatively affect others is a bad habit to get in. The world is not all about you. It’s about the whole human race.)
Anyway, because of this, I feel I must extend the Zork III deadline to give these broken-then-patched-together teams a fighting chance to finish it on time. So Zork III is now due Thursday, March 28th at midnight.
Carry on…
-
Office hours confusion
I think I miscommunicated (and am even confused myself) about my Thursday office hours. I was in from 1-2pm today, and had a fair crowd (three students). But I just got an email from a student saying they thought I was having them at 3:30pm. I don’t even know myself anymore. :\
Anyways, I’m home now, and won’t be returning to campus until a student club meeting tonight, but I’m happy as always to help via email.
Sorry!
-
Stephen’s solution to practice SWYK check
Here is my solution to the practice SWYK check:
-
“divergent branches” error
If you are getting a “divergent branch” error, I believe the likely fix is to run this command:
$ git config pull.rebase false
-
github and SSH keys
Be sure to remember that creating a github account involves setting up SSH keys. Read the CPSC 225 notes from Ian on that topic if you need a refresher how.
-
Practice SWYK check posted
Here’s a SWYK check from last semester which you are encouraged to do on your own for practice before Friday’s main event.
Suggestion: work on this together with your Zork teammates, as practice and camaraderie!
-
Zork III (team project!) assigned!
I have posted the next installment of the Zork project, and this one marks an important milestone: the transitioning from working alone to working together.
Please check your email as soon as you read this to discover who your teammates and begin meeting them and working with them right away! You should plan to meet early and often this week to get things off on the right foot.
Happy Zorking, everybody!
-
Another tutor has appeared!
Kenzie will be available for tutoring on a walk-in basis in HCC 211 on Wednesdays 3:30-5:30pm.
-
Office hours on Zoom today
Hit me up from 1-2pm; I’ve put the Zoom invite in Canvas.
-
Code samples
From yesterday’s class:
Passing arguments to superclass constructor:
Using multiple interfaces, not multiple inheritance:
Using the Comparable interface:
-
Test on westeros.zork
Here’s a larger zork file that you can and should use to make sure your Dungeon hydration procedure is bulletproof.
-
Updated zoo code (top-down inheritance) posted
From today’s class, the updated versions of:
-
Game plan
If memory serves, our game plan for this week was to:
- Spend a little time reviewing the SWYK check on Monday, for those who didn’t get much of it working the day before break.
- Finish up inheritance plus some Java odds & ends from chapter 3 during Wednesday’s lecture. (And also hear from VA Tech grad school opportunities.)
- Quiz #3 will be Friday the 15th, and will concern mostly inheritance concepts (although as always, everything’s fair game).
- Finally, SWYK check #4 will take place on Friday the 22nd.
See everybody tomorrow!
-
Stephen’s solution to SWYK check 3
Here’s my solution to SWYK check 3:
-
“The Dungeon isn’t there yet”
I realized today in office hours that there was a slight bug in my Zork II design; namely, when Exits are being hydrated, they need to be able to get Room objects that match the names in the file, yet the Dungeon is in the process of being hydrated, and so isn’t available yet.
This seems like the cleanest fix:
- Add a .setDungeon() accessor method to GameState in order to access the Dungeon object. (This is now reflected in the class diagram.)
- Add this line of code as the first line of the new Dungeon constructor:
GameState.instance().setDungeon(this);
Now, in the Exit constructor, you’ll be able to safely call GameState.instance().getDungeon().getRoom() so that you can wire up your hydrated Exits to the right Rooms.
-
Connor, another Peer Tutor
Connor is another peer tutor, who will be available on a walk-in basis in HCC 210 on Thursdays 4-5pm.
-
Permanent Thursday office hours switch
Because of (reasons), I’m switching my Thursday office hours for today and the rest of the semester from 1-2pm to 3:30-4:30pm.
This has been a public service announcement.
-
Not quite one-liners
I said in the Zork II description that the exception classes would be one-liners. To be fair, if you have the ability to add a String to an IllegalDungeon/SaveFormatException object, then you need a constructor in there too.
Just to eliminate confusion, here is, verbatim, the complete code for the four Exception classes:
public class NoRoomException extends Exception {} public class NoExitException extends Exception {} public class IllegalDungeonFormatException extends Exception { public IllegalDungeonFormatException(String e) { super(e); } } public class IllegalSaveFormatException extends Exception { public IllegalSaveFormatException(String e) { super(e); } }
The first of these four snippets should be in NoRoomException.java. The second should be in NoExitException.java. The third should be in IllegalDungeonFormatException.java. The fourth should be in IllegalSaveFormatException.java.
Now move on to step b.
-
Code from today’s class
From today’s (afternoon) class:
-
Zork II posted!
No rest for the weary! Zork II has been posted, and is due on March 13th at midnight.
Important note: If you didn’t get your Zork I working properly, you should download my Zork I to use as a starting point, then continue from there. My git bundle is in the Files tab of Canvas, and is called zorkI_stephen.git. You can unpack it with:
$ git clone zorkI_stephen.git zorkII
This will give you a new directory (called zorkII) underneath your current directory. You can cd in there to work on all the code for this project.
-
Zork I solution posted
I have posted my solution to Zork I in the “Files” tab of Canvas. (The bundle is called “zorkI_stephen.git“. After downloading it to your machine, and/or uploading it to the cpsc server, you can unpack it with the command “git clone zorkI_stephen.git aNewDirectoryName“. This will make a directory under your current directory called aNewDirectoryName with all my code in it. You can ignore the stuff in “design” for now; these are PUML files for the design diagrams, and I’ll speak more about them later.)
There are three reasons I’m posting this:
- For those who successfully completed Zork I, you might be curious to see how I did certain things. Feel free to poke around under the hood. Note that my solution is not “better” than yours; it’s just different.
- For those who did not successfully complete Zork I to see how it’s done. Please peruse in depth and detail.
- For those who did not successfully complete Zork I to use as a starting point for their Zork II project, coming later today.
-
Missing afternoon class today
I’m not going to be able to make it to campus by the time the afternoon quiz starts today, so afternooners please just take the quiz as normal, in the usual time and in the usual place and in the usual way, and I’ll see you again on Monday.
-
Passing “this”
Remember: “this” means “the object the method was called on.” You can use it as a reference variable just like any other — it’s on the stack like everything else with a name. And it can be passed to a function/method that has an argument of the appropriate type.
For instance, here is a perfectly reasonable line of code one might find in a Room class:
... if (GameState.instance().hasBeenVisited(this)) { ... } ...
-
Office hours switch
Today’s office hours will be 3:30-4:30pm instead of the usual 1-2pm. Sorry for any inconvenience. Email, as always, is open any time.
-
If you get this error
If you get a compile error that says:
instance variable x was not initialized inline nor in all constructors
you may need to set your inst vars to null (or zero, if numeric) where they’re declared. Like this:
class Car { private String make = null, model = null; private int odo = 0; ... }
-
SWYK check 2: Stephen’s solution
Here’s my solution to SWYK check 2.
-
entryRoom inst var
You may recall me mentioning in class that my drawing tool kept stupidly drawing the “entryRoom” arrow on top of the “rooms” arrow between the Dungeon and Room boxes on the diagram. So I had to omit it. But there should indeed be another “has-a” association from Dungeon to Room, with multiplicity 1, which translates into another inst var of type Room (called “entryRoom”) in the Dungeon class.
-
Installing vim plugins
There’s lots of ways to install vim plugins. It’s been a while since I’ve installed a new one, but here’s a procedure I just Googled and verified. I’m showing it here for the “supertab” plugin, but you can substitute any other plugin for the “supertab” line below:
- Install the Vim-Plug program. Just type this at the command line:
$ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
- Open your .vimrc file (or create it if it doesn’t already exist) in vim.
- At the very bottom of this file, add these lines:
call plug#begin() Plug 'ervandew/supertab' call plug#end()
- Quit vim and open vim again (by typing just “vim“). Then type:
:PlugInstall
and press Enter. You’ll get a happy message in the left-hand pane. Quit out of vim (with “:qa“) and reopen it. You should now be able to use “supertab” (tab completion of words already in the file you’re editing) like I do in class.
Finally, if you’d like to browse various plugins, there are millions. One list is here: https://vimawesome.com/.
- Install the Vim-Plug program. Just type this at the command line:
-
“Heroes” code (with HashSets and Hashtables) posted
Here’s our code from today.
-
Zork I posted!
As promised, this big monster (which constitutes the first stage of your semester-long project) has been posted. It is due on Saturday the 24th at midnight, and is not for the faint of heart.
DO!
NOT!
PROCRASTINATE!
-
SWYK check 1: Stephen’s solution
Here’s my solution to today’s SWYK check problem. Perusing this and comparing with yours is an excellent and praiseworthy idea.
-
Upcoming events
Consider attending these!
- The NSWC-DD job fair
- The CyberBytes Capture-the-Flag contest
- The ORISE internship program
-
In-class Singleton code (“Government”) posted
Here’s the code for the Government Singleton class we wrote together on Friday, plus some client code that uses it.
-
Updated Car class (with exceptions) posted
Here’s the updated version of the Car class, which throws an Exception from .drive() to indicate errors.
-
New homework posted!
This fun and light-hearted assignment is designed to familiarize yourself with Zork, the text-based adventure game which will be dominating much of your life in the coming weeks. It’s due Saturday, Feb 10th at midnight.
Happy adventuring!
-
Career-oriented events
Those interested in working in high-tech for actual wages may be interested in the following career-related activities coming up soon:
- Career Connections (Thursday, Feb 8th, CRUC’s Chandler Ballroom)
- The NSWC Dahlgren job fair (Tuesday, Feb 13th, Fredericksburg Convention Center)
-
Extra credit code
The solution to yesterday’s extra credit problem was:
Yoduh May duh 4S B which U!
And here’s the code for it: CrazyInClassExercise.java and Thingamajig.java. You can copy these directly from the Internet to your cpsc account through these commands:
$ wget http://stephendavies.org/cpsc240/CrazyInClassExercise.java $ wget http://stephendavies.org/cpsc240/Thingamajig.java
-
.gitignore files
For anyone who forgot to write down the instructions about .gitignore files from class yesterday, and wants to create one, it’s actually described in a later chapter of the book. (See pp.219-220.)
-
Window dressing
All that needs to pass “diff” is the bulk of your output — all the Star Wars names, Sith Lord names, preceded by the proper numbers, etc. You don’t need to worry about whether the first couple lines of output are different from galaxians.txt (like if you didn’t print “Welcome to the Star Wars name generator!” with the same capitalization, or if you have all the prompts for input in your file).
-
Two ways to get help from Stephen
Most of the time, to help you with errors in your program, I’m going to actually have to see your program so that I can compile it myself, run it, make changes, insert debug statements, etc. There are two ways to get this to me:
- The cumbersome way: send me your .java files as email attachments, after downloading them to your machine (using, say, FileZilla).
- The quick way: in your “help me!” email, tell me the full path to your project directory (i.e., the output of “pwd“). Then I can use my Jedi Master superpowers to go into the cpsc server and spy on your code directly.
“It’s your choice, but I warn you not to underestimate my powers.” — Luke Skywalker
-
Virtual office hours today
I’m home today with a nasty calf muscle pull. You can reach me on Zoom during our office hours time, and I will post the link to my Zoom meeting room in Canvas.
-
“Making each Person variable name different”
Quite a few people are getting stuck on the question, “if the user enters 50 people, how do I come up with 50 different variable names to hold each of the 50 different Person objects?”
The answer is: you don’t. You don’t need a different variable name for each Person. You just need one, which will temporarily hold on to the Person just long enough to insert it into your list. Here’s the pattern:
ArrayList
people = new ArrayList (); while (...) { ... Person p = new Person(....) people.add(p); } When this loop completes, voilà! you now have an ArrayList that holds all the Persons. Only one variable name (p) was ever needed.
-
The first, and only, extension of the semester
The first program of the year has been extended, and is now due Saturday Feb 3rd at midnight.
This will be the only extension of the semester. The only reason I’m granting it is that I want to make darn sure this first easy program is a success, and I’m choosing to bail out students who have not set themselves up for success on it. Be forewarned!
P.S. Those who meet the original deadline will get 1 extra credit point.
-
Permanent office hours switch
I’m switching my Monday morning 10-11am office hour to Tuesdays 3:30-4:30pm for the rest of the semester. Just an FYI!
-
Yesterday’s code posted
Our first version of the Car class has been posted. To be improved!
-
Programming assignment posted!
Your first semi-real programming assignment of the semester has been posted, and is due next Thursday at midnight.
I call it “semi-real” because it is not a simple connect-the-dots exercise as the setup homework was, but neither is it as complex as the Zork project, which will be coming in phases before you know it.
START EARLY on this, and demonstrate a consistent effort over time. That is the way to succeed.
-
Responsive reading #1 posted!
The first responsive reading assignment of the semester has been posted, and is due to my manila envelope this Friday before Farmer Hall closes. Send questions!
-
Setting your git identity
A couple students have reported that when they got to step 4 of p.19 on the homework assignment, git complained at them telling them it didn’t know who they were.
Right, it’s been so long I forgot about that. The first time you use git, you’ll need to enter these three commands (in the first two, be sure to replace the text with your actual first and last name, and with your actual email address):
$ git config --global user.name "Your First And Last Name" $ git config --global user.email yourUMWNetID@umw.edu $ git config --global core.editor vim
Do this right before doing step 4 on p.19.
-
Extra credit: AI tools in programming
For up to 2 points of extra credit, read my recent blog post and write a 2-3 paragraph response (about ½ single-spaced page). In the response, you should either agree or disagree with my claim, and support your position well. (You are not required to agree with me in order to get a good grade; feel free to disagree with me if you believe I am wrong.)
Turn in your printed response to the “240” manila envelope hanging outside my office door by Tuesday, Jan. 23rd at 5pm.
-
Welcome!
Hey everybody, welcome to the spring 2024 edition of CPSC 240: Object-oriented Analysis with Stephen!
This site is gonna be hip-hoppin’ with all kinds of great stuff real soon, so stay tuned!