Setup #

Things like String or String.equals() are red #

This is a JDK issue - go to File > Project Structure > Project > Project SDK to troubleshoot. If your Java version is 17.0, then you should have a 17.0 SDK and a Level 17 language level.

IntelliJ is telling me “package org.junit does not exist”, or “cannot resolve symbol junit”, and things like @Test are red #

You probably forgot to add your libraries. You have to add your libraries every time you start a new project!

The console button isn’t showing up #

That’s probably because you didn’t compile successfully. Usually, it’s because you did not add your libraries.

My Java files have a red circle, with a J inside the circle, next to the file icon #

Make sure that you’ve opened the lab04 directory in IntelliJ. If you have, right-click the folder containing that Java file, then Mark as -> Sources Root.

Measurement.java #

How do I type " in a Java string? #

To put a double-quote in a Java string, use a backslash:

String dQuote = "\""

Do we need to handle negative numbers? #

No. The Measurement class doesn’t need to do sensible things when passed negative numbers as arguments.

Do we need to worry about integer overflow? #

No. (Although you could imagine someone’s Measurement class handling this correctly.)

Do we need to worry about null arguments? #

Not this time. You may assume that minus and plus are only passed non-null arguments. (They are the only two methods that take in objects.)

assertEquals fails even though my Measurements are the same #

Remember that assertEquals uses the equals method. If your Measurement class doesn’t override equals, it’s using the default Object::equals, which checks that the objects are the same instance. We haven’t learned about what exactly this is yet, but it’s a problem!

You could either override equals (we haven’t learned how to do this yet), or assertEquals on the toStrings of the Measurements. We recommend the latter, since you will have written that anyway.

I passed my tests locally, but I’m failing on Gradescope #

There’s a couple possible reasons for this:

  • minus, plus, and multiple should not alter the current Measurement, and instead create a new object.
  • You are likely missing edge case testing. For example, what if the number of inches passes 0 or 12?