Assignment 4 — Java, in a file

The stripe and the flag drawn in text, with Check.is where where: was. First, a three-question setup survey: a GitHub username, where you run Java, and which Java that is.

Due Sep 29, 2026

Two parts, both due Tuesday, September 29. Part A is a Brightspace survey and takes about ten minutes. Part B is a file.

AI: the course AI policy applies in full. No AI-generated code, and no asking a chatbot to solve these problems before you have.

Part A — the setup survey

On Brightspace, under Surveys: Java setup: Java version, IDE, GitHub. Three questions. None of them has a right answer, and none carries points.

  1. Your GitHub username. If you do not have an account, make one at https://github.com (Sign up, top right). Choose a username made from your first and last name, lowercase, joined with a hyphen: first-last. If that one is taken, add something short after it. Then put your full name on the profile: Settings → Public profile → Name.
  2. Where you run Java — the lab’s IntelliJ IDEA, IDEA on your own computer, NetBeans, VS Code, or OneCompiler.
  3. Which Java that is. The starter below has a program that answers this, src/Version.java; on OneCompiler it is https://onecompiler.com/java/4544z24zr. Run it in the setup you picked in question 2 and paste the line it prints. If it does not run, paste the error instead; that is an answer too.

Do this part first. Question 3 is what tells me which Java you have when something goes wrong later, and it is the ten minutes of this assignment that help most.

Starting code

The starter is a repository: https://github.com/cu-cs-labs/cmsc-120-stripe. Three files under src/:

  • Stripe.java — the program. Yours.
  • Check.java — Check.is, which is Pyret’s is for Java. Given; do not edit it, though you are welcome to read it.
  • Version.java — for the survey.

In IntelliJ IDEA: Welcome screen, Get from VCS, paste the URL, Clone. Open src/Stripe.java and press the green Run arrow beside main. If you started this in class on Wednesday, keep going in that project.

On OneCompiler: open https://onecompiler.com/java/4544z33u6. Stripe.java and Check.java are already there; press Run. Version.java, for the survey, is its own link in Part A.

Done when it prints Looks shipshape, all 2 checks passed.

Git is only how the files reach you this week. There is nothing to commit and no account is needed.

Part B — the file

Check.is is is. Where Pyret had

stripe-width(10) is 60

main has

Check.is(stripeWidth(10), 60);

and Check.done() stays the last line of main. A check that fails prints what it got and what it expected.

Every function gets a // line above it saying what it gives back, and at least two Check.is lines in main, worked out by hand before the body is written.

  1. flagWidth — a flag is two stripes wide. Monday’s, and the warm-up.

    int flagWidth(int u)

    flagWidth(10) is 120, flagWidth(5) is 60. It may call stripeWidth, and is shorter if it does.

  2. stripeRow — a stripe drawn as a row of characters as wide as the stripe.

    String stripeRow(int u)

    Text can do this itself: "#".repeat(6) is ######. repeat is something the text knows how to do; the dot is how you ask it, the same shape as Check.is. stripeRow(1) is ######. Text knows how long it is, too: stripeRow(2).length() is 12.

  3. flagRow — one row of the flag: two stripes side by side, in two characters. + joins text.

    String flagRow(int u)

    flagRow(1) is ######....... One of your checks compares flagRow(10).length() with flagWidth(10).

  4. flag — a stripe is u tall, so the flag is u rows. "\n" is the character that ends a line, and a row with one on the end can be repeated like any other text.

    String flag(int u)

    flag(1) is "######......\n". Work out flag(3).length() by hand and check it. Then print flag(4) after Check.done() and look at it.

Done when Check.done() prints Looks shipshape with every function checked, and flag(4) prints as a flag.

Hand in

Upload Stripe.java on Brightspace, under Assignments → A4. The file itself, not a paste, and not Check.java — your file is run against the course’s own copy of it, so leave that one as it is.

Where it is: in IDEA, the folder you cloned into, IdeaProjects inside your user folder, then cmsc-120-stripe/src/Stripe.java. In the lab that is the machine you sat at, not any other. On OneCompiler, copy the file’s text into a file called Stripe.java on your own computer, and upload that.

If you run out of time

Do the survey first: it is ten minutes, and it is how I can help you with whatever went wrong. Then flagWidth, stripeRow and flagRow with their checks, which Wednesday’s class already started. flag can be the last evening’s work.

Grading

Full credit for the survey done and a file that runs and does 1 through 4.

Most of the weight is on three things:

  • The checks. Every function has its // line and at least two Check.is lines, with the answers worked out rather than read off the body. flag(3).length() is the one to do on paper.
  • The picture. flag(4) prints as a flag: every row the same width, nothing extra on the end.
  • A file that runs. A Check.is line that fails costs less than a function with no check at all.

Presentation

Two of you will be asked on Wednesday, September 30 to put your file on the projector and walk the class through it. You will not be told in advance.

One of the two will be asked what Check.is told them that printing true on Monday did not.

What else to do (optional part)

Ungraded. No points, and skipping them costs nothing. The drawing ones are worth doing in order.

More to draw

  1. row — flagRow with the two characters as parameters:

    String row(int u, String a, String b)

    row(1, "#", ".") is ######....... Then rewrite flagRow as one line that calls row. Your checks for flagRow say whether you changed what it does; the answer should be that you did not.

  2. board — the flag, and under it the flag with its stripes swapped: a checkerboard of four.

    String board(int u)

    board(1) is "######......\n......######\n". One check compares board(2).length() with flag(2).length().

  3. tricolor — three stripes side by side, in three characters. Its width is stripes(u, 3), where

    int stripes(int u, int n)

    is the width of n stripes at unit u. Write both, and check one against the other: Check.is(tricolor(10).length(), stripes(10, 3)).

  4. flagSize — how many characters flag(u) has, worked out with arithmetic rather than by drawing it.

    int flagSize(int u)

    Work it out on paper first. Then check it against flag(u).length() for three values of u. Two of your own functions agreeing is the best kind of check there is.

  5. frame — the flag in a frame: a row of +---+ above and below it, and a | at each end of every row.

    String frame(int u)

    The border is the same text twice. Give it a name inside the method, String edge = ...; on a line of its own, and use it twice. frame(1) is 45 characters long; say why before you check it.

Three things to try

  1. Change both ints in stripeWidth to double. Java stops in three places before running anything. Read all three; two of them are repeat, and what it says about a double is worth a sentence in your own words. Then put the ints back.

  2. Write Check.is(stripeWidth(10), "60") in main — a number on the left, text on the right. What happens, and when: before the program runs, or while it runs? Then delete the line.

  3. Open Check.java and read it; the comments are written for you. Then delete the is that takes two Strings and run your file. What does Java say, and when: before running anything, or while running? Put it back.