CS 1311 Spring 2001 Assignment 10 The First Brush with Java Due date and time: Friday, March 23, 2001 9:00 a.m. (See warning at the end of this assignment) This assignment has three major objectives 1. Download and install Java and a suitable editor onto your computer 2. Try out Java by writing and running (in Java) some programs that do the same (or similar) kinds of things as programs that you have already written in pseudocode. 3. Learn how to submit assignments to WebWork that will be autograded. NOTE: For many people installing Java and a suitable editor will be very simple and uneventful. For a small percentage of students there will be problems. Do not wait until the last minute!!! Objective 1 Installing Java =============== Go to the CS 1312 (NOT CS 1311) class webpage: http://www.cc.gatech.edu/classes/AY2001/cs1312/ and follow the links to Java Resources depending on the type of machine/Operating System that you are using. Follow the instructions. If you have problems and are using Windows your TA or lecturer may be able to help you. If you have problems and are using a Mac look for help on the macusers newsgroup: git.cc.class.cs131x.macusers If you are using Unix/Linux/Free BSD look for TA's wearing shirts that say things like: "So little time, so much to code". They may be wearing shirts with Penguins. They will probably be drinking Surge. They will not be running Windows on their laptop. They will be sleepy. They will be wearing wrist braces. Installing an Editor ==================== Option 1: Recommended for CS majors and anyone who expects to be doing a lot of work on computers using different operating systems and anyone who likes the idea of wearing wrist braces. Emacs: Go to the CS 1312 (NOT CS 1311) class webpage: http://www.cc.gatech.edu/classes/AY2001/cs1312/ and follow the links to Emacs depending on the type of machine/Operating System that you are using. Option 2: Go to http://www.jcreator.com and download Jcreator. Install after the Java install is complete. Follow the instructions Option 3: Go to http://www.ultraedit.com and download Ultraedit. Follow the instructions. Objective 2 Write the following programs: P1: A program that will print Hello, world! on the screen. This should be in a file called Helloworld.java and the only method should be the main method: public static void main(String args[]) P2: Create a file called P2.java containing a class called P2 This class will contain several static methods. This means that the method will have the word static in its header (example): public static void someMethod(... Note: What we will be doing in this assignment is not typical object-oriented programming. It is simply designed to let you get a feel for writing methods, passing parameters, etc. The class does not need any variables but should contain necessary constants (e.g. public static final String MYGTNUM = "gt1234";) Also remember that Java is case sensitive so the required headers given to you must appear in your assignment exactly as they appear in this assignment. Write methods that will do the following: a.) Print your gt number to the screen. Required method header: public static void gtnum() b.) Take in a String and print it 1 time on 10 lines. Don't be a chump, use a loop! Required method header: public static void print10(String datain) c.) Take in three ints and return the maximum. Required method header: public static int max3(int n1, int n2, int n3) d.) Take in two ints. Inside the method print out the two values, then swap them then print them out (still inside the method.) Required method hearer: public static void swap(int n1, int n2) e.) Take in two ints. Print them out, call the swap method (from d), after it returns print out the current value of the variables that you passed in to swap. Can you explain what happened? Will you be able to explain it on a test? Required method header: public static void swapTest(int a, int b) f.) Passed in an int n calculate and return n factorial (n!). Use recursion. Required method header: public static int factR(int n) g.) Same as f only use iteration (some kind of loop). Required method header: public static int factL(int n) h.) You should also write a main method. Your main method should call all of the methods that you have written and thoroughly test them. Required method header: public static void main(String args[]) Objective 3 Turn in the following files to WebWork: Helloworld.java Helloworld.class P2.java P2.class You will get a grade report and may resubmit as many times as you wish (which also depends on the current WebWork reponse time.) Starting early (and finishing early) will pay big dividends. Note: A post will be made to .announce letting you know when the autograder is available. AutoGrading: Helloword: 10 points 10 Methods a-g above: 10 points apiece. 70 TA Evaluation: This will include style issues such as spacing, indentation, comments (precondition, purpose and postcondition), use of constants plus evaluation of the main (did it test all methods thoroughly, etc.) 20 --- 100 Note: The autograder will actually call your methods by itself and test them. Your main should test the methods to aid you in making sure that they work correctly. # # ## ##### # # # # # #### # # # # # # ## # # ## # # # # # # # # # # # # # # # # # # ## # ###### ##### # # # # # # # # ### ## ## # # # # # ## # # ## # # # # # # # # # # # # # #### Many students assume that they cannot fail to get a perfect score on an autograded assignment. "After all," they think, "I'll just run it over and over until it's perfect." Many of these students will achive less than satisfactory results because they start too late and they fail to take into account the autograder slow-down at the last minute. In addition, the autograder does not teach you Java. It is a tool to help you learn. Randomly changing lousy code in a futile last minute Las Vegas style of programming will amuse us and frustrate you. IT WON'T WORK!!! Due date and time: Friday, March 23, 2001 9:00 a.m.