Lab 1 Name: Checked: (instructr r TA initials) Objectives: Learn abut jgrasp - the prgramming envirnment that we will be using (IDE) Cmpile and run a Java prgram Understand the relatinship between a Java class names and file names Practice using basic Java utput statements and adding dcumentatin (cmments) t yur surce cde Experience Java errrs Learn the basics f sequential executin, variables, and the assignment statement Instructins: Cmplete and submit the preparatin befre cming t the lab. Yu will be assigned a partner fr this lab. Each f yu will cmplete the lab separately, but feel free t help each ther learn! If bth are stuck r dn't understand smething, get help frm instructr r TA At varius pints, yu are asked t cmpare yur wrk with yur classmate s and sign each ther s wrksheet. Be sure t check yur classmate s wrk befre signing. What if yur answers are different? Which ne is crrect? It may be that they are bth crrect, but ask fr help if yu are nt sure. When finished, dem yur prgrams and get yur wrksheet checked and initialed by the instructr r TA. Preparatin: Fllw the instructins n the curse website t install Java JDK and jgrasp n yur laptp. 1. Create a flder n yur cmputer fr this curse. Yu are respnsible fr rganizing yur files fr each lab int separate subflders. Fr example, use a flder Lab01 fr this lab s files. 2. Dwnlad and save Lincln.java. Open the file using jgrasp. 3. In jgrasp, cmpile Lincln.java by clicking big green plus buttn: Nte that yu nw have a file Lincln.class in the same flder It is NOT required (r desirable) t pen that file, but yu may, if yu are curius. It is nt meant t be read by humans! It cntains the bytecde that yu will run, as instructed in the next step. 4. In jgrasp, run Lincln.class by clicking n the red runner buttn: This causes yur prgram t execute its instructins See the utput f this run in the interactins (lwer pane) in jgrasp 5. When finished, submit the files Lincln.java and Lincln.class thrugh blackbard under the assignment Lab 1 Prep
Part A: Running and mdifying cde 1. Open, cmpile and run the ther tw examples frm chapter 1: Lincln2.java and Lincln3.java These wrk fine but are hard t read. Practice tidying up the cde and nte that yu can use the Generate CSD and Remve CSD buttns t make the jb easier. Shw yur wrk t a classmate. 2. Open Lincln.java again. Edit it by renaming the class t MyLincln. Try t cmpile the prgram. What happens? Save this mdified prgram as MyLincln.java and run MyLincln. Add r mdify the cmments at the tp f the prgram t include: Yur name (yu are nw the Authr) A nte abut the riginal authr ("based n a prgram by Lewis & Lftus") Tday's date A very shrt summary f the mdificatins yu made Re-cmpile and run t make sure it still wrks (there shuld be n difference in its functinality) Part B: Debugging 3. Experiment with MyLincln.java and intrduce sme errrs ( bugs ). Try sme f the fllwing t see what happens when yu re-cmpile and (if successful) run the prgram. If yu get an errr right away, mark it as syntax, if it cmpiles but yu get an errr when yu try t run it, mark it as runtime, and if it cmpiles and runs but prduces a wrng (r different result than intended, which we take t be the riginal), mark it as lgic. (Be sure t fix each errr befre the next!) Change the first println t print Errr: Change the secnd println t bgus Errr: Remve the semicln at the end f ne f the statements Errr: Remve the last brace f the prgram Errr: Change main t man Errr: Smething else yu tried? Errr: Classmate signature (cmpare ntes):
Part C: Creating a prgram frm scratch: MyQute.java 4. Using MyLincln as a mdel, create a new prgram named MyQute and make it d the fllwing: Print ut a new qute f yur chsing Add variables t the prgram such as: int x = 42; int cunt = 100; duble pi = 3.14; String name = "Kripke"; (we will be studying variables next week; fr the mment we are just experimenting!) Add mre utput statements t use yur new variables, such as: System.ut.println ("Hwdy " + name); System.ut.println ("The answer is " + x); System.ut.print ("Cunting... up: " + (cunt + 1)); System.ut.println ("... and\n... dwn: " + (cunt - 1)); System.ut.println("The perimeter f a circle with radius " + x + " is " + (2* pi * x)); Be sure t pay attentin t crrect structure, syntax, indentatin, and cmments! Feel free t be creative! Cmpile and run yur prgram t make sure it wrks and that it prints ut the values f yur variables where yu expect them. Try changing it arund t use different values r different variable names (we are using the names x, cunt, and name here). Be sure t stay away frm the reserved wrds (see fig 1.18, p32). We will be learning a lt mre abut variables, but fr the mment yu can just experiment with whatever cmes t mind. Dn t wrry abut making mistakes that s the best way t learn. REMINDERS: 1) Review wrksheet. All questins answered and in agreement with partner Signatures frm yur partner where required 2) Fill ut the cmment sheet 3) Dem yur prgrams and get initials frm instructr r TA n this wrksheet 2) Detach and hand in the cmments sheet.
Lab 1 Cmments Name: Checked: What was the mst valuable thing yu learned in this lab? What did yu like best abut this lab? Was there any particular prblem? D yu have any suggestins fr imprving this lab as an effective learning experience?