Programming MethodologyLecture02.docx

上传人:b****5 文档编号:6015500 上传时间:2023-01-03 格式:DOCX 页数:17 大小:32.04KB
下载 相关 举报
Programming MethodologyLecture02.docx_第1页
第1页 / 共17页
Programming MethodologyLecture02.docx_第2页
第2页 / 共17页
Programming MethodologyLecture02.docx_第3页
第3页 / 共17页
Programming MethodologyLecture02.docx_第4页
第4页 / 共17页
Programming MethodologyLecture02.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

Programming MethodologyLecture02.docx

《Programming MethodologyLecture02.docx》由会员分享,可在线阅读,更多相关《Programming MethodologyLecture02.docx(17页珍藏版)》请在冰豆网上搜索。

Programming MethodologyLecture02.docx

ProgrammingMethodologyLecture02

ProgrammingMethodology-Lecture02

Instructor(MehranSahami):

Alrighty,welcomebacktoCS106A.Ifyou'restuckintheback,justcomeondown,haveaseat.Originally,Ithoughtmaybewewouldhaveslightlyfewerpeopletodaythanlasttime,butthatappearsnottobethecase.Sowhilewe'rewaiting,everyonelovesbabies,soIdecidedtoput?

that'sKarel,theRobot,theearlydays.

No,thisactually?

myson,andyeah,Iknow.He'salittlebitoldernowbut,like,he'sgottheselittlerobotpajamasandherunsaroundallthetime.SoI'mlike,oh,it'sKarel,TheRobot,andmywifelooksatmelike,it'syourson.Butthat'sawholedifferentissue.

Anyway,afewadministrativeannouncementsbeforewestart.Acouplethings,therearefourmorehandoutstoday,justbecausewelikeconsistency.Fourlasttime,there'sfourthistime.They'reallintheback.Ifyoudidn'talreadypickthemup,youcanpickthemupafterclass,buttheyhavealltheinformationaboutdownloadingEclipse,whichistheenvironmentthatyou'regoingtouseforprogramminginthisclass,bothforKarelandforJava.

ThereisalsoaspecialhandoutintherejustonusingKarel,soittalksabouthowKarelworksintheEclipseenvironment,andsoyoucangetallsetupwiththat.Andsoaftertoday,you'llknowhowKarelworksandyou'llhavetheenvironmenttouseit.Sosurprisinglyenough,youalsogetyourfirstassignmenttoday,whichisactuallyintwoparts.

Sotheassignment,therealassignmentistheprogrammingpart,whichisdueonFridayofnextweek,October5th.Thereisalsoanemailparttoit,wheretheemailpartis,weaskallofyoukindfolkstosendanemailtoBen,theheadTA,myself,andalsoyoursectionleader.SoBenandIgetawholebunchofmail,yoursectionleaderwillhopefullygetalittlebitlessmail.

Butyouwon'tactuallyknowyoursectionleaderuntilafteryougotoyourfirstsectionnextweek,whichiswhythatpartoftheassignmentisnotactuallydueuntilbasicallyoneminutebeforemidnightonSunday.SoIdidn'tmakeitmidnight,justbecausethenthere'salwaysconfusion,midnight,whichnight?

So11:

59p.m.onSunday,October7thiswhenyoushouldsendthatemail.

That'snotreallythecriticalpartoftheassignment.Thecriticalpartoftheassignmentistheprogrammingproblems,whichareactuallyalldueinclassonFriday.Okay,andthenthere'sonelastassignment,oronelasthandout,whichisabouthowyouactuallysubmityourworkinthisclass.You'llsubmityourworkbothelectronicallyandinhardcopy.Theelectroniccopy,sothatyoursectionleadercanrunitandverifyit.Thehardcopyissothattheycanactuallywritecommentsonit,andthenyou'lldointeractivegradingwiththemaswell.

Acoupleotherquickannouncements.Thewebsite,incaseyouweren'thereonMondayandyoudon'tknowwhathandoutsI'mtalkingabout,andyoudon'tknowwheretogetthem,gototheclasswebsite,cs106A.stanford.edu.TherewillbeelectroniccopiesinPDFformatofallthehandoutsthere,soyoucangetcaughtupiftodayisyourfirstday.

Youalsoneedtosignupforasection.Aswementionedlasttime,sectionsignupsstarttomorrow,5:

00p.m.Signupearlyifyouwanttohavethemostflexibilityintermsoftime,becauselookaround,there'sawholebunchofpeopleinthisclass.It'sgoingtofillupquickly.Soifyouhaveconstraints,signupquickly,andtheplaceyousignupisCS198,notCS106A,butCS198.stanford.edu/section.The198folksarethefolkswholovinglyrunallofthesectionsandcoordinatethewholeprogram.

Last,butnotleast,justawordonthereadingsthatIdidn'tmentionlasttime.Onthesyllabus,you'llnoticethatprettymuchforeveryday,ormostdaysinthequarter,thereissomesortofreadingassociatedwithit.That'sthereadingassignmentthatyoushouldhavedonebythatday'slecture,becausethat'swhatwewillcoverinthatday'slecture.

SofortodayitshouldbethefirstthreechaptersoftheKarelbook,orthecoursereader.Andifyou'relike,ohmyGod,I'malreadythreechaptersbehind,don'tworry,it'slike20pagesorsomething.It'sprettylightweight,butyoushoulddothereadingsbythattimeinclass.Soanyquestionsaboutanythingwecoveredlasttime,whichismostlylogistics,oranyofthesortofadministrivia?

Allrighty,thenlet'sgetstartedontherealcontent.Soyourememberfromthetimebefore,wetalkedalittlebitaboutKarel,theRobot,andhereisKarelinthatworldthatIshowedyoubefore.Andtherewereavenuesthatrunnorth-south,andstreetsthatruneast-west,andlittlebeepersintheworld.AndKarencanfacedifferentdirections,andthere'swalls.

Andsonow,wewanttothinkabouthowdoweactuallyprogramKarel.Howdowegetthislittleguytodosomethinginterestingintheworld?

Okay,anditturnsouttherearefourcommandsthatKarelunderstands,okay,andthoseareprettystraightforward.

Soheretheyare.You'regoingtogetallofKarel'svocabularyin,like,oneminute.There'sacommandcalledmove,andmovebasicallymovesKarelonespotforwardinthedirectionhe'sfacing.Soifhe'soncornerone,one,andhemovesonespotforward,he'sfacingeast.Sohe'llmoveovertotwo,one,basically.Soonecornerforwardinthedirectionhe'sfacing.

Karelalsostartedbeingagooddemocrat,knowshowtoturnleft.Soheturnsleft.ThisisalowercaseT,thisisanuppercaseL.Soturningleftchangeshisdirectionby90degreesinthelefthandofwhicheverwayhe'sfacing.Soifhe'sfacingeastnow,andheturnsleft,hewillbefacingnorth.Andthenhecanturnleftagainandhe'llbefacingwest.

Okay,now,question?

Student:

[Inaudible]?

Instructor(MehranSahami):

Thereisnospacehere.Thesearealloneword.Goodquestion,andIloveitwhenyoumakeiteasy.Allright,sobesidesturningleft,there'salsoB-personKarel'sworld,andifhecouldn'tdoanythingwithbeepers,theywouldn'tbeinteresting.Sohecanpickupbeepers,whichinterestinglyenoughiscalledpickBeeper,againlowercaseP,uppercaseB,alloneword,andthereisputBeeper.

AndwhatthesedoispickBeeper,ifKarelhappenstobeonacornerthathasaBeeperonit,hepicksupthatBeeper,andstuffsitinhisBeeperbag,inwhichcasethecountinhisBeeperbaggoesupbyone.Orifit'sinfinite,itremainsinfinite,becausehe'sgotarealbigBeeperbag,andsometimeshecaninfinitelymanyBeepersinthere.It'sjust?

wecantalkabouttheinfinityofKarel'sBeeperbagssomeothertime,butifyou'reinterested,it'sfascinating.

AndhecanalsoputBeeper,whichmeanshecangotoacornerandbelike,"Hey,I'mjustfeelinghappy.I'mgoingtoputaBeeperdown,say,onthatcornerrightthere."Exceptyoucan'tthrowthebeepers,right.Karel'skindoflimited.He'sgot,youknow,ifyoulookathimhe'sgotnoarms.He'sgotlegs.Noarms,sobasicallyallhecandoishesortoflikedropsthelittleBeeperwherehe'sat.Sothisputsitonthecornerthathe'sat.

Andthesethingsarewhatwerefertoasmethods.Okay,methodsarebasicallysomeinstructionthatwecancall,okay,oruse,likemove,orturnleft,orpickBeeper,orputBeeper.AndwhatwesayisKarelrespondstothismethod.Whatwe'redoingiswe'reinvoking,orwe'recallingaparticularmethodonKarel,andhetakessomeaction,whichisbasicallywhatthatmethodspecifiestodo.

Okay,soifwekindofthinkaboutthisprogram,orifwekindofthinkaboutthisworld,maybewewantKareltodosomething.Sohere'stheinitialconfigurationoftheworld.MaybewhatwewantKareltodoispickupthisbeeper,dropitoffatthiscorner,andendupatthiscornerfacingtotheeast.Andyoucanthinkabouthowwemightdothatwithsomeoftheinstructionswehave.

Sowhatwewantthefinalconfigurationoftheworldtolooklike,andI'lljustputKarelatblindingspeed.YoucanactuallycontrolKarel'sspeedherewiththislittleslider.SoI'mgoingtojustshowyoutheendconfigurationbyrunningKarelsofastyoucan'tevenseeit.It'sjust?

he'sblindinglyfast.He'sjustthatgood,okay.

Andsothat'swhatwewanttogetto.Noticehe'sstillfacingeast,buthe'spickedupthatbeeperthatwasonthatcornerattwo,one,andmoveditovertothecorneratfour,two.Okay,andsohowmightwedothis?

Right,soonethingwecouldconsideris,whatwastheinitialstateoftheworldagain?

SoI'mjustgoingtorunthisprogramagain,andhereIhaveaclipsetup,whichisyourhandoutnumberfiveexplainshowtogetthis.ButifIwanttorunaprogram,thereisthesetwolittlerunningpersonicons,orasyoumightnotice,weevenhaveourownmenuinEclipse,becauseStanford'sjustthatmuchfun,okay.

SoundertheStanfordmenu,wehavethesetwooptionsforrun.Importprojectisexplainedinthehandout,iswhatyou'lluse.We'llgiveyousomeinitialstuffforKarelthatyou'llstartwith,andyou'lluseimportprojecttogetitintoEclipse.Butonceit'sthere,wecanrunit,andsowhatwe'regoingtodoissayrunthisparticularKarelprogram.Soit'sget?

andwe'llgothroughallthis?

it'sgetandgo.

AndthisisourfirstKarelprogramthatwewanttorun,andit'ssortof,here'stheinitialworldagain,allbigandhappy.SoI'mgoingtoshrinkthisdownalittlebit,sowecanseeitoverhereontheside,whilewethinkaboutwhatcommandsKarelwouldneedtoexecutetokindofgettothatfinalstatewejusttalkedabout.

Andoverhere,happilyenough,letmeresizealittlebit,isourfirstfile,whichisemptyrightnow,thatwe'regoingtowriteourfirstKarelprogram.SowhatcommandsmightweconsiderKarelactuallydoingfromthelistyouhavehere,tosortofaffectw

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 军事政治

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1