SlideShare a Scribd company logo
1 of 5
Download to read offline
CS3 Project                   - HANGMAN
Objective:

    r    Create a Hangman console game
    o    Create a console application that allows the user to add/delete words to be used in the game

Deadline:

    r    Second week of January 2011 (first meeting of the week)

Other details:

    o    Lab pairings will be in effect.
    o    I   will give you the entire 1" week of January to do this but you might want to start during the
         brea k
    o    There will be 2 modules so you can work independently at the start then combine the modules
         at the end or work on both modules together.
    o    The emphasis will be handling inputs through console and external file     a-s   well as proper error
         handling.
    o    For any questions, email me at: paolo.santos@pshs.edu.ph or paolo.niccolo.santos@gmail.com



lnstructions:

    1.   Create a menu that displays:


         1. Manage Word Library
         2. Play Hdngman
         J. tlx] f,

         >l
    2.   When L is selected, the user is directed to module 1 (See next page).
    3.   When 2 is selected, the user is directed to module 2 (See page 3).
    4.   Selecting 3 ends the program.
Module 1: Creating the Word Library (File Reading/Writing Module)

     L.   Start by manually creating a text file containing the default list of words (each word
          separated by a new line). Name it wordlist.txt. The file should look like this:

          Merry
          Christmas
          Rudolph the red nosed reindeer



     2.   At the start of the module, load all the words into an array of Strings
     3.   Then, display the following menu:


          1. Display word library
          2. Add a word
          3. Delete a word
          4. Save current list
          5. Exit
     4.   When f. is selected, print the entire array of words.
     5.   When 2 is selected, prompt the user for a word then add it to the array.
     6.   When 3 is selected, print the entire array of words in this manner:


          I.   Merry
          2.   Christmas
          3.   Rudolph the red nosed reindeer



          Then prompt the user for a NIJMBER. Delete the word that corresponds to that number
          (example if the user enters 1, delete Merry from the array).


     7.   When 4 is selected, save the words contained in the array to wordlist.txt
     8.   When 5 is selected, return the user to the previous menu.
Module 2: Creating the game (Console Inputs Module)

        1.   You will need the file HangmanWord.java (located at the end of this document) for this
             module.
        2.   Start with an arrav of words and use the random class to generate a random number to
             randomly pick a word from the list.
        3.   Once a word is selected, you now need to transform it into a HangmanWord
                 a. To create a HangmanWord, simply input the String into the constructor:
                       new HangmanWord(<String value>);
                 b.    How to use a HangmanWord Object:
                           i.    When the object is created, it automatically geneterates a String that
                                 contains the blanks of the word. Meaning if you entered new
                                 HangmanWord("hello"), it generates "           ".
                                                                         ----
                           ii.   To output the String of blanks, use the outputBlanksfl function.
                          iii.   You can use the use the guess(char letter)or guess(String letter)function to
                                 guess a letter that is contained in the word. lt outputs true if the letter is
                                 contained in the word, false otherwise. lt is CASE SENSITIVE. lf the letter is
                          .      contained in the word, the blank is replaced by the letter.
                          iv.    Calling the isGuessed0 function returns true if the word is successfully
                                 guessed, and false otherwise.
        4.   OnCe yOu've made       your hangman wOrd, set hOw many "lives" your user has tO guess the
             word.
        5.   Output the blanks

                                                               (example the word is snowman)

        6.   Prompt the user for an input (either String or char)
             >s
        7.   Use the guessfl     function of the HangmanWord o.bject
                 a.    lf it returns true, output the blanks


                 b.    lf it returns false, subtract a "life" from the user then output the blanks
                 c.    lf the word is fully guessed (no more blanks)go back to 1.
                 d.    lf the user is out of lives, output the word then go back to the main menu.
    '            e,    lf the user is not out of lives and the word still contains blanks, go back to 5.
public cfass Hanqmanword {
    private String inword;
    nriv,atc Strino outword;
     nri vafe i nt I etters I eft;

    nrrl.rlin       llanam:nfaTnrd/af   Vvgl4rrY
                                                    rina       r^rnrrl   t

             inword : word;
             outword : "";
             Ietters feft : 0;
             for(int i:0;     i < word.IengthO; i++;1
                  1f((word.charAt(i):: ' ') I | (word.charAt(i):= '. ',                                    I   I


                    (word.charAt(i):: ', ') | I (word.charAt(i):: 'e'1 |                               t


                    (word.charAt(i)::'l')   | I (word.charAt(i):: "")   |                              l


                    (word.charAt (i)::'"  )){
                       outword : outv/ord + word.charAt(i) ;
                  ) else {
                     outword : outword         ;
                     Ietters_left++;
                          )

                ]
     )


    public boofean giress (char letLer)                                       {

       boofean hasletter : false;
        for(int i = 0; i < inword.lengtho; i++11
             if ( (lnword. charAt (i) := letter) && (outword. charAt (i) :: '_')                                   )i
                   outhrord: outword.substring(0,i) + fetter +
                                                         outword. substri-ng ( i+1, outword. lenqth ( ) ) ;
                              L--T                   *     +vr,^.
                              IIOJ!V ^tt^, LgI
                                        L
                              letters_left--;

                ]


         .   return has{.etter;
     t
     t


     pub-Iic boo}ean guess (St ring letter ) {
             if(letter.lengthO    != 1) t
                   SysLem.out.println ("lnvalid guess. ")                           ;
                    return false;
                ]


             boolean hasLetter : false;
             for(int i:0;        i < inword.lengthO; i++11
                  if  ( (Ietter.equals (inword.substring(i, i+1) ) )                          &&
                     ("_".equals (outword. substring (i,i+t1 ; I 1                       1




                       outword : outword. substring (0, i) + fetter +
                              outword. substring (i+1, outword. length ( ) ) ;
                              hasLetter : true;
                              fetters_left--;
/

                                                                                       -


            return hasLetter;
    )



    public void seLWorl (String word)          {

        inword : word;
        outword : "";
             letters_left : O;
            for(int   i = 0; i < word.lengthO; i++11
                    if((word.charAt(i):= ' ') ll (word.charAt-(i)::'.')       ll
                            (word.charAt(i):= ', ', I I (word.charAt(i):: '?') i
                                                                               i


                            (word.charAt(i):= ttt; ll (word.charAt(i):: "'t, 1l
                            (word'charAt (i)::' " ) ) {
                      outword: outword + word.charAt(i) ;
                 l else   1


                    outword : outword + "_" ;
                    f ette rs_le ft ++;
                      l
            I
    )


    n'ht in qts,,n^ ^rll-^ufBlanks()       {

         String   out : tr tt -

            for(int i:0;    i < outworcl.lengthO; i++;1
                 our : our + outword. charAt (i) + rr II'
            )



            return out. trin   (   )   ;
        )



    public boolean isGuessedO {
        return (letters left- :: 0);
        l




                                                                                   5

More Related Content

What's hot

Python unit 2 M.sc cs
Python unit 2 M.sc csPython unit 2 M.sc cs
Python unit 2 M.sc csKALAISELVI P
 
Python for text processing
Python for text processingPython for text processing
Python for text processingXiang Li
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutesSumit Raj
 
Ad hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and CatsAd hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and CatsPhilip Schwarz
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaRasan Samarasinghe
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basicsLuigi De Russis
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for KidsAimee Maree Forsstrom
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayAlexis Gallagher
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutesSidharth Nadhan
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
 
Python Puzzlers - 2016 Edition
Python Puzzlers - 2016 EditionPython Puzzlers - 2016 Edition
Python Puzzlers - 2016 EditionNandan Sawant
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Paige Bailey
 

What's hot (20)

Python unit 2 M.sc cs
Python unit 2 M.sc csPython unit 2 M.sc cs
Python unit 2 M.sc cs
 
Python
PythonPython
Python
 
DITEC - Programming with Java
DITEC - Programming with JavaDITEC - Programming with Java
DITEC - Programming with Java
 
Python for text processing
Python for text processingPython for text processing
Python for text processing
 
An Intro to Python in 30 minutes
An Intro to Python in 30 minutesAn Intro to Python in 30 minutes
An Intro to Python in 30 minutes
 
Ad hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and CatsAd hoc Polymorphism using Type Classes and Cats
Ad hoc Polymorphism using Type Classes and Cats
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in Java
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basics
 
Python introduction
Python introductionPython introduction
Python introduction
 
Python
PythonPython
Python
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
 
Protocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That WayProtocols with Associated Types, and How They Got That Way
Protocols with Associated Types, and How They Got That Way
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutes
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 
Python Puzzlers - 2016 Edition
Python Puzzlers - 2016 EditionPython Puzzlers - 2016 Edition
Python Puzzlers - 2016 Edition
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Functional concepts in C#
Functional concepts in C#Functional concepts in C#
Functional concepts in C#
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 

Viewers also liked

The fall of the empire
The fall of the empireThe fall of the empire
The fall of the empireiamkim
 
Fil 3 q readings
Fil   3 q readingsFil   3 q readings
Fil 3 q readingsiamkim
 
Letter science fair
Letter science fairLetter science fair
Letter science fairiamkim
 
Physics newton's laws
Physics   newton's lawsPhysics   newton's laws
Physics newton's lawsiamkim
 
Chem lin reg
Chem   lin regChem   lin reg
Chem lin regiamkim
 
Outreach room assignments for lakbay-aral (v2).
Outreach   room assignments for lakbay-aral (v2).Outreach   room assignments for lakbay-aral (v2).
Outreach room assignments for lakbay-aral (v2).iamkim
 
Upcat sched
Upcat   schedUpcat   sched
Upcat schediamkim
 
1 july 2011 batch congress
1 july 2011 batch congress1 july 2011 batch congress
1 july 2011 batch congressiamkim
 
Ss italian renaissance
Ss   italian renaissanceSs   italian renaissance
Ss italian renaissanceiamkim
 
Nat sci minerals part1
Nat sci   minerals part1Nat sci   minerals part1
Nat sci minerals part1iamkim
 
Exploration
ExplorationExploration
Explorationiamkim
 
Upcat sched
Upcat   schedUpcat   sched
Upcat schediamkim
 
Dost application
Dost applicationDost application
Dost applicationiamkim
 
Yearbook grad pic orders
Yearbook   grad pic ordersYearbook   grad pic orders
Yearbook grad pic ordersiamkim
 
Cat revised guidelines on tickler formatting (with signatures).
Cat   revised guidelines on tickler formatting (with signatures).Cat   revised guidelines on tickler formatting (with signatures).
Cat revised guidelines on tickler formatting (with signatures).iamkim
 
High Operating Costs
High  Operating  CostsHigh  Operating  Costs
High Operating Costssolardude
 
Tenegen ea prez_0325
Tenegen ea prez_0325Tenegen ea prez_0325
Tenegen ea prez_0325kriszi
 
Tenegen tanarszerep 2010_1001
Tenegen tanarszerep 2010_1001Tenegen tanarszerep 2010_1001
Tenegen tanarszerep 2010_1001kriszi
 
Multimedia2009 Prez Fodorne
Multimedia2009 Prez FodorneMultimedia2009 Prez Fodorne
Multimedia2009 Prez Fodornekriszi
 
Változó tanárszerep - XI. E-learning fórum
Változó tanárszerep - XI. E-learning fórumVáltozó tanárszerep - XI. E-learning fórum
Változó tanárszerep - XI. E-learning fórumkriszi
 

Viewers also liked (20)

The fall of the empire
The fall of the empireThe fall of the empire
The fall of the empire
 
Fil 3 q readings
Fil   3 q readingsFil   3 q readings
Fil 3 q readings
 
Letter science fair
Letter science fairLetter science fair
Letter science fair
 
Physics newton's laws
Physics   newton's lawsPhysics   newton's laws
Physics newton's laws
 
Chem lin reg
Chem   lin regChem   lin reg
Chem lin reg
 
Outreach room assignments for lakbay-aral (v2).
Outreach   room assignments for lakbay-aral (v2).Outreach   room assignments for lakbay-aral (v2).
Outreach room assignments for lakbay-aral (v2).
 
Upcat sched
Upcat   schedUpcat   sched
Upcat sched
 
1 july 2011 batch congress
1 july 2011 batch congress1 july 2011 batch congress
1 july 2011 batch congress
 
Ss italian renaissance
Ss   italian renaissanceSs   italian renaissance
Ss italian renaissance
 
Nat sci minerals part1
Nat sci   minerals part1Nat sci   minerals part1
Nat sci minerals part1
 
Exploration
ExplorationExploration
Exploration
 
Upcat sched
Upcat   schedUpcat   sched
Upcat sched
 
Dost application
Dost applicationDost application
Dost application
 
Yearbook grad pic orders
Yearbook   grad pic ordersYearbook   grad pic orders
Yearbook grad pic orders
 
Cat revised guidelines on tickler formatting (with signatures).
Cat   revised guidelines on tickler formatting (with signatures).Cat   revised guidelines on tickler formatting (with signatures).
Cat revised guidelines on tickler formatting (with signatures).
 
High Operating Costs
High  Operating  CostsHigh  Operating  Costs
High Operating Costs
 
Tenegen ea prez_0325
Tenegen ea prez_0325Tenegen ea prez_0325
Tenegen ea prez_0325
 
Tenegen tanarszerep 2010_1001
Tenegen tanarszerep 2010_1001Tenegen tanarszerep 2010_1001
Tenegen tanarszerep 2010_1001
 
Multimedia2009 Prez Fodorne
Multimedia2009 Prez FodorneMultimedia2009 Prez Fodorne
Multimedia2009 Prez Fodorne
 
Változó tanárszerep - XI. E-learning fórum
Változó tanárszerep - XI. E-learning fórumVáltozó tanárszerep - XI. E-learning fórum
Változó tanárszerep - XI. E-learning fórum
 

Similar to Cs hangman

controlstatementspy.docx
controlstatementspy.docxcontrolstatementspy.docx
controlstatementspy.docxmanohar25689
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Twoamiable_indian
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string libraryMomenMostafa
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxCatherineVania1
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
Introduction to Kotlin.pptx
Introduction to Kotlin.pptxIntroduction to Kotlin.pptx
Introduction to Kotlin.pptxAzharFauzan9
 
01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptxIvanZawPhyo
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python ProgrammingVijaySharma802
 

Similar to Cs hangman (20)

Python Part 1
Python Part 1Python Part 1
Python Part 1
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 
controlstatementspy.docx
controlstatementspy.docxcontrolstatementspy.docx
controlstatementspy.docx
 
C tutorial
C tutorialC tutorial
C tutorial
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
9 character string &amp; string library
9  character string &amp; string library9  character string &amp; string library
9 character string &amp; string library
 
Improve Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
 
Python Session - 4
Python Session - 4Python Session - 4
Python Session - 4
 
Java Week4(C) Notepad
Java Week4(C)   NotepadJava Week4(C)   Notepad
Java Week4(C) Notepad
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
Python programming
Python  programmingPython  programming
Python programming
 
LectureNotes-04-DSA
LectureNotes-04-DSALectureNotes-04-DSA
LectureNotes-04-DSA
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
Introduction to Kotlin.pptx
Introduction to Kotlin.pptxIntroduction to Kotlin.pptx
Introduction to Kotlin.pptx
 
01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx01 Introduction to Kotlin - Programming in Kotlin.pptx
01 Introduction to Kotlin - Programming in Kotlin.pptx
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 

More from iamkim

Nat Sci - Minerals
Nat Sci - MineralsNat Sci - Minerals
Nat Sci - Mineralsiamkim
 
Batch 2012 schedule of exit interview
Batch 2012 schedule of exit interviewBatch 2012 schedule of exit interview
Batch 2012 schedule of exit interviewiamkim
 
College test results b2012
College test results b2012College test results b2012
College test results b2012iamkim
 
Chem cations
Chem   cationsChem   cations
Chem cationsiamkim
 
Chem anions
Chem   anionsChem   anions
Chem anionsiamkim
 
Grad ball collections per section(01 28-12)
Grad ball collections per section(01 28-12)Grad ball collections per section(01 28-12)
Grad ball collections per section(01 28-12)iamkim
 
Congratulations to batch 2012 star scholar candidates
Congratulations to batch 2012 star scholar candidatesCongratulations to batch 2012 star scholar candidates
Congratulations to batch 2012 star scholar candidatesiamkim
 
Retreat consent form
Retreat consent formRetreat consent form
Retreat consent formiamkim
 
Retreat agreements
Retreat agreementsRetreat agreements
Retreat agreementsiamkim
 
Fil la loba negra
Fil   la loba negraFil   la loba negra
Fil la loba negraiamkim
 
Fil fray botod
Fil   fray botodFil   fray botod
Fil fray botodiamkim
 
Dasalan at tocsohan
Dasalan at tocsohanDasalan at tocsohan
Dasalan at tocsohaniamkim
 
Chem ps electrolysis
Chem   ps electrolysisChem   ps electrolysis
Chem ps electrolysisiamkim
 
Physics waves
Physics   wavesPhysics   waves
Physics wavesiamkim
 
Math 3 hw ps2
Math   3 hw ps2Math   3 hw ps2
Math 3 hw ps2iamkim
 
Memo circular # 4 dtd nov 4, 2011
Memo circular # 4 dtd nov 4, 2011Memo circular # 4 dtd nov 4, 2011
Memo circular # 4 dtd nov 4, 2011iamkim
 
Final creative shots hair & makeup evaluation (110211)
Final creative shots hair & makeup evaluation (110211)Final creative shots hair & makeup evaluation (110211)
Final creative shots hair & makeup evaluation (110211)iamkim
 
Creative shots hair & makeup evaluation (110211)
Creative shots hair & makeup evaluation (110211)Creative shots hair & makeup evaluation (110211)
Creative shots hair & makeup evaluation (110211)iamkim
 
Cat creative marching guidelines
Cat   creative marching guidelinesCat   creative marching guidelines
Cat creative marching guidelinesiamkim
 
Reminders
RemindersReminders
Remindersiamkim
 

More from iamkim (20)

Nat Sci - Minerals
Nat Sci - MineralsNat Sci - Minerals
Nat Sci - Minerals
 
Batch 2012 schedule of exit interview
Batch 2012 schedule of exit interviewBatch 2012 schedule of exit interview
Batch 2012 schedule of exit interview
 
College test results b2012
College test results b2012College test results b2012
College test results b2012
 
Chem cations
Chem   cationsChem   cations
Chem cations
 
Chem anions
Chem   anionsChem   anions
Chem anions
 
Grad ball collections per section(01 28-12)
Grad ball collections per section(01 28-12)Grad ball collections per section(01 28-12)
Grad ball collections per section(01 28-12)
 
Congratulations to batch 2012 star scholar candidates
Congratulations to batch 2012 star scholar candidatesCongratulations to batch 2012 star scholar candidates
Congratulations to batch 2012 star scholar candidates
 
Retreat consent form
Retreat consent formRetreat consent form
Retreat consent form
 
Retreat agreements
Retreat agreementsRetreat agreements
Retreat agreements
 
Fil la loba negra
Fil   la loba negraFil   la loba negra
Fil la loba negra
 
Fil fray botod
Fil   fray botodFil   fray botod
Fil fray botod
 
Dasalan at tocsohan
Dasalan at tocsohanDasalan at tocsohan
Dasalan at tocsohan
 
Chem ps electrolysis
Chem   ps electrolysisChem   ps electrolysis
Chem ps electrolysis
 
Physics waves
Physics   wavesPhysics   waves
Physics waves
 
Math 3 hw ps2
Math   3 hw ps2Math   3 hw ps2
Math 3 hw ps2
 
Memo circular # 4 dtd nov 4, 2011
Memo circular # 4 dtd nov 4, 2011Memo circular # 4 dtd nov 4, 2011
Memo circular # 4 dtd nov 4, 2011
 
Final creative shots hair & makeup evaluation (110211)
Final creative shots hair & makeup evaluation (110211)Final creative shots hair & makeup evaluation (110211)
Final creative shots hair & makeup evaluation (110211)
 
Creative shots hair & makeup evaluation (110211)
Creative shots hair & makeup evaluation (110211)Creative shots hair & makeup evaluation (110211)
Creative shots hair & makeup evaluation (110211)
 
Cat creative marching guidelines
Cat   creative marching guidelinesCat   creative marching guidelines
Cat creative marching guidelines
 
Reminders
RemindersReminders
Reminders
 

Cs hangman

  • 1. CS3 Project - HANGMAN Objective: r Create a Hangman console game o Create a console application that allows the user to add/delete words to be used in the game Deadline: r Second week of January 2011 (first meeting of the week) Other details: o Lab pairings will be in effect. o I will give you the entire 1" week of January to do this but you might want to start during the brea k o There will be 2 modules so you can work independently at the start then combine the modules at the end or work on both modules together. o The emphasis will be handling inputs through console and external file a-s well as proper error handling. o For any questions, email me at: paolo.santos@pshs.edu.ph or paolo.niccolo.santos@gmail.com lnstructions: 1. Create a menu that displays: 1. Manage Word Library 2. Play Hdngman J. tlx] f, >l 2. When L is selected, the user is directed to module 1 (See next page). 3. When 2 is selected, the user is directed to module 2 (See page 3). 4. Selecting 3 ends the program.
  • 2. Module 1: Creating the Word Library (File Reading/Writing Module) L. Start by manually creating a text file containing the default list of words (each word separated by a new line). Name it wordlist.txt. The file should look like this: Merry Christmas Rudolph the red nosed reindeer 2. At the start of the module, load all the words into an array of Strings 3. Then, display the following menu: 1. Display word library 2. Add a word 3. Delete a word 4. Save current list 5. Exit 4. When f. is selected, print the entire array of words. 5. When 2 is selected, prompt the user for a word then add it to the array. 6. When 3 is selected, print the entire array of words in this manner: I. Merry 2. Christmas 3. Rudolph the red nosed reindeer Then prompt the user for a NIJMBER. Delete the word that corresponds to that number (example if the user enters 1, delete Merry from the array). 7. When 4 is selected, save the words contained in the array to wordlist.txt 8. When 5 is selected, return the user to the previous menu.
  • 3. Module 2: Creating the game (Console Inputs Module) 1. You will need the file HangmanWord.java (located at the end of this document) for this module. 2. Start with an arrav of words and use the random class to generate a random number to randomly pick a word from the list. 3. Once a word is selected, you now need to transform it into a HangmanWord a. To create a HangmanWord, simply input the String into the constructor: new HangmanWord(<String value>); b. How to use a HangmanWord Object: i. When the object is created, it automatically geneterates a String that contains the blanks of the word. Meaning if you entered new HangmanWord("hello"), it generates " ". ---- ii. To output the String of blanks, use the outputBlanksfl function. iii. You can use the use the guess(char letter)or guess(String letter)function to guess a letter that is contained in the word. lt outputs true if the letter is contained in the word, false otherwise. lt is CASE SENSITIVE. lf the letter is . contained in the word, the blank is replaced by the letter. iv. Calling the isGuessed0 function returns true if the word is successfully guessed, and false otherwise. 4. OnCe yOu've made your hangman wOrd, set hOw many "lives" your user has tO guess the word. 5. Output the blanks (example the word is snowman) 6. Prompt the user for an input (either String or char) >s 7. Use the guessfl function of the HangmanWord o.bject a. lf it returns true, output the blanks b. lf it returns false, subtract a "life" from the user then output the blanks c. lf the word is fully guessed (no more blanks)go back to 1. d. lf the user is out of lives, output the word then go back to the main menu. ' e, lf the user is not out of lives and the word still contains blanks, go back to 5.
  • 4. public cfass Hanqmanword { private String inword; nriv,atc Strino outword; nri vafe i nt I etters I eft; nrrl.rlin llanam:nfaTnrd/af Vvgl4rrY rina r^rnrrl t inword : word; outword : ""; Ietters feft : 0; for(int i:0; i < word.IengthO; i++;1 1f((word.charAt(i):: ' ') I | (word.charAt(i):= '. ', I I (word.charAt(i):: ', ') | I (word.charAt(i):: 'e'1 | t (word.charAt(i)::'l') | I (word.charAt(i):: "") | l (word.charAt (i)::'" )){ outword : outv/ord + word.charAt(i) ; ) else { outword : outword ; Ietters_left++; ) ] ) public boofean giress (char letLer) { boofean hasletter : false; for(int i = 0; i < inword.lengtho; i++11 if ( (lnword. charAt (i) := letter) && (outword. charAt (i) :: '_') )i outhrord: outword.substring(0,i) + fetter + outword. substri-ng ( i+1, outword. lenqth ( ) ) ; L--T * +vr,^. IIOJ!V ^tt^, LgI L letters_left--; ] . return has{.etter; t t pub-Iic boo}ean guess (St ring letter ) { if(letter.lengthO != 1) t SysLem.out.println ("lnvalid guess. ") ; return false; ] boolean hasLetter : false; for(int i:0; i < inword.lengthO; i++11 if ( (Ietter.equals (inword.substring(i, i+1) ) ) && ("_".equals (outword. substring (i,i+t1 ; I 1 1 outword : outword. substring (0, i) + fetter + outword. substring (i+1, outword. length ( ) ) ; hasLetter : true; fetters_left--;
  • 5. / - return hasLetter; ) public void seLWorl (String word) { inword : word; outword : ""; letters_left : O; for(int i = 0; i < word.lengthO; i++11 if((word.charAt(i):= ' ') ll (word.charAt-(i)::'.') ll (word.charAt(i):= ', ', I I (word.charAt(i):: '?') i i (word.charAt(i):= ttt; ll (word.charAt(i):: "'t, 1l (word'charAt (i)::' " ) ) { outword: outword + word.charAt(i) ; l else 1 outword : outword + "_" ; f ette rs_le ft ++; l I ) n'ht in qts,,n^ ^rll-^ufBlanks() { String out : tr tt - for(int i:0; i < outworcl.lengthO; i++;1 our : our + outword. charAt (i) + rr II' ) return out. trin ( ) ; ) public boolean isGuessedO { return (letters left- :: 0); l 5