CPSC 240

  • Syllabus
  • Office/Tutors
  • Readings
  • Assignments
  • Today’s code examples posted

    I have posted today’s code as a github repo. If you’d like to get a copy of its code, just enter this in your workspace:

    $ git clone git@github.com:divilian/anotherzoo.git anotherzoo
    

    and voilà, you’ll have an anotherzoo directory with its contents.

    Oct 15

  • First team assignment (Zork III) posted!

    Okay gang, I hope you’re well-rested from fall break. It’s time to take a hard pivot into the team-centric portion of the semester, starting with the new homework assignment!

    Note very very carefully that this is a team assignment. Do not start plunging in and working on it yet! Instead, read your email for a very important message about your team assignment, and make contact with your team! They will be your compatriots from now until the end of the term.

    That said, do start reading the assignment and begin to wrap your head around it! Lots of fun here, which will take significant time on all y’all’s part to experience. Start building that in to your schedule and expectations!

    Oct 14

  • Test dungeon posted (westeros.zork)

    For your reference, here’s the dungeon that I’m battle testing your Zork II on. You can download it to your workspace via:

    $ wget http://stephendavies.org/cpsc240/westeros.zork .
    
    Oct 13

  • Quiz #3 postponed

    So, it turns out we’re not ready for quiz #3 yet. The material it covers everything up through and including chapter 12, which we haven’t yet reached in class. We’ll have to do quiz #3 the following week, probably in-class Monday the 20th. Stay tuned for more.

    Oct 12

  • Office hours time change — Tue 10/7

    On Tuesday the 7th, my office hours will be 1:30-3:30pm instead of the normal 12-2pm.

    Oct 6

  • Today’s Caravan code posted

    From today’s class:

    • RoadTrip.java
    • Car.java
    • Caravan.java
    Oct 6

  • Zork II: let the class diagram win

    A couple of brilliant students have pointed out to me this weekend that there’s an inconsistency between the class diagram and the sequence diagram for Zork hydration: in the class diagram, I have the (new) Exit constructor only taking a Scanner as an argument, whereas the seq diag shows it taking a Dungeon object as well. What gives?

    Note that the fundamental “problem” here is: how will an Exit object that’s being hydrated get access to the actual Room objects it needs to connect itself to? One way is to hand its constructor the Dungeon object so it can call .getRoom() on it. Another way is to have the Exit constructor go through the (globally accessible) GameState object to get the Dungeon, which it can then call .getRoom() on. (I’m all ears for a third option.)

    The reason for the discrepancy has to do with the version history of the Zork design. The seq diag is older, and is actually from my previous Zork design from a few years ago. In that older design, I did things the “give the Dungeon to the Exit constructor” way. Since then, I’ve decided I like it better to not have to pass that extra argument, since the Exit constructor (or anything in the program, actually) can always get the Dungeon by going through the GameState.

    Bottom line: you can do it either way and it’s fine. Since I prefer the new design choice, I recommend you let the class diag “win” over the seq diag in this case. But it’s not require that you adhere to one vs. the other.

    Postlude: why not just fix your &@#$*!! sequence diagram, Stephen? Answer: because this exact scenario made for such a good learning experience. 🙂

    (Extra credit to Odari and Morgan for calling out this contradiction.)

    Oct 5

  • Stephen’s solution to SWYK check 2 posted

    Here’s my solution to Wednesday’s SWYK check.

    Oct 3

  • Custom Exception classes

    There’s a bit of confusion about the Exception subclasses defined in the Zork II design, which is understandable since they use inheritance and we haven’t covered that yet.

    Let me make it easy for you. You should create a file called IllegalDungeonFormatException.java and put exactly these contents into it:

        public class IllegalDungeonFormatException extends Exception {
            public IllegalDungeonFormatException(String e) {
                super(e);
            }
        }
    

    Likewise, you should create a file called IllegalSaveFormatException.java and put exactly these contents into it:

        public class IllegalSaveFormatException extends Exception {
            public IllegalSaveFormatException(String e) {
                super(e);
            }
        }
    

    You should also create a file called NoRoomException.java with exactly these contents:

        public class NoRoomException extends Exception {}
    

    and finally, a NoExitException.java with these contents:

        public class NoExitException extends Exception {}
    

    Save those, make sure they compile (to catch typos), and commit them to your repo. From now on, whenever you discover a problem in a .zork file you’re hydrating (like, for instance, that the third line is anything other than literally “===“) you can write this code:

        if (bad thing happens) {
            throw new IllegalDungeonFormatException("Third line is not ===!");
        }
    

    Any time you read a .sav file and find something wrong (like, for instance, that there is no “Room states:” section), you can write this code:

        if (other bad thing happens) {
            throw new IllegalSaveFormatException("Missing 'Room states:' section!");
        }
    

    And of course when you reach the end of the rooms, or exits, while hydrating a Dungeon, you’ll be doing these things:

        ...
        throw new NoRoomException();
    

    and

        ...
        throw new NoExitException();
    

    exactly as described in chapter 10.

    Oct 3

  • Zork II sequence diagram posted

    To help you wrap your head around the hydration process, check out this sequence diagram (click on it to enlarge) which illustrates it:





    Oct 1

  • Zork II posted!

    The next installment of your Zork project has been posted, and is due midnight, Oct 10th. Read through it as soon as you read this, and get your neurons fermenting!

    For those who struggled with Zork I, and did not end up producing a working version, you should start with my Zork I solution. It is in Canvas, in the “Files” tab, and is called zorkI_stephen.git. To pursue this route, you should:

    1. Download that file to your local machine.
    2. Use scp or Filezilla or any other method to upload it to your workspace on cpsc.umw.edu.
    3. On cpsc.umw.edu, figure out where you want to unpack it, and move the zorkI_stephen.git file to that directory. (The pwd, cd, ls, mkdir, and mv Linux commands may all come in handy here.)
    4. Once the file is in the location where you want to unpack it, cd to that directory, and type:
      $ git clone zorkI_stephen.git zorkII
      

      This will make a new “zorkII” directory in your workspace. If you go inside it (with cd) and look around, you’ll see a src directory with all my code inside. This new zorkII directory is a git repo (as you can verify with ls -a and looking for .git in the output). Proceed on the assignment using the code in this directory, and perform all git commits in this new repo.

    Oct 1

  • Dealing with compile errors correctly

    Here’s a pro-gamer tip you may or may not know: whenever you compile (with javac) and get errors, always inspect and fix the first compile error in that list of errors, then re-compile. Don’t pick and choose from all the error messages to decide which one to fix first. This is because of “cascading errors”: if you have something syntactically wrong on line 17, that will often confuse the compiler into misinterpreting all the stuff on lines 18-100, which may give a slew of (ultimately non-)errors.

    Sep 25

  • Interpreter does instantiate Dungeon, Room, and Exit objects

    The Interpreter (specifically, the buildSampleDungeon() function) will instantiate Dungeon, Room, and Exit objects in order to build your little toy 5-room dungeon. These lines are not shown on the class diagram, and PlantUML is being finicky for me so I’m going to choose not to try and add those to the diagram but instead simply affirm the relationships in this announcement.

    Thanks to Morgan for catching this.

    Sep 24

  • Missing “Dungeon has-a Room” arrow

    Not only will every Dungeon object have a Hashtable of Room objects, as shown on the original diagram, but also every Dungeon object will have, as a separate instance variable, a Room object that is designated as “the entry room.” (This is where the adventurer will initially spawn when the game begins. In the original Zork, I think it was “West of House” or some such.)

    I added this line to the diagram now, though it’s kind of hard to make out since PlantUML keeps drawing the two lines nearly on top of each other. Anyways, just be aware that there should be two different associations between the Dungeon and Room classes: one for “all the rooms” and one for “specifically the entry room.”

    Thanks to Odari for catching this.

    Sep 23

  • Stephen’s SWYK check 1 solution

    Take a look at my solution to SWYK check 1 if you’d like to see where you might have gone wrong. And ask questions any time!

    Sep 22

  • Programming assignment (Zork I) posted!

    As promised, Zork I (your first real programming assignment of the semester) has been posted. It is due at the end of the month. Warning: procrastinating on this assignment will result in certain death. I can tell you this from years of experience teaching this class. This is true even if you started igpay at the last minute and got it perfect. The Zork homework, and all that follow, are at a completely different level than Igpay was, I promise you.

    Suggestion: work on this assignment a little bit every day between now and the due date.

    Suggestion 2: for today’s “little bit,” start by simply reading the assignment, start to finish!

    Sep 20

  • Homework posted!

    This lil’ homework should be relaxing and fun for you, and can be viewed as “the calm before the storm.” (The “storm” is programming assignments #2 and beyond.)

    Good luck, adventurer! This little 10-pointer is due next Friday at midnight.

    Sep 13

  • Hint: reading an entire line of input

    If you’ve instantiated a Scanner object, like so:

      Scanner input = new Scanner(System.in);
    

    then you can read an entire line of input from the user this way:

      System.out.print("Where do you want to go today? ");
      String destination = input.nextLine();
    

    Now, if the user types “New York City“, the value of the destination variable will be “New York City“.

    However, if you do this instead:

      System.out.print("Where do you want to go today? ");
      String destination = input.next();
    

    (stare carefully to see the difference) then Java will only read the first word of the input, and leave the rest dangling on the input stream for later. In this case, the value of destination will be “New“.

    Strange but true.

    Sep 11

  • Crazy in-class example

    I have posted the code for today’s crazy in-class activity to a github repo. This is the “normal” way to share code, and the way you’ll be doing it all semester with your team.

    To get the code, cd to whatever directory on cpsc.umw.edu you’d like to put the code in (you can create a new directory for this purpose if you’d like) and type this command:

    $ git clone git@github.com:divilian/CrazyInClassExample.git
    

    This will clone my repo in your local workspace on cpsc. You can then cd into the directory it made (CrazyInClassExample) and see, compile, and run all the code.

    You might ask, “in general, how does one know what to put after the “git clone” part? Answer: on the repo’s home page, click the green box that says “Code” and copy the link in the “SSH” tab. That’s what you paste immediately after typing “git clone“.

    (Btw, if you don’t have your github SSH keys set up like Ian specified, you’ll instead choose the “HTTPS” tab, and paste that URL after “git clone” instead.)

    Finally, the answer to the activity is:

    Yoduh May duh 4S B which U!
    Sep 10

  • Department events

    Some exciting upcoming department events: please consider attending!

    • Monday = CyberClub Interest Meeting @ 6:00 in HCC 111
    • Weds = GMU Accellerated Grad Program Info Session @ noon in Farmer 041 (free pizza)
    • Weds = UMW CPSC/CYBR Internship Panel @ 4:00 in Farmer 036
    • Thurs = DiverCS Trivia Night & Snacks @ 5:00 in Farmer 054
    Sep 8

  • Latest Car code posted

    Here’s the latest version of our Car class that we worked on in lecture today.

    Sep 8

  • Responsive reading posted!

    The next homework due (after “igpay“) is a thoughtful written response to a book section and article I have posted. All the details are here. It’s due to my manila folder at 5pm on Monday Sep 15th. Send questions!

    Sep 7

  • IMPORTANT clarification

    The purpose of the first programming assignment is for you to get used to using the Linux CLI (command-line environment) with vim and git and javac.

    Therefore DO NOT use NetBeans, IntelliJ, Eclipse, or any other IDE to complete this assignment! That would be a complete waste of time.

    My purpose isn’t to test that you can write basic Java code. I already know you can write basic Java code, otherwise you wouldn’t have the prerequisites necessary to get into this course. My purpose, instead, is to help you get up to speed being productive in a CLI.

    Sep 3

  • Lab Aide hours

    A number of talented lab aides are at your disposal this semester for help with your understanding in learning how to program! I’ve put their names and weekly date/time/locs in the office hours tab.

    Sep 1

  • Stupid string tricks

    Here’s a helpful list of common String methods you may find handy to use in your igpay project.

    Sep 1

  • Saturday’s homework

    If you didn’t turn in the homework due Saturday on time, you forfeited the one point it was worth, which of course isn’t much. However, you still have to do this homework! If you don’t, you won’t be able to do much of anything else in the class.

    Sep 1

  • Accommodations

    If you’ve received an accommodation letter from the ODR, and sent it along to me, thank you very much. Let me be specific about how I will handle all of these:

    1. I fully intend to comply with all your accommodations, but I may need to be periodically reminded on a case by case basis. If I do end up needing reminding at any time, please don’t interpret that as “Stephen doesn’t care about me or my accommodation.” Instead, interpret it as “Stephen has a lot of things he’s trying to carry in his mind right now, and it’s hard for him to memorize everybody’s accommodation needs at all times.” Please do just gently remind me, and I’m happy to accommodate.
    2. For accommodation needs like “the ability to record the lecture,” that power is officially granted to everybody. Heck, you can even stick the recording on Youtube if you want.
    3. For accommodation needs like “a distraction-free environment for quizzes,” please tell me at the beginning of our first quiz that you need this, and I will relocate you to another room for the quiz.
    4. For accommodation needs like “extra time on quizzes,” I’ll also have you in the distraction-free room, and give you 1.5x or double time or whatever your accommodation awards. Do be aware that this will mean missing some class time (since class on Fridays will begin immediately after the regular quiz time, so if you’re still working on it you’ll miss those minutes of lecture). Usually, that time will probably be spent going over the questions on the quiz, so you shouldn’t miss much, if any, new material.
    5. For accommodation needs like “access to a laptop to take notes,” please let me know this in class Wednesday so I can relocate you to the back/side of the classroom (where others won’t be distracted by your screen).
    6. For anything else you think I need to know about, just come ask me: email, after class, and office hours are all good.
    Aug 29

  • Program #1 posted!

    The first programming assignment of the semester has been posted, and is due at midnight on Thursday, September 11th. Good luck, and ask questions!

    Aug 27

  • Enrolling in CPSC 225

    CPSC 225 currently shows “full/overenrolled” on Banner, but that’s just because Dr. Finlayson wants to be notified when people join so he can set them up on the server.

    So: if you haven’t previously completed CPSC 225, and you’re not currently registered, please send an email to ifinlay _AT_ umw _DOT_ edu and ask to be added.

    Aug 26

  • Summer email

    Here’s the essence of that June 2nd email I sent to the class:

    As the summer months truly begin to set in, and you get into the rhythm of your break from classes, I’d like to interject a dose of reality. If you’ve had me in class, you’ve heard this spiel before. If not, then allow me to highlight some incontrovertible facts of the universe:

    Computer programming, like playing the piano or marathon running, is an activity that requires consistent practice in order to perform at a high level. There’s simply no way you can practice your instrument dutifully for three months, then take three months off, and not suffer a major degradation in your skills. Similarly, there’s no way to train like an Olympian for three months – running 15-20 miles a week – and then take three months off without losing nearly as much stamina as you’d gained.

    Your body simply doesn’t work that way. And it turns out, neither does your brain. (If you didn’t realize this, your brain is actually part of your body! And it obeys all the same physical rules.)

    Every variable you declare, function you call, and while-loop you write strengthens the logical component of your mind that you need for programming. It develops and reinforces those patterns you’ll need to rely on in the trenches, when your frontal lobe is allocated to contemplating larger concerns like architecture, design, and strategy.

    …When I begin the first lecture on August 25th at 11am, I’ll be assuming you have mastered the Java material in CPSC 220 and are ready to climb higher from there. I will not be spending the first month or two reviewing the 220 material and trying to wake you back up from your coma.

    Aug 25

  • Welcome!

    Greetings, and welcome to the fall 2025 edition of CPSC 240: Object-oriented Analysis & Design with Stephen!

    This site is gonna be hip-hoppin’ with all kinds of great stuff real soon, so stay tuned!

    Aug 12

CPSC 240

CPSC 240

stephendavies.org