Please read the entire PDF before starting. You must do this assignment individually.It is very important that you follow the directions as closely as possible. The directions, whileperhaps tedious, are designed to make it as easy as possible for the TAs to mark the assignments by lettingthem run your assignment, in some cases through automated tests. While these tests will never be used todetermine your entire grade, they speed up the process significantly, which allows the TAs to provide betterfeedback and not waste time on administrative details. Plus, if the TA is in a good mood while he or she isgrading, then that increases the chance of them giving out partial marks. :)Up to 30% can be removed for bad indentation of your code as well as omitting comments, coding structure, ormissing files. Marks will be removed as well if the class and method names are not spelled and capitalizedexactly as described in this document.To get full marks, you must:• Follow all directions below• Make sure that your code compiles– Non-compiling code will receive a very low mark• Write your name and student ID as a comment in all .java files you hand in• Indent your code properly• Name your variables appropriately– The purpose of each variable should be obvious from the name• Comment your work– A comment every line is not needed, but there should be enough comments to fully understandyour program1Part 1 (0 points): Warm-upDo NOT submit this part, as it will not be graded. However, doing these exercises might help you to do thesecond part of the assignment, which will be graded. If you have diculties with the questions of Part 1, thenwe suggest that you consult the TAs during their oce hours; they can help you and work with you throughthe warm-up questions. You are responsible for knowing all of the material in these questions.Warm-up Question 1 (0 points)Write a method swap which takes as input two int values x and y. Your method should do 3 things:1. Print the value of x and y2. Swap the values of the variables x and y, so that whatever was in x is now in y and whatever wasin y is now in x3. Print the value of x and y again.For example, if your method is called as follows: swap(3,4) the e↵ect of calling your method should bethe following printinginside swap: x is:3 y is:4inside swap: x is:4 y is:3Warm-up Question 2 (0 points)Consider the program you have just written. Create two integer variables in the main method. Callthem x and y. Assign values to them and call the swap method you wrote in the previous part using xand y as input parameters.After calling the swap() method—inside the main method— print the values of x and y. Are theydi↵erent than before? Why or why not?Warm-up Question 3 (0 points)Write a method that takes three integers x, y, and z as input. This method returns true if z is equal to3 or if z is equal to the sum of x and y, and false otherwise.Warm-up Question 4 (0 points)Let’s write a method incrementally:1. Start by writing a method called getRandomNumber that takes no inputs, and returns a randomdouble between 0 (included) and 10 (excluded).2. Now, modify it so that it returns a random int between 0 and 10 (still excluded).3. Finally, let the method take two integers min and max as inputs, and return a random integergreater than or equal to min and less than max.Warm-up Question 5 (0 points)Create a file called Counting.java, and in this file, declare a class called Counting. This program takesas input from the user (using args) a positive integer and counts up until that number. eg:> run Counting 10I am counting until 10: 1 2 3 4 5 6 7 8 9 10Warm-up Question 6 (0 points)For this question you have to generalize the last question. The user will give you the number they wantthe computer to count up to and the step size by which it will do so.> run Counting 25 3I am counting to 25 with a step size of 3:1 4 7 10 13 16 19 22 25Page 2Warm-up Question 7 (0 points)This program prints the outline of a square made up of * signs. It should take as input the length ofthe sides in number of *’s. This program should use only two for loops, and use if statements within thefor loops to decide whether to draw a space or a star. Draw the outline of a square as follows.⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤⇤N.B. It is normal that the square does not appear to be a perfect square on screen as the width and thelength of the characters are not equal.How do you generalize the program in order to print a rectangle where both the base and the height aregiven as input?Page 3Part 2The question in this part of the assignment will be graded.Question 1: Craps (50 points)Craps is a dice game where each player bets on the outcome of the dice rolls. The goal of this question isto write several methods in order to create a program that simulates the outcome of a Pass Line Bet (seebelow) in a game of Craps. All the code for this question must be placed in a file named Gambling.java.The Pass Line BetCraps is a game of rounds. The first dice roll of a round is called the Come-out Roll. When a playeris making a Pass Line Bet, they will place a bet before the Come-Out Roll. Depending on the result ofthe roll, the player might win, lose, or go to the “next stage” of the game:• If a 7 or an 11 is rolled, then the player wins.• If a 2, 3, or 12 is rolled, then the player loses.• If any other number is rolled, the player must go to the next stage.For the next stage, it is important to remember which number was rolled in the Come-Out Roll, thisnumber is called the point. In the second stage, the player will keep rolling the dice until one of thefollowing happens:• A 7 is rolled, and the player loses the bet• The point is rolled again, and the player wins the betThe payout is 1:1: the players win as much as he bets. Thus, if the player bets $5 and wins he willreceive an additional $5. If he loses, he will lose the entire bet.Let’s see a couple of examples:• The result of the Come-Out Roll is a 3. ! The player loses!• The result of the Come-Out Roll is a 5 ! The dice are rolled again until either a 7 or a 5 is rolled.Supposed that the results of the rolls are the following: 10, 11, 4, 7. ! The player loses!• The result of the Come-Out Roll is a 9 ! The dice are rolled again until either a 7 or a 9 is rolled.Let the results of the rolls be as follow: 3, 5, 9. ! The player wins!Now that we now how the game works, let’s see which methods we need to simulate the result of a PassLine bet in a game of Craps.1a. A method to simulate a dice rollIn a game of Craps, players are betting on the outcome of a roll of two six-sided dice. Write a methodcalled diceRoll that simulates the roll of two six-sided dice. Such method will have to return an intbetween 2 and 12 (included), which is the sum of the result of rolling two six-sided dice. Notice, thatto simulate the roll of two six-sided dice, you will have to generate two random numbers between 1and 6 (both included) and sum the results together. If you have any doubts on how to achieve this,make sure you first understand the warm-up Question 4, where you are asked to build a method calledgetRandomNumbers.Page 41b. A method to simulate the second stage of the betWrite a method secondStage that simulates the second stage of the Pass Line Bet. This method takesas input one integer value that corresponds to the point, the number rolled in the Come-Out Roll (either4, 5, 6, 8, 9, or 10), and returns an int which will either be a 7 or the point itself depending on which onegets rolled first. Let the method print all the dice rolls on the same line until a 7 or the point is rolled.For example, if the method is called with input 5, the following might get printed on your screen:4, 6, 11, 7Make sure to use diceRoll to obtain the value of each roll.1c. A method to check if the player has enough moneyWrite a method canPlay which takes two doubles as input and returns a boolean value. The first inputvalue corresponds to the money the player has, the second corresponds to how much money the playerwould like to bet. A player is allowed to play only if they bet more than $ 0.0, but not more than whatthey own own. If the player is allowed to play, your method should return true. The method shouldreturn false otherwise.For example:• canPlay(5.25, 5) returns true,• canP帮做Java编程作业、Java课程设计代写留学生、代写留学生Java语言、Java作业代做留学生lay(0.0, 2.0) returns false, and• canPlay(5.0, -3.0) returns false.1d. A method to simulate the Pass Line BetFinally, write a method passLineBet that simulates what happens when a Pass Line Bet is placed. Thismethods takes two doubles as input: the first one corresponds the total amount of money the player has,the second correspond to how much money the players decides to bet. The method will return a valueof type double which corresponds to the amount of money the player has left after one round of Craps.The method should first check if the player is allowed to play using canPlay. If the player is not allowedto play, your method should print out a statement informing the player he has insucient funds to placethe bet and simply return the amount of money the player has at the moment. If the player is allowedto play, then you can go ahead and simulate 1 round of Craps.Your method should print the result of the Come-Out Roll (the first roll in a round of Craps) as wellas what will happen next. For example, here is the player in the first stage of the game, the Come-OutRoll. Recall that the player wins with a 7 or 11, loses with a 2, 3, or 12, and moves to the second stagewith any other number. Here are some possible outcomes:• A 7 has been rolled. You win!• A 12 has been rolled. You lose!• A 5 has been rolled. Roll again!If necessary, the second stage needs to be simulated (using the secondStage method) in order to de-termine whether the player wins or loses. If at the end of the second stage a 7 was rolled your methodshould print a statement informing the player he lost, if instead the point was rolled your method shouldprint a statement informing the player he won. Use canPlay, secondStage, and diceRoll in order toPage 5implement the simulation of a Pass Line Bet. Remember to update the amount of money the player hasleft depending on whether he won or lost the bet. This number should be returned as a value of typedouble.1e. Setting up the main method (Optional - No extra marks)Set up the main method so that the program receives two inputs of type double via command line ar-guments. The first input corresponds to the money the player has, the second to the money they wouldlike to bet. From the main method, call passLineBet with the appropriate inputs in order to place thebet. Make sure to output a statement informing the player with how much money he has left after hisbet. These are a couple of examples of how your program should run:> run Gambling 25.5 7.0A 5 has been rolled. Roll again!4, 3, 12, 5You win!You now have: $32.5> run Gambling 5.5 7.0Insufficient funds. You cannot play.You now have: $5.5> run Gambling 10 7.0A 12 has been rolled. You lose!You now have: $3.0Question 2: Monthly Calendar (50 points)For this question, you will write a program that displays the monthly calendar of the month desired bythe user. To do that, you will need to implement all the methods listed below. All the code for thisquestion must be placed in a file named MonthlyCalendar.java.2a. A method to obtain the number of the monthWrite a method called getMonthNumber that takes a String as input containing the name of the month.The method returns the int associated to it (starting from 1 up to 12). If the String does not containa valid name for a month, then the method should return -1. Note that the method should not be casesensitive. For example,• getMonthNumber(&"june&") returns 6• getMonthNumber(&"January&") returns 1• getMonthNumber(&"junes&") returns -1• getMonthNumber(&"JuNe&") returns 6• getMonthNumber(&"cats&") returns -12b. A method that computes the day of the weekWrite a method getDayOfTheWeek that takes three integers as input (representing the day d, monthm and year y, respectively) and returns an int representing the day of the week on which that datePage 6falls. A value of 0 denotes Sunday, 1 denotes Monday, 2 denotes Tuesday, and so forth. You can fairlyassume that the inputs represent a valid date. Regarding the month m, note that 1 represents January,2 February, 3 March, and so on. To compute the day of the week, you must use the following formulas(based on a Gregorian calendar):where mod indicates the modulo operator. Please note that the final result is stored in the variable. For example:• getDayOfWeek(2,8,1953) returns 0 (Sunday).The input represents the date August 2, 1953. The values of the variables described above are:= 0. You can use this values to debug your method in case itis not returning the correct value.• getDayOfWeek(26,12,1893) returns 2 (Tuesday)The input represents the date December 26, 1893. The values of the variables described above are:• getDayOfWeek(1,1,2000) returns 6 (Saturday)The input represents the date January 1, 2000. The values of the variables described above are:2c. A method to check if a year is a leap yearWrite a method isLeapYear which takes one integer as input representing a year. You can assume thatthe input represents a valid year (i.e. it is a positive integer). The method returns true if the year isa leap year, false otherwise. Note that, a year is a leap year if it is divisible by 4, except for centuryyears which must be divisible by 400 in order to be leap. For example 1988, 1992, 2000, 2096 are leapsyear and 1985, 2002, 2100 are not leap.2d. A method that returns the number of days in a monthWrite a method getNumberOfDays which takes two integer as input, one representing a month and theother representing a year, respectively. You can assume that the inputs are valid (i.e. they are bothpositive integers and the one representing the month is greater than or equal to 1 and less than or equalto 12). As already stated above, remember that for the months 1 represents January, 2 February, 3March, and so on. The method returns the number of days in the given month. Remember that themonth of February in a leap year has 29 days. To get full marks your method must call isLeapYear().For example:• getNumberOfDays(4, 2018) returns 30.• getNumberOfDays(2, 1992) returns 29.• getNumberOfDays(1, 1853) returns 31.Page 72e. A method to display the Monthly CalendarFinally, write a method displayMonthlyCalendar that takes as input a String representing a monthand an int representing a year. The method should use getMonthNumber() to retrieve the numberassociated to the month. If the String does not represent a valid month, then the method should printa message stating that there is no such month. Otherwise, the method should go ahead and display themonthly calendar associated to such month and year. Use getDayOfTheWeek() and getNumberOfDays()to figure out on which day of the week the month starts and how many days the month has. Using thisinformation, the method can then display the calendar exactly as shown in the examples below. Notethat each day of the week is separated by 2 tab characters.• displayMonthlyCalendar(&"April&", 2018) should display• displayMonthlyCalendar(&"FEBRUARY&", 1992) should display• displayMonthlyCalendar(&"january&", 1853) should display• displayMonthlyCalendar(&"SApril&", 2018) should displayPage 82f. Setting up the main method (Optional - No extra marks)Set up the main method so that the program receives two inputs: the first one of type String denoting amonth, and the second one of type int indicating a year. You can then call displayMonthlyCalendar()with the appropriate inputs and see the calendar displayed by your method (as in the examples above).What To SubmitPlease put all your files in a folder called Assignment2. Zip the folder (please DO NOT rar it) and submit itin MyCourses. Inside your zipped folder there must be the files listed below. Do not submit any otherfiles, especially .class files.Gambling.javaMonthlyCalendar.javaConfession.txt (optional) In this file, you can tell the TA about any issues you ran into doingthis assignment. If you point out an error that you know occurs in your problem, it may leadthe TA to give you more partial credit. On the other hand, it also may lead the TA to noticesomething that otherwise they would not.Marking SchemeQuestion 1Question 1a: 10 pointsQuestion 1b: 17 pointsQuestion 1c: 5 pointsQuestion 1d: 18 pointsQuestion 2Question 2a: 10 pointsQuestion 2b: 8 pointsQuestion 2c: 5 pointsQuestion 2d: 7 pointsQuestion 2e: 20 points100 points转自:http://ass.3daixie.com/2018052758777183.html
讲解:Java、Java、Java、Java
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...