1.Read the textbook project description thoroughly before you do anything else. Make sure you compile and test your program repeatedly as you are implementing each step described below.
2.Type in the OSProcess program in Figure 3.13 on page 118 of your textbook. Compile it and run it. Make sure you understand how it works, since you will need to use similar code for you shell.
3.Type the SimpleShell program in Figure 3.37, compile it and run it.
4.Begin by adding code that splits the String into a String array. Look up the String class in the Java API and read about the split() method. You will be splitting the user input based on a single ‘space’ character and saving the result in a String array.
5.The ProcessorBuilder constructor that is described page 150 accepts a List of String objects. You will need to find a class that implements the List interface and then transform your String array into a List of Strings. You can use ArrayList or List class in java.util package. You will need to read the java API to learn how to add String objects to your ArrayList or List. One you figure out your need to write code that iterates through your String array and adds each String to the ArrayList or List.
6.One you correctly have all of your String in your List, all you need to do is to create your ProcessBuilder object.
7.Next, you will need to create a Scanner or BufferedReader to read the output string of the process builder object. This is almost identical to how it is handled in the OSProcess program in page 118. You OSProcess will print out the result of the command. Try it with the cat command, the ls command, and the ps
8.Congratulations! Your project tis now working! Back up your program to a separate directory in case you mess it up by adding the stuff below.
9.Add code to your project so that if the command entered is “exit” or “quit” the shell outputs “Goodbye.” And exits the program. You can use System.exit(0) to exit your running program.
10.Next,get your shell to successfully change directories using the cd command. To do this, you will need to use the directory (File directory) method of the ProcessBuilder project, and you will also need to have a File object that keeps track of the current directory. For example, if you are in your home directory and it contains a directory called Project1, and you type:
to get into your Project1 directory. If you just type cd
you will get an exception. If you get this far,
will not work as expected.
11.Get your program working with relative paths. For instance, make it so typing:
cd Project 1
actually takes you to the Project1 directory instead of throwing an exception. Also
should work as expected in this case.
12.Finally, add some error/exception handling and do it gracefully. For instance, if a user types in cd fakeDirectory
and it does not exist, you should tell the user instead of crashing with an exception. If I can crash your program by trying to use your shell by doing normal things, you won’t get these final points.
|Input test cases||Results|
|Compile and runs the program||The shell program can compile and run successfully|
|ProcessBuilder object||ProcessBuilder object is correctly created, ps, ls, and cat command works|
|Exit and quit||Exit and quit works|
|Change directory to /home/user||cd followed by pwd|
You are able to change directory to /home/user directory and display it. (absolute path is working)
|Handle absolute path||cd /home|
You are able to change directory to /home
|Relative path||thencd user|
You are able to change directory to /home/user (relative path is working)
|cd again and type|
cd /user/Project1 or any existing folder
You are able to change directory to /home/user/Project1
You are able to change directory to /home/user
|Error handling||cd fakeDirectory|
Error message for invalid path
If you made it this far and everything is working, you’ve done a really great job and you’ve passed all testing cases.
So you are finished! Unless
Implement the history feature as described at the end of the project description. If you get it working flawlessly and eventually earn an A in the class, then I will think you are awesome and get 20 bonus points on this project as well. If you are only able to get it to work partially, then explain, in detail, what is working and tell me how many bonus points you think it’s worth between 1 and 19. Please make sure the rest of your project is working first.
What did you learn?
1.How far did you get in this project? What grade are you expecting? Did you find the milestones in the description helpful? Do you think you could have gotten the project working as well as you did without the milestones?
2.Do you feel like a better programmer now that you’ve completed this project? How does this compare to programming project that you’ve had in prior class?
3.Describe 3 problems (relating to this assignment) that arose while you were working on this project and explain how you solved them.
4.How long did you spend on this assignment? Give me specifics. For example:
5.Total hours spent. Try to be honest and do not exaggerate here.
- Make frequent backups of your program so that you can revert to a working copy if you mess something up.
- Do NOT turn a program that will no compile. We will not be able to test it, and we can’t spend time trying to get it working, so you will not get any credit.
- Keep sharing and posting in the discussion board.