Assign 1: Writing Simple Java Programs
Objective: To practice writing and debugging simple Java programs, e.g., using the String class and its API.
Due: Friday before class
Set Up
Cloning the Repository
In your terminal, go to the directory where you are keeping your repositories for CSCI209. Clone the repository for this assignment. Add your name to the README file.
Bookmark the Java API
Bookmark the Java 18 API. Also bookmark the course schedule page, if you haven't already.
Part 1: Debugging a Program (30 pts)
Objective: The goal of this part of the assignment is to get you familiar with the required Java syntax, the compiler's error messages, and how to fix the errors so that the program compiles. Debugging is one of the most important skills you learn from programming, so it's good to practice, especially on a small program.
The given Assign1.java
program contains at least 4
errors. Some are compiler errors that the compiler will catch. Others
are logic errors that the compiler won't catch. The errors are
common--you'll likely make these mistakes yourself at some point in
time. You'll find those bugs faster in the future since you've
practiced debugging them.
Comment out the original code and note the cause of the error. Then, correct the code. You prove to me that you know how to fix it by what you put in the code. The comments prove that you understand why the error occurred. Strive for the fewest changes (both in number and size of changes) that fix the problem.
Save your output (using the >
output redirection)
in a file called debugged.out
. Add this file to your
repository.
FAQ -- not to be read until after you've attempted the assignment at least partially.
Part 2: Using Strings and Getting User Input (20 pts)
Your Java program (FileExtensionFinder
) should take in
a file name (a String) as user input and display the file extension,
lowercased. For example, when you run your program using java
FileExtensionFinder, it should look something like:
Enter your filename: myfile.txt Your file is a(n) txt file.
There are a variety of ways to solve this problem. Think about
your algorithm and what tools (Java classes/methods--check out the
String
API)
are available to you. You
should not need to use any control structures for
this problem (we have not covered those yet) because we are not
going to worry about error handling at this point. Use print
statements to check/verify your work at intermediate steps. Remove
them for your final submission.
Wait to get user input last in your development process. To start, hardcode the String variable that represents the filename and write your code to find the extension. Then, hardcode a different String to test that your code still works with that new value. Then and only then, add user input.
More example output:
Enter your filename: intro.pptx.pdf Your file is a(n) pdf file.
Enter your filename: Paper.DOCX Your file is a(n) docx file.
At this point in the term, you don't need to worry about error handling, such as if there is no filename given or if there is no "." in the filename.
Since the program is getting user input, we can't just write to an output file like we did for the last assignment. I will execute your code using my test cases.
Cleaning up your code
Great! You got it working! Before you submit, review your code. Is your code written in an (relatively) understandable way? Any extra code that you no longer need? Do you have appropriate comments? Is the indentation appropriate?
Submission
Submit your assignment by pushing the code, output file, and
README.md to GitHub. Note that the .class
files should
not be included in the repository. I set up
the .gitignore
file to prevent you from adding
the .class
file.
Checking your work
It is recommended that you [re?]clone your project in a new directory, and then make sure that you can compile and run your programs. (This is, afterall, exactly the process that I'll use.)
Grading (60 pts)
You will be evaluated based on
- (30 pts) Part 1: Debugging your program
- Catch, fix, comment all errors; program gives expected output
debugged.out
has the expected output
- (20 pts) Part 2: Correctness of your program
- identifies and displays the extension of the filename
- gets filename as user input
- (10 pts) Parts 1-2: Proper style, indentation, documentation of Java programs