Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
lab 14 Lab 14 I frequently change the lab assignment just before class starts (and sometimes during class).   Try not to download the assignment until after class. Please read https://www.plagiarism.org/article/what-is-plagiarism. Code may be copied from the lecture notes or from web pages or from books     Copied code MUST include a citation (e.g. URL of the web page where the code is copied from)     Code that is copied and then modified MUST include a citation (e.g. URL of the web page where the original code was copied from)     Code copied from the lecture notes are not required to have a citation. You may NOT copy answers from another student. You may NOT allow another student to copy your answers. You may NOT turn in a team solution (e.g. 2 or more people work on the lab together and turn in multiple copies of the same lab). Help is available by:    READING THE LECTURE NOTES!    USING THE UML-LIKE DIAGRAMS!    Put a System.out.println statement immediately below any line that creates a variable, changes a variable, or uses a variable         Example:  System.out.println("myVariable = " + myVariable)    coming to a lab session (available only for in-person or zoom classes)    visiting the Magic Lab (https://www.mjc.edu/instruction/bbss/magic.php)    using Google or YouTube    sending me an e-mail    posting a note on the Canvas Q/A Discussion Board and hope that a student will write a response    sometimes a FREE tutor is available from the Library and Learning Center    join a study group OR gather up some folks and start your own study group The following cheat sheet might be useful. Please do homework 14 before you start on this lab. I strongly recommend you answer each and every question in homework 14. I strongly recommend you type each and every answer into Game.java to verify the correctness of your answer. Write the code to play concentration. Your code should display 2 or more rows of cards. Each row should display 4 or more cards. You will need to use pairs of matching cards.  For example, you might want to use 2 ace of hearts, 2 king of hearts, 2 queen of hearts, and 2 jack of hearts. Here is an algorithm that you may find useful: When the game launches:      create an array of Sprites.  Each sprite holds one card.      let concentration =            new Concentration object that contains our sprites     let timeDelay = 0 Every 1/16 second:      paint all the cards in concentration      pause the game until timeDelay ticks down to 0      tell concentration to flip up any card that the human clicked on      ask concentration how many cards are flipped up       if 2 cards are NOT flipped up            return      if user clicked the mouse           let timeDelay = 30           return      tell concentration          if the 2 face-up cards match              remove them      tell concentration to flip all face-up cards face down   Here are some UML-like diagrams: Concentration   Concentration(Sprite sprites[]) void ifMouseIsClickedOnCardThenFlipCardFaceUp() int numberOfFaceUpCards() boolean doAllFaceUpCardsMatch() void flipAllCardsFaceDown() void makeAllFaceUpCardsInvisible() void resetAllCards() int numberOfFaceDownCards() int numberOfVisibleCards() void paintComponent(Graphics g) Sprite Image image int x int y int width    //read only int height   //read only boolean visible Sprite(Image image, int x, int y)     NOTE:  Image image = new ImageIcon("cat.gif").getImage()   boolean intersects(Sprite sprite) void paintComponent(Graphics g) boolean contains(int pointX, int pointY) Game GameBoard gameboard void initializeSprites() int gameboard.getWidth() int gameboard.getHeight() boolean isUpArrowPressed() boolean isDownArrowPressed() boolean isLeftArrowPressed() boolean isRightArrowPressed() boolean isSpaceKeyPressed() int getMouseX() int getMouseY() boolean isMouseClicked() int randomNumber(int minNumber, int maxNumber) GameBoard   int getWidth() int getHeight() Here are steps for getting your development environment set up. step 1:  download Game.zip step 2:  right click Game.zip and select "Extract All" step 3:  open a text editor step 4:  use your text editor to open Game.java step 5:  find the code that looks like this:              public void paintFrame(Graphics g) {                  /* Type your code here */              } step 5:  double click Concentration.txt step 6:  select the entire contents of Concentration.txt step 7:  paste the contents to Game.java at the indicated position; make sure you paste the code below the closing brace }.              public void paintFrame(Graphics g) {                  /* Type your code here */              }              //paste the contents of Concentration.txt here.  Make sure you are BELOW the closing brace }. step 8:  download imagesOfCards.zip step 9:  right click imagesOfCards.zip and select "Extract All" step 10:  copy all of the extracted images into the same folder that contains Game.java step 11:  write your code in Game.java step 12:  save your changes step 13:  launch a cmd console step 14:  cd to the same folder where Game.java is located step 15:  set PATH=[location of java's bin folder];%PATH% step 16:  javac Game.java step 17:  java Game Requirements: When the game is launched:     cards are shuffled     cards are displayed face down, in a nice array The user can immediately click on a card to flip it face up     i.e. the user should not have to wait 2 seconds to click on a card The user can not flip up more than 2 cards When the 2nd card is flipped face up, then the game should pause for 2 seconds If the 2 face up cards match, the 2 cards should disappear If the 2 face up cards do not match, the 2 cards should be flipped face down    Problems and Solutions: Problem:  When I paste the Concentration class into Game.java, my code no longer compiles. Solution 1:   Paste the Concentration code immediately BELOW paintFrame's closing brace. Solution 2:   You might have picked up some invisible characters from your web browser.  Right click the hyperlink for Concentraction.txt and save as a file.  Then use Notepad to open the file.  Copy the code from Notepad and paste it into Game.java. Problem:  I don't see any cards Solution 1:  Download and unzip imagesOfCards.zip.  Then copy the images into the Game folder. Solution 2:  Write the code to render the Sprite of a cat onto the screen.  Then modify the code to render the Sprite of a card onto the screen. Problem:  I don't know how to make an array Solution 1:  READ THE LECUTRE NOTES!!!                    OR                    Use Google to find web pages and/or video clips (the lecture notes will get you an answer much quicker) If you encounter coding errors, then do this:     Repeat until all errors are fixed         Find the first error (the error at the very top of the list of errors)         Fix ONLY the first error.  Do NOT fix any other errors.         Try running the code Get a screenshot of the screen while the code is running.  The screenshot should have 2 or more cards visible. Crop the screenshot. There is no need to write a test plan. CHECK YOUR CANVAS SUBMISSION!!!!   insert a blank USB drive into your computer    log on to Canvas    go to the lab assignment    download your submitted files    put your downloaded submitted files onto your USB flash drive    Folks, who are using Netbeans, should launch Netbeans, open the NetBeans project that is on the USB flash drive, and run the code.    Folks, who are using the command line, should launch command console, go to the USB flash drive, compile their .java file, and run their .java file See How To Avoid The Potholes When Submitting a Lab for additional information. To grade this lab, I will compile and run your code.     If no code is turned in, then I won't be able to grade this lab.     If the code doesn't compile, then I won't be able to grade this lab.     If the code doesn't run, then I won't be able to grade this lab.     If any test, which is marked as passed, fails, then I will assign a grade of 0 to this lab. For folks who need help to get started: Download a fresh copy of Game.java Write code to render a cat on the screen.  Compile and run the code to make sure the cat appears.  If anything goes wrong, fix it. Download imagesOfCards.zip.  Unzip the file into the same folder that contains images of cats and bananas. Change the code.  Instead of rendering a cat.gif or cat.png, try rendering hq.gif or some other card. Compile and run the code to make sure a card appears.  If anything goes wrong, fix it. Download concentration.txt.  Copy and paste the code from concentration.txt into Game.java. To make sure the code is pasted in the correct place, try compiling Game.java.  If an error message appears, try moving the pasted code to a different place. Look through the lecture notes and find the code that creates an array of cards and that places the array in a new Concentration object.     Declare a concentration object in the space for declaring variables.     Define the concentration object in the space for initializing variables.  Here is where the Concentration's constructor is called. Try compiling Game.java.  If an error message appears, fix the code. Look at Concentration's UML-like diagram.  Find a way to render the Concentration object onto the screen. Inside of paintFrame(), render the Concentration object.. Try compiling and running the code to make sure several cards appear on the screen.  If anything goes wrong, fix it. Look at Concentration's UML-like diagram.  Find a find a way to flip a card up when  the mouse is clicked on a card. Try compiling and running the code.  When a card is clicked on, the card should flip face up.  If anything goes wrong, fix it. Try clicking on a second card.  The card should flip face up.  If anythinsg goes wrong fix it. Look at Concentration's UML-like diagram.  Find a find a way to count of the number of face-up cards.  Change the code. Write the number of cards to either the console or the screen. Try compiling and running the code.  Click on some cards.  The correct number of cards should be displayed.  If anything goes wrong, fix it. Change the code.  When 2 cards are face up; write the message "2 cards are face up." Try compiling and running the code.     Click on a card.  The message "2 cards are face up" should NOT appear.     Click on a second card.  The message "2 cards are face up" should appear.     Click on a third card.  The message "2 cards are face" should NOT appear.     If anything goes wrong, fix it. Look at Concentration's UML-like diagram.  Find a way to figure out a way to determine if the 2 face up cards match. Change the code.      When 2 cards are face up and if the 2 cards match, write the message "2 face up cards match."     When 2 cards are face up and if the 2 cards do NOT match, write the messages "2 face up cards do NOT match." Try compiling and running the code.     Click on a card.  We should NOT see either "2 face up cards match" nor "2 face up cards do NOT match."     Click on a second card.          If the 2 cards match, we should see "2 face up cards match"         If the 2 cards do NOT match, we should see "2 face up cards do NOT match."     Click on a third card.  We should NOT see either "2 face up cards match" nor "2 face up cards do NOT match."     If anything goes wrong, fix it. Look at Concentration's UML-like diagram.  Find a way to figure out a way to make the 2 cards disappear. Look at Concentration's UML-like diagram.  Find a way to figure out a way to make the 2 cards flip face down. Change the code.     When 2 cards are face up and if the 2 cards match, make the 2 cards disappear.     When 2 cards are face up and if the 2 cards do NOT match, flip the 2 cards face down. Try compiling and running the code.     Click on a card.  We should NOT see either "2 face up cards match" nor "2 face up cards do NOT match."     Click on a second card.          If the 2 cards match, the 2 cards should disappear.         If the 2 cards do NOT match, the 2 cards should flip face down.     If anything goes wrong, fix it. Change the code.   Add a 2-second time delay when a 2nd card is flipped up.    Here is how I grade this lab: 8 points:  display 2 or more rows and 4 or more columns of cards 1 point" if wait for 3 seconds, nothing happens 1 points: can click on a card to flip it face up 1 point: did NOT have to wait 2 seconds to flip up the 2nd card 1 point:  can click on a 2nd card to flip it face up 2 points: can not flip up a third card 1 point: game is paused for 2 seconds 2 point: if 2 cards match, they disappear 2 point: if 2 cards don't match, they are flipped down 1 point: can continue playing the game by clicking on a card   Folks who need a working Java development environment, can read this:  How to install and use Java on the command line.  This is the quickest, easiest, and most fool-proof way to set up a Java development environment. Deliverables: .java file or a zip file of your project folder To avoid Canvas breaking your Java application by changing the names of your .java files, insert your .java files into a zip file. screenshot There is no test plan for this lab You may, if you want to, turn in one zip file that contains all the files.  Do NOT use 7z nor rar nor tar nor tar.gz. I STRONGLY recommend checking your Canvas submission:     insert a blank USB flash drive into your computer     launch Canvas     download your uploaded file(s) onto the USB flash drive     run your uploaded java file and verify the output looks ok     see How To Avoid The Potholes When Submitting a Lab for additional information