Skip to main content.

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: Before the next class (Monday)

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 14 API. Also bookmark the course schedule page, if you haven't already.

Part 1: Debugging a Program (25 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. Use should 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.

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. Use print statements to check/verify your work at intermediate steps.

The code to get user input is commented on in the provided file. Uncomment getting user input last and put it in the appropriate place in your code.

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 we're 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.

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.

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?

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 (55 pts)

You will be evaluated based on