SE1011
Homework

Week 1

  • Choose any file on your computer. Right-click on the file and select "Properties"
  • Write the name of the file and its size measured in bytes.
  • What is the size of the file measured in KB (Kibibytes/Kilobytes) or MB (Mebibytes/Megabytes)? What do these units mean?
  • Write whether this file stored on your hard-disk, in memory, or on the CPU. (A full sentence is not required.)
  • Press the keys <CTL>-<Alt>-<Delete> all at the same time. This will bring up a blue screen with a few options. Click on "Start Task Manager." This will bring up the task manager for your computer. On the Performance tab, you can see CPU usage and Memory usage. Write these down for your computer.
  • In the processes tab of the Task Manager is a list of all the programs running on your computer. Pick a process. Write its name, and the amount of memory it is using. Write whether this memory is larger or smaller than the file you selected earlier.
  • Can your hard-drive hold more, or your memory? Do you think there are any computers with the opposite?
  • On paper, write an algorithm to compute the volume of a sphere
  • On paper, write a Java program for 1. You do not need to write the imports, class, or public static void main(String[] ignored), just the stuff inside it.
  • In IntelliJ, make two errors at compile time. Write the errors that IntelliJ gives you and explain why you received them.
  • In intelliJ, make an error at runtime. Write the error message you receive. Explain why you received it.

Week 2

  • What does 1 + 2 * 3 evaluate to?
  • What does 2 + 7 % 3 evaluate to?
  • What does 4 % 1 + 5 evaluate to?
  • Can you implicitly cast a float to an int?
  • Can you implicitly cast an int to a long?
  • Can you implicitly cast a long to a float?
  • Can you explicitly cast a double to an int?
  • Can you explicitly cast an int to a double?
  • Exercise: 3.10, 3.11 (Note: Exercises, not Review Questions)
  • Exercise: 3.4, 3.16
  • Set up codingbat: Create a Mozilla Personal account using your MSOE email, and use it to log into the codingbat site. (Unless you already have a Codingbat account.) Don't follow the plain "create account" link. Under preferences, put your instructor's email address in the "Share To" field. (Dr. Taylor's 5 minute tutorial video)

Week 4

Week 6

  • Write a constructor method shown in a UML diagram as +Complex(real:double) that constructs a new "Complex" object with the imaginary part 0.
  • Complete the toString method shown in a UML diagram as +toString():String. Rewrite the method so that it displays the negative complex numbers with a minus sign instead of a plus sign between the parts. e.g. Instead of 1.0 + i-3.0, the method should print 1.0 - i3.0. (It should still represent other complex numbers in the original format.)
  • In the complex class, we used this.real = real; to avoid the problem of assigning the parameter back to itself (real = real.) Can you think of another way to solve the problem?
  • Write the plus method that we will implement on Friday. Rememer, this method should create a new object which represents the sum of this object and the object comp that is passed in.
  • For the following program, draw a memory diagram using the format we use in class at each letter comment (e.g. // a.) in the program snippet below. Assume the program uses a Dragster class with two members, velocityMetersPerSecond and positionMeters. You only need to draw the velocity instance variables, not the other instance variables in the class (And you can abbreviate the names!). Also draw the local variables in main and all of the reference arrows. Be sure to provide the name (if it has one) and type of each variable and object.
    public static void main(String[] ignored) {
      Dragster red = new Dragster();
      Dragster blue = null; 
      red.setVelocityMetersPerSecond(200);
      // a.
      blue = red;
      // b.
      blue.setVelocityMetersPerSecond(10);
      // c.
      red.step(1);
      blue.step(1);
      System.out.println("Red: " + red.getPositionMeters()+ " m");
      System.out.println("Blue: " + blue.getPositionMeters()+ " m");
    }
  • What will be printed by the two lines at the end of the program in part 1?
  • How would you fix the program so that it does what the user expects?

Weeks 7 and 8

Paper exercises

  • Objects don't have names. Instead, they have reference variables that point to them. Then the name of the reference variable is, for all practical purposes, the name of the object in our program. Normally, we would not have two reference variables pointing to the same object. That would be ambiguous, giving two names to the same thing. Identify a situation where having two reference to the same object might be useful.
  • If a method accesses a class variable, and also an instance variable, does the method have to be a class method? Does it have to be an instance method? Can it be both? Explain your answer.
  • Why is it safer to declare a named constant public than to do the same with an instance variable?
  • Exercises 8.3, 8.4 (See p. 284 for Car4 class, also note these are Exercises, not Review Problems)
  • Exercises 9.2, 9.3, 9.5. (Note: arrays of chars are not Strings)

Week 9