Back To: [Winthrop] [CBA] [CS&QM] Jim McKim
Welcome to Winthrop.edu

Homepage for Overview of Computer Science (CSCI 151)

Spring, 2012

[Announcements] [Assignments and labs] [Lecture notes] [Code examples]

Syllabus

Library classes, including graphics

Dead Rulers Talking. Kristen Huete was a student in this course in Spring, 2006. She wrote about her experiences and presented the resulting paper at the South Carolina Academy of Sciences annual meeting in Spring, 2007. And she won the award for best Undergraduate Math/Computer Science presentation at that meeting!

Announcements:


Assignments and labs:

This next lab will spread over two days. Be sure to e-mail the code to your partner at the end of the first day. That way you both have copies of what you've accomplished so far. Be sure to come to lab on both days even if you finish early as I may make some changes or additions. The goal for the labs on 2/13 and 2/15 is to learn about private variables and public mirror functions. We'll also write some convenience functions. Finally we'll add yet another routine to each of Conversation and Ruler. Seems the boss wants us to report some statistics.

  1. Same partners, switch roles.

  2. Start with the Conversation system as you had it last time.

  3. If you haven't already done so, take the printing of numRulers out of MainConversation. It was just there to illustrate public variables. Keep the variable numRulers in Conversation as we'll use it later, but make it private. In fact, make all variables in both Conversation and Ruler private.

  4. As always use javac *.java to compile. Always use java MainConversation to run.

  5. In Ruler, add in public mirror functions for the name, title, people, and country variables.

  6. Add in public convenience functions: Start with getIdentity(), which combines the title and name. Use it at least once in your code.

  7.  Add in two more public convenience functions: getIdentityWithCountry(), which combines title, name and country; and getIdentityWithPeople(), which combines title, name, and people. Use at least one of these with otherRuler in your sayHelloTo() routine.

  8. The boss says we need a way to print out statistics for each ruler. There will be more statistics to come, but the boss first wants to see how many conversations each ruler has started.

  9. Add a report() routine to Ruler and a reportRulers() routine to Conversation. The reportRulers routine will tell each Ruler to report its stats. For the moment just have the Rulers say who they are (use one of our three convenience functions to do this, you pick which one) when report() is called.

  10. Introduce a new variable, numConversations, into Ruler. This variable should represent the number of conversations that a Ruler has started. Note that numConversations is fundamentally different from name, title and the others. We need the Conversation class to tell us what our name and title will be. We don't need Conversation to tell us anything about numConversations. The Ruler class can handle this all by itself.

  11. As is often the case with variables you need to declare numConversations, initialize it, update it, and output it. Each of these will be done in a different place in the Ruler code. Figure out where and implement.

  12. You should be about here by the end of the first day. Maybe a little further, maybe not quite this far, but right around here. Wherever you are, e-mail your code to your partner!

  13.  At this point the output from report() should look something like: I'm President Lincoln from America and I've started 2 conversations. Unfortunately it might just as likely say: I'm Queen Cleopatra from Egypt and I've started 1 conversations.

  14. Talk to your partner about how we might avoid that last grammatical error. Then implement the plan.

  15. Once the above is working, add code so that as many as three different messages come out.
    1. For 0 conversations, something like: I'm the lonely Queen Cleopatra and I need someone to talk to.

    2. For 1 conversation, something like: I'm President Abraham Lincoln and I've started just one conversation.

    3. For 2 or more conversations, something like: I'm Saint Joan of Arc and I've started 72 conversations. Of course it won't really be 72; it'll be however many conversations Joan actually started.

  16. Change the code in Conversation so that at least one Ruler doesn't talk at all, at least one talks just once, and at least one talks two or more times. This will test that all your code in Ruler is actually working.
  17. Finally, the boss wants to see to whom everybody spoke most recently. Specifically, he wants to see additional output in cases (b) and (c) above. For (b) something like: I'm President Abraham Lincoln. I've started just one conversation and that was with Saint Joan of Arc. For (c) something like: I'm King Hammurabi. I've started 28 conversations, the last with President Abraham Lincoln.
  18. Talk to your partner and make a plan. Note that you will not need any new routines to implement this requirement. Nor will you need to make any change at all to Conversation.java. In fact, except for adding the reportRulers routine we've made no changes to Conversation.java this whole week. This is a sign that the structure we have in place is pretty well designed.
  19. You will need a new variable, so think about what type of variable it should be, where it will be declared, where it will be given a value, and where it will be output. That last one should be obvious, I hope.
  20. Implement the new functionality. Test it.
  21. E-mail Conversation and Ruler to your partner and to me.


The goal for the lab on 2/8 is to further understand how classes and routines communicate with each other. We'll also give our Rulers a people to, well, rule.

  1. Same partners, switch roles.

  2. Start with the Conversation system as you had it last time. Fix any problems with that version. For example a few teams didn't have an identifyRulers() routine in Conversation. Others didn't have good spacing in their output.

  3. When you give a ruler its name, title, and country, these strings should not contain any leading or trailing spaces. Or any extraneous words like "of". If you have anything like that, take it out. If you now need to fix the output of identify(), do so.

  4. Always compile using javac *.java. Always run using java MainConversation.

  5. Give each Ruler a people. Abe's people are Americans, Joan's are French, Cleo's are Egyptians, and so on. To do this, look at how we're currently giving each Ruler a name, title, and country, and do likewise. Print the people in identify() as in Hello world, I am Abraham Lincoln, President of the glorious Americans! You don't need to use that exact phrasing, but the message should include the name, title, and people of the Ruler. Don't lose the country variable, we'll use it later.

  6. Make the variables name, title, country, and people in Ruler public for today. You'll see why in a bit.

  7. Add a routine called sayHelloTo() to Ruler. As discussed in class this routine should take a String parameter for the moment. This is similar to what the Ruler() constructor does, but call this one otherName.

  8. Invoke this new routine from Conversation. The call will look something like lincoln.sayHelloTo("Joan"). In this case the program should print something like: Hey Joan this is Abraham Lincoln.

  9. Similarly if you call this with joan.sayHelloTo("George"), the program should print: Hey George this is Joan of Arc. Note that we could send any string as a parameter: joan.sayHelloTo("Once upon a time") will compile and run.

  10. Add a converse routine to the Conversation class. This is where all the calls to sayHelloTo should go. Make sure that each of your rulers is involved in the talking.

  11. As discussed in class, change the sayHelloTo() routine so that it accepts a Ruler object as a parameter instead of a String. My parameter is now called otherRuler. We still want the output to be the same. You'll have to think a little about how to get the other ruler's name to come out.

  12. Once you've got that, change the sayHelloTo() routine to include title and country of both rulers, as in Hello, Saint Joan of Arc from France. This is President Abraham Lincoln and I bring greetings from America.

  13. E-mail Conversation.java, and Ruler.java to me (and your partner)


The goal for the lab on 2/6 is to understand how different classes work together to make up a system at compile time and then to see how the objects spawned from these classes make up a system at runtime. We'll also get more practice with routines and see how to send information from one routine (and one class) to another.


One more time on GradingSystem. The goal this time (2/1) is to revamp the code to use routines. Once we have these we'll see that variables that are used in more than one routine need to be declared outside of any routine, traditionally at the top of the class. So we'll do that too. We'll learn about the visibility of routines and variables from outside the class we're working in. And we'll learn more about if statements.


OK, it's 1/30 and we're making good progress on GradingSystem.


Lab on 1/25. The eventual goal for the GradingSystem project is to simulate a large number of students who had all B's in the old system and see what likely happened to them when the system changed. We'd expect some percentage of student gpas to go up, an equal percentage to go down, and a somewhat smaller percentage to stay at 3.0. The question is, what exactly are these percentages? We'll take another step towards that goal today and learn some more about coding and design as we go.


The goal for the lab on 1/23 is to begin an experiment regarding the uses of plusses and minuses in the grading system at Winthrop and the effect on students' Life scholarships. We'll do this by looking at what might happen to a student who gets a B under the straight (no plusses or minuses) system in all of her first 10 courses at Winthrop. Note that because we're still very much beginning programmers our simulation will necessarily be overly simplified as that restriction shows. We'll assume that each course counts 3 credits, so we're effectively looking at the student's first 30 credits. This also means that computing the GPA is just a matter of averaging the course grades. The current system adds +'s and -'s to grades so that if a teacher uses the +/- system our B student might get any of 3 grades (B+, B, or B-) in any one course. We'll assume each of these is equally likely. In the current system a B+ counts 3.33, a B counts 3.0, and a B- counts 2.67. So in theory a student who used to get all B's in all 10 courses (and hence a 3.0 average) could now average anywhere from 2.67 to 3.33. Proponents argued that the additional accuracy is important and that over time students will be helped as much as they're hurt. Opponents were (still are) concerned that students who are hurt initially may lose their Life Scholarships (cutoff is 3.0 on 30 credits) and may have to drop out of school. These students won't be around to benefit from the "over time" argument. The goal of our (admittedly oversimplified) simulation is to try to get a handle on the proportion of students affected by the +/- system.


The goal for the lab on 1/18 is to understand how Random numbers can be generated in Java. As we will see random numbers are quite important for simulations.


The goal for the lab on 1/11 is to get you reading some simple Java code and making minor changes.


The goal of the first lab, 1/9, is to make sure everyone can log onto the system, send e-mail, and work with Java files. A secondary goal is for me to collect some info about you. So....


    The last few semesters the students in this course designed and built a small system that allowed world leaders to speak to each other. Unless inspiration strikes, we'll do something similar. I'll demo some student versions of this system in the next few days.

Lecture notes:

    I'll hand these out in class, but they'll always be here as well. Except for the first chapter I tend to use coding examples instead of powerpoint lectures. See below for some examples we'll likely cover.

    Chapter 1, Computer Systems

 

Java Listings. These are examples, mostly from the text. As we get into the appropriate chapters we'll use some of these in lab. You'll want to download others just for practice. Compile 'em, run 'em, and experiment on 'em.

 

    Chapter 1, Lincoln. java

    Chapter 2, Countdown. java

    Chapter 2, Facts. java

    Chapter 2, PianoKeys.java

    Chapter 2, Geometry.java

    Chapter 2, Echo.java

    Chapter 2, GasMileage.java

    Chapter 2, Roses.java

    Chapter 2, Snowman.java and Snowman.html (It may be easier to right click on this second one to save it properly)

 

    Chapter 3, RandomNumbers.java

    Chapter 3, Authority.java

    Chapter 3, NestedPanels.java

    Chapter 3, LabelDemo.java. For this one, you also need devil.gif. Again, right-clicking will allow you to save almost anything properly.

 

    Chapter 4, PushCounter.java and PushCounterPanel.java. These two make up a single system. Compiling PushCounter.java will force automatic compilation of PushCounterPanel.java. It'd be illuminating for you to put both these into an empty directory, compile the first one, and then notice how many files are created.

    Chapter 4, Splat.java, SplatPanel.java, and Circle.java. These three make up a single system. This is a really nice example of constructing multiple Circle objects from one Circle class.

    Chapter 5 (sort of), We need to distinguish between left and right button mouse events to implement Minesweeper, or just about any highly interactive graphics system. TwoButtonListener is a reusable class that will make this easy, and PushCounter and PushCounterPanel have been updated so that they now show how to use it. As usual, right click and save all these.

    Chapter 5, Splat.java, SplatPanel.java, and Circle.java. These are the updated versions reflecting work done on SplatPanel in class through 10/27. Illustrates if-else and switch statements.

 

    Chapter 5 with a touch of Chapter 7, Splat.java, SplatPanel.java, Circle.java, and AudioPlayer.java. These are the updated versions reflecting work done on SplatPanel in class through 11/1. Illustrates Arrays, For loops, and the use of sound.