Signing Naturally Homework Answers Unit 4

0 views
Skip to first unread message
Message has been deleted

Evaristo Nicholls

unread,
Jul 16, 2024, 7:00:47 AM7/16/24
to ricorsandflan

The purpose of this homework is to help you set up your developmentenvironment, get reacquainted with Java, and start getting familiar with tools you willuse for the rest of the course. Although the homework description islong, we expect the step-by-step instructions will make doing thehomework less overwhelming than reading it may be.

If you would like to get more practice with Java,then we recommend walking through Oracle's Java tutorials described under Problem 7. Try to complete Homework 3first so you can use the tools we describe here when doing the examples inOracle's tutorial.

signing naturally homework answers unit 4


DOWNLOAD ---> https://urllio.com/2yMMym



You are free to get help from anyone on any portion of this homework. That is,the standardcollaboration restrictions do not apply to this homework. You willneed to know this material for the remainder of the quarter, however,so make sure you understand thoroughly the tools and concepts in this homework.

You first need to decide what computer(s) and developmentenvironment(s) you will use for the course, or at least for thishomework. We strongly recommend using the Eclipse IDE inCSE331, but we will not check whether or not you do so. We alsoprovide instructions for working from the Linux command line.

You can use the CSE department's instructional labs by going to thebasement of the Allen Center; or access the facilities remotely; orinstall a virtual machine on your own computer that is just like thedepartment's Linux machines; or install Java, Eclipse, and othernecessary tools on your own computer. There are trade-offs amongthese choices: theWorking At Home documentexplains the trade-offs and provides the instructions for each option. Please read this document and setup the development environment that you want, again Eclipse IDE is highly recommended.

Once you have chosen and prepared a development environment, you should set it upfor CSE331 use.See Starting Eclipseand follow any instructions that are applicable. (Note: if youswitch development environments later in the quarter, revisit these instructions.)

Throughout the course, you will receive starter code and submityour assignments through CSE's GitLab server (git). git is a version controlsystem that lets software engineers backup, manage, andcollaborate on large software projects.GitLab is a CSE department server that provides git repositories for students in CSE331and many other classes and projects (You will learn more about gitin section.)

SeeEditing and CompilingSource Files to help learn how to perform the following basictasks: adding new files to your directory structure, compiling Javacode, and reading the Java compiler's output (which may indicateerrors).

Try to compile the provided code in HolaWorld.java.You should see compilation errors for this file. (Andpossibly in hw3/test/RandomHelloTest.java too; if so,ignore these for now since we will fix them in the next part.) Inparticular, the lines:

are problematic. (If you're using the the Ant builder,you may see the second error only after you've fixed the first one.)If you are using Eclipse,these errors will be marked with red squiggly lines in HolaWorld.java,and HolaWorld.java itself will be marked with a red crossmarkin the Package Explorer.

Don't write your own random number generator to decide whichgreeting to select. Instead, take advantage ofJava's Random class. (This is a good example of the adage "Know and Usethe Libraries" as described in Chapter 7 of Joshua Bloch'sEffective Java. Learning the libraries will take some time,but it's worth it!)

This line creates a random number generator (not a randomnumber, which comes later, but a Java object thatcan generate random numbers). In Eclipse, your code may bemarked as an error by a red underline. This is because theRandom class is defined in a package that has not yet beenimported (java.lang and hw3 are the only packagesthat are implicitly imported). Java libraries are organized aspackages and you can only access Java classes in packages that areimported. To importjava.util.Random, add the following line under theline package hw3; at the top of your file (afterthe package hw3; declaration):

Read the documentation for Random's nextInt(int n) method by going to the Java API and selecting Randomfrom the list of classes in the left-hand frame. Many classes also let youpull up documentation directly in Eclipse. Just hover over the class ormethod name and press SHIFT+F2.

The main method in the skeleton code above printsthe value returned by getGreeting. So ifyou insert code in getGreeting to select a greetingrandomly, when the class is run it willwill print that greeting.

Testing is essential for writing quality software, so it's important for testing to bea convenient part of software development.JUnit isa framework for creating unit tests in Java. A unit test is atest for checking that a given method in a class conforms to itsspecification for an input. This problem provides a quickoverview and simple example of how JUnit works.(Unit testing will be more significant in later assignments.)

A window or panelwith a menacing red bar will appear, indicating that someof the tests in FibonacciTest did not complete successfully(see screenshot at right). Thetop pane displays the list of tests that failed, while the bottom paneshows the Failure Trace for the highlighted test. The first line in theFailure Trace should display an error message that explains why thetest failed. (The author of the test code createsthis error message.)

Use the information in the Failure Trace box to help you continue debuggingFibonacci. Keep a record of what you did to debugFibonacci as you will have to answer questions about yourdebugging experience in the next problem. After you have fixed all theproblems in Fibonacci, you should see a bright green barinstead of a red one when you run FibonacciTest.

Now look atthe JUnit tests that we wrote for HolaWorld andRandomHello. They are calledHolaWorldTest and RandomHelloTest,respectively. Ensure that your modified code passes these testsbefore you turn in your homework.

Until now, we have only been introducing tools. This problemdelves into a real programming exercise.This problem will likely be somewhat challengingfor most of you. Don't be discouraged. We're here to help, and weexpect that time spent now will pay off significantly during the restof the course.

Next, create a class BallContainer. As before,skeleton code is provided (see BallContainer.java). ABallContainer is a container for Balls. BallContainer should support thefollowing methods: your task is to fill in the code toimplement these methods correctly:

InBallContainer, we use a java.util.Set to keep track ofthe balls. This is a great example of using a predefined Java data-structure tosave yourself significant work.Before implementing each method,read the documentation for Set. Some of your methods will be as simple ascalling the appropriate predefined methods for Set.Tohelp you out, we have included a JUnit test called BallContainerTest.java.

In this problem, you will do a little more designing and thinking and alittle less coding. You will implement the Box class. A Box is also a container forBalls. The key difference between a Box and aBallContainer is that a Box has only finite volume. Once abox is full, we cannot put in more Balls. The size (volume) of a Boxis defined when the constructor is called:

(Optional Note: You may wonderwhy we did not make Box extend BallContainervia inheritance. That is, why did we not make Box asubclass of BallContainer? We will discuss this much moredeeply later in the course, but the key idea is that Box isnot what we call a true subtype of BallContainer because it isin fact more limited than BallContainer (a Box canonly hold a limited amount); hence, a user who usesa BallContainer in his code cannot simply substitutethat BallContainer with a Box and assume the samebehavior. (The code may cause the Box to fill up, buthe did not have this concern when using a BallContainer).For this reason, it is unwise to makeBox extend BallContainer.)

When you have committed and pushed all of your changes and are done with the assignment,you shouldcreate a git tagin your repository named hw3-final and push that tag to your repository.Once you have committed and pushed that tag, your assignment has been submitted.The staff will grade the files in your repository that are labeled with that tag.Be sure you remember to add/commit/push your files and the tag!

For each homework, we strongly recommend that you validate what you have turned in by running the provided validation checks on attu. Read about validate now and be sure to get it working for the sake of this and future homeworks. While validate does not ensure your homework is perfect, it performs important sanity checks, like seeing if your code compiles and if expected files are present in the repository.It is in your interest to do these checks. They often can catch minorerrors that can cause programs to fail spectacularly when they are evaluated,which can cause a program that is basically correct to receive a score farlower than it should have gotten.

Validate your homework and fix problems as many times as necessary untilthere are no errors. If you push additional changes to your repositoryto fix problems you will need to reapply the hw3-final tagso it references the proper version of the code in your repository. Seethe version controldocumentation for details. You have now successfully turned in yourCSE331 homework.

If you have not had much experience with Java, we recommend that you dothese extra Optional Problems(source code for these problems can be found in the hw3.optionalpackage that came with your hw3 checkout).If you do not know Java, CSE 331 will require you to learn it quitequickly. The optional problems, although not required, will help youbecome more comfortable with Java.

In this part, you will learn about Eclipse's built-in debugger. Adebugger can help you debug your program by allowing you to"watch" your program as it executes, one line at a time, andinspect the state of variables along the way. Using a debugger can bemuch more powerful and convenient than littering your program withstatements that print output.

b1e95dc632
Reply all
Reply to author
Forward
0 new messages