Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1: Make a bag that can hold anything This first part checks that you know how to use generics, write JavaDocs, and use

imageimage

Part 1: Make a bag that can hold anything This first part checks that you know how to use generics, write JavaDocs, and use the basic command line tools you'll use throughout the semester. You need to write a class called One ItemBag (in a file called OneItemBag. java that you create). This class represents a bag that can hold any single type of object (decided at bag-creation time), and only one item of that type at a time. You may have a zero-parameter constructor if you want one, but you must have the following three features: 1. a method that puts an item in the bag (addItem ()) which returns whether or not it was successfully added 2. a method that removes an item from the bag and returns it (remove Item()), return null if there is no item 3. a method to check if an item is in the bag (hasItem()) which returns true or false Make sure to comment your code as you go in proper JavaDoc style. To check that you've got the right idea, we've provided a class called BagusageDemo.java which shows creating two different bags that store different things (some kiwis and some acorns). You should not alter this class to "make it work", but rather alter your bag to allow the provided code to work. You can use the command "java BagUsage Demo" to run the testing code defined in main (). You could also edit this main () to perform additional testing (we won't be using BagUsageDemo for testing, it's just a demo for you). Note that JUnit test cases will not be provided for OneItemBag, but feel free to create JUnit tests for yourself. A part of your grade will be based on automatic grading using test cases made from the specifications provided. TL;DR You're making a bag (OneItemBag) and using JavaDoc comments. There's test code in BagUsageDemo. Checking That You've Got Style Every professional developer needs to adhere to a coding style (indentation, variable naming, etc.). This is non-optional in 99.99999% of professional settings (aka. "jobs"). Normally, in school, a grader checks your style manually, but this is very inefficient since you only get feedback after your project is completed (not while you're writing), and it's very hard for someone to manually check these things. We're going to help move you along the path to "coding with style" this semester. We have provided you with a command line tool that checks your style for you: checkstyle (https://checkstyle.org). This tool has plugins for Eclipse, NetBeans, jGRASP, and many others (see their website), but there is also a command line interface (CLI) which has been provided with this project (checkstyle.jar). This automatic checker is similar to ones used at large companies (like Google, Oracle, and Facebook). If you're curious, we're using a subset of Google's style requirements for this class. The provided as310code.xml checks for common coding convention mistakes (such as indentation and naming issues). You can use the following to check your style: java -jar checkstyle.jar -c [style.xml file] [userDirectory]/*.java For example, for a user directory 001-krusselc-po checking for JavaDoc mistakes I would use: java -jar checkstyle.jar - cs310code.xml 001-krusselc-p0/*.java Note: if you have a lot of messages from checkstyle, you can add the following to the end of the command to output it to a file called out.txt: > out.txt If checkstyle finds nothing wrong you'll see "Starting audit... Audit done." and nothing else. Checking Your JavaDoc Comments You should verify that your JavaDoc comments adhere to the proper format (especially if you're new to writing JavaDocs). We've provided a second checkstyle file (cs310 comments.xml) that looks for JavaDoc issues and in-line comment indentation issues. You can run it the same way as cs310code.xml, for example: java -jar checkstyle.jar -c cs310 comments.xml 001-krusselc-po/*.java TL;DR There are some tools you need to try out. They are provided. They help you code more professionally. 3 Part 2: Putt Putt Banana Coconut! This second part of the project checks that you know how to use command line arguments and write basic Java code (including exception handling), and it gives you more practice writing JavaDocs and using checkstyle. You'll also be able to see and use JUnit tests (such as the ones we use when grading). Specification: Write a program (Banana Coconut, that lives in Banana Coconut. java). This program should accept multiple numbers as command line arguments and print those numbers out again space separated, but for multiples of 3 print "banana" instead of the number, for multiples of 7 print "coconut" instead of the number, and for the multiples of both 3 and 7 print "banana-coconut" instead of the number. For numbers smaller than 1, print "puttputt". Don't forget to document as you go. Example program run (coloring added for readability): > java Banana Coconut 1 2 3 4 5 1 2 banana 45 > java Banana Coconut 0 1 3 5 7 17 21 puttputt 1 banana 5 coconut 17 banana-coconut > java Banana Coconut 3 7 21 7 3 banana coconut banana-coconut coconut banana Checking for Invalid Input Your program should print the following (exactly) if the command line argument is missing or if any of the command line arguments are not a valid integer. This message should be sent to System.err not System.out. Example commands which generate this error include: > java Banana Coconut > java BananaCoconut apple > java Banana Coconut 2 apple Error message: One or more numbers required as a command line argument. Example Usage: java BananaCoconut [number] [number] [...] Exactly Matching Output Eight unit tests have been provided to automatically check that you are exactly matching the output required (BananaCoconutTest. java) since it is hard to eyeball differences in text. To run these tests, navigate to the directory above your user directory (from your user directory type ed.. to go up one directory) and do the following... Compile and run the tests with the following in Windows: javac -cp.junit-4.11. jar; [userDirectory] Banana CoconutTest.java java -cp.junit-4.11. jar; [userDirectory] Banana Coconut Test Or for Linux/Mac, replace all the semicolons wit colons in the classpath: javac -cp.junit-4.11.jar: [userDirectory] BananaCoconutTest.java java -cp.: junit-4.11.jar: [userDirectory] Banana Coconut Test Replace [userDirectory] with your actual user directory name. For example, on my computer (running Windows) from my "p0 directory" (not from my user directory which would be "001-krusselc-p0"), I would type: javac -cp.junit-4.11. jar;001-krusselc-p0 BananaCoconutTest.java java -cp. junit-4.11. jar; 001-krusselc-po BananaCoconut Test Check Your Style and JavaDocs Run both checkstyle files again on this new program to verify you got those basics down. TL;DR You need to make a program (Banana Coconut) with exact output. JUnit tests are provided.

Step by Step Solution

3.49 Rating (146 Votes )

There are 3 Steps involved in it

Step: 1

Step 1 Q1 A bag that can hold any single type of object and only one item of that type at a time One... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts in Enterprise Resource Planning

Authors: Ellen Monk, Bret Wagner

4th edition

1111820392, 978-1133707462, 1133707467, 978-1111820398

More Books

Students also viewed these Programming questions

Question

Did the parties reach an agreement that both were satisfied with?

Answered: 1 week ago