Programming Assignment 2

Due Date: Tuesday, January 24, 10:00PM Pacific Time

Learning Goals


Different assignments in this course have different collaboration policies. On this assignment, you can collaborate with anyone in the course, including sharing code. In your submission, give credit to all students and course staff who helped you with this assignment by noting their name and how you used their ideas or work. Note that using someone’s work without giving credit to them is a violation of academic integrity.

Starter Code

You can download the starter code for this assignment here:

Start Early!

Start working on the assigment early. Even an hour a day can be very helpful to make sure you finish before the deadline.

Submission Checklist

You will submit two files to the PA2 assignment:

Part 1 has a method and 3 tests. The code has several compile time errors. Fix the errors so that the code satisfies the following:

  1. method checkNumber()
    • takes a double called myNumber as its parameters
    • checks if myNumber is positive, negative, or zero, and returns the information as String type.
    • If positive: the return message should be "The number [myNumber] is positive."
    • If neggative: the return message should be "The number [myNumber] is negative."
    • If zero: the return message should be "The number is zero."

    For example, checkNumber(3.5) returns "The number 3.5 is positive."

  2. field answer1: tests the result of checkNumber() with argument 1
  3. field answer2: tests the result of checkNumber() with argument 0
  4. field answer3: tests the result of checkNumber() with argument -10.5

Part 2

You will write all your code and comments in This file will contain all three classes that you write, including Tweet, User, and ExampleTweets.

In this programming assignment, you will be using tweets as data and representing them using objects. The choices we make will be similar to those in many social media posting platforms. You will be making two classes for implementation and one example class for testing your implementation. Altogether, you will create 3 classes in one file, and around a dozen objects.


The class User represents users, the authors of Tweets.

Note: To get information about the user (when creating user objects) you will have to go to their profile and see how many followers they have and then instantiate a new object with that value.

An example user


The class Tweet represents a single tweet.

An example Tweet


The ExampleTweets class is for testing your own implementation.

In order to test your classes and methods, find four real tweets from with the following properties:

You may find these accounts useful and relevant for finding fun Tweets:

(If you can’t go to Twitter for some reason, let us know via Piazza or email and we’ll help you out – you may be able to complete the assignment with another social media example).

In your test class ExampleTweets, you will construct User objects and Tweet objects corresponding to these four tweets you found. In your test file, you will call each method you write at least twice using the objects you constructed to build these examples. Since there are 5 methods, you should have at least 10 method calls total to test your work, and every method should be called at least twice. For each tweet you found, write a comment before the line where you construct it with:

For checking off your work, you should have:

A submission checklist can be found here


There are multiple oppurtunities to get feedback for PA2. By submitting before the deadline, you will receive feedback after it is graded shortly after the dealine. You may also submit to the Late/Resubmit for PA2 one time after the deadline to earn additional feedback.

For more information about the grading policy, visit the course syllabus.