teaching machines

CS 145 Lab 4

Last lab we looked at methods. Grasping this idea of pushing out sequences of instructions to these standalone “subprograms” is of utmost importance to your proper understanding of computer science and programming. It’s so important that this week’s lab does not introduce any new topics.

Please take the time to ask questions and resolve any lingering confusion you have about how code works.

Reminder

Be sure to get your checkpoints from lab 3 checked off in the first 20 minutes of this lab. They should already be working and ready for approval.

Problems

Complete four of the five problems below.

  1. Write a method generateWeather that generates a random weather report, listing the day’s high and low temperatures (ensure the low is lower than the high) and whether or not it is raining.
  2. Write a method composeUsername that takes two String arguments, one for the first name, one for the last name. It returns a username of the form “<lastname><first initial>”.
  3. Write a method that getTriangleArea that takes arguments for a triangle’s base and height and returns its area.
  4. Write a main method that creates a Robot, prompts for and retrieves from the user an xy-coordinate, and then moves the mouse to the entered coordinate. (Eclipse will complain about the line where you create the Robot. Click on the error in the margin and add the throws clause.)
  5. Write a method getStatusBar that takes an integral argument that you may assume is between 0 and 100. Return a sequence comprised of this number of asterisks (*).

Checkpoint #1. Either properly indent your code or hit Control-Shift-F in Eclipse to format it automatically. Show your TA or instructor your solutions.

TODO

  • Homework 1 is due before Tuesday next week.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *