* Dynamic Memoy *Big O Notation*Stacks *Exteme Pogamming*Selection Sot*Insetion Sot*Watefall Model Sting*Aays*AayList*Client Seve*Atificial Intelligence*Inheitance*Files*Video Games*Shot cicuit evaluation* Assignment 0/0 2 /0 8 /0 16 Vesion: 3.2a Last Updated: 9/20/2017 10:29 PM Binay Ones Comp Twos Comp Summe Assignment Welcome to the AP Compute Science Pogam! This is a challenging and fun couse as we delve deepe into compute science. Attached you will find summe assignments to be completed by the fist day of school next yea. 1
The two aticles ae fom the Oacle page and they descibe the basic concepts of classes and objects. Hee ae the URL s http://java.sun.com/docs/books/tutoial/java/concepts/object.html http://java.sun.com/docs/books/tutoial/java/concepts/class.html 1. Pepae a 6-8 slide powepoint pesentation o google slides on the aticles descibing the diffeences. If necessay, use the intenet and compute books to exploe the diffeences between classes and objects, etc. The following pogams can be ceated using eithe the console o Swing. 2. Wite a pogam that takes as inputs the lengths of thee sides of a tiangle and displays; fist, whethe o not the 3 values epesent a tiangle and then whethe the tiangle is scalene, isosceles, o equilateal. Useful facts: In a tiangle, the longest side must be less than the sum of the othe two sides. A scalene tiangle has all sides unequal. An isosceles tiangle has two sides equal. An equilateal tiangle has all sides equal. HINTS fo Testing: When testing, make sue you test with all sides the same and you pogam doesn t epot the tiangle to be both isosceles and equilateal. 2
3. DO NOT USE Math.andom() fo this assignment!!!! This assignment needs to have a andom numbe geneato using the java.util.random class I will be using a seed to test this. Only geneate numbes when you ae using them to oll dice. See below fo the esults expected given a seed of 10! In the game of caps, a playe olls 2 six sided dice and adds up the sum. The fist oll is special; a playe can eithe win o lose instantly on the fist oll. DO NOT USE nextint(11) + 2; THIS DOES NOT SIMULATE PROBABILITY AND THE LIKELYHOOD OF 7 COMING UP MOST OFTEN!!! If the fist oll is a 7 o 11, INSTANT WINNER. The ound is ove. If a playe olls a 2, 3 o 12, INSTANT LOSER. If none of the above ae olled, the playe goes into a phase whee they continually oll 2 dice until one of two things happens; 1) the playe olls the intial numbe (known as the point) the playe WINS 2) the playe olls a 7, the playe LOSES. Examples of dice oll sequences and esults i. Roll a 7 on fist oll -> WIN ii. Roll an 11 on fist oll -> WIN iii. Roll a 2 on fist oll ->LOSE iv. Roll a 3 on fist oll -> LOSE v. Roll a 12 on fist oll -> LOSE vi. Roll a 5, 9, 12, 6 and then a 5 to win since you eolled the point vii. Roll a 5, 9, 12, 6 and then a 7 to lose since you olled a 7 when attempting to eoll the point viii. Roll 8, 2, 3, 11, 12, 9, 3, 3, 5, 9, 10, 8 to win since you eolled the point Make a caps game in the console o Swing that stats the playe out with 100 chips(o cookies o pape clips, bid eggs, whateve) 3
Befoe each game, the use is asked to make a wage (by default, just wage 10%) Then allow the use to play the game by olling the dice. Use the space ba o key o something to allow them to see each oll. Afte the game is won o lost, subtact o add chips and then display them to the sceen. If the use is out of chips, then Sample Results fo Seed 10 fom Alex Heman (2017) Poject un: You have 100 chips. How many do you want to bet? 1 Type '' to oll the dice. You olled a 5 Type '' to oll the dice again. You olled a 5 YOU WON!!!! You got 1 chips. $$$$$$$$$$$$$$$$ WINNER $$$$$$$$$$$$$$$$$$$ You have 101 chips. How many do you want to bet? 2 Type '' to oll the dice. You olled a 10 Type '' to oll the dice again. You olled a 7 You capped out and lost 2 chips. ================LOSER====================== You have 99 chips. How many do you want to bet? 2 Type '' to oll the dice. You olled a 9 Type '' to oll the dice again. 4
You olled a 8 Type '' to oll the dice again. You olled a 5 Type '' to oll the dice again. You olled a 5 Type '' to oll the dice again. You olled a 7 You capped out and lost 2 chips. ================LOSER====================== You have 97 chips. How many do you want to bet? 3 Type '' to oll the dice. You olled a 7 YOU WON!!!! You got 3 chips. $$$$$$$$$$$$$$$$ WINNER $$$$$$$$$$$$$$$$$$$ You have 100 chips. How many do you want to bet? 2 Type '' to oll the dice. You olled a 8 Type '' to oll the dice again. You olled a 7 You capped out and lost 2 chips. ================LOSER====================== You have 98 chips. How many do you want to bet? 2 Type '' to oll the dice. You olled a 8 Type '' to oll the dice again. You olled a 6 Type '' to oll the dice again. You olled a 6 5
Type '' to oll the dice again. You olled a 6 Type '' to oll the dice again. You olled a 4 Type '' to oll the dice again. You olled a 4 Type '' to oll the dice again. You olled a 10 Type '' to oll the dice again. You olled a 6 Type '' to oll the dice again. You olled a 8 YOU WON!!!! You got 2 chips. $$$$$$$$$$$$$$$$ WINNER $$$$$$$$$$$$$$$$$$$ You have 100 chips. How many do you want to bet? 10 Type '' to oll the dice. You olled a 4 Type '' to oll the dice again. You olled a 11 Type '' to oll the dice again. You olled a 2 Type '' to oll the dice again. You olled a 8 Type '' to oll the dice again. You olled a 12 Type '' to oll the dice again. You olled a 10 6
Type '' to oll the dice again. You olled a 12 Type '' to oll the dice again. You olled a 4 YOU WON!!!! You got 10 chips. $$$$$$$$$$$$$$$$ WINNER $$$$$$$$$$$$$$$$$$$ You have 110 chips. How many do you want to bet? 3 Type '' to oll the dice. You olled a 4 Type '' to oll the dice again. You olled a 4 YOU WON!!!! You got 3 chips. $$$$$$$$$$$$$$$$ WINNER $$$$$$$$$$$$$$$$$$$ HINTS fo Testing: If you seed the Random numbe geneato object, then you will get the same sequence of pseudo andom numbes each un of the pogam. Fo example, Random = new Random(100); will cause all calls to.nextint(n); to give the same sequence. This helps you find the epeated case you ae looking fo without testing foeve. Be sue you ve coveed all cases. NOTE: Console pogammes will be witing a loop while Swing uses will have to keep tack of whethe it is a eoll o initial oll. Swing utilizes its own loop to keep checking fo any events that might occu and epot those events to the pogam handles. Theefoe, although thee is a loop, it has been ceated by the authos of the Swing GUI developes. To deal with this, use a global vaiable inside you Fame to detemine if the next oll is an initial oll o eoll. Fo example, public CapsFame extends javax.swing.jfame{ boolean fistroll = tue; } 7
This vaiable can be used to infom the actionpefomed method inside the CapsFame when a oll is a fist oll and when it is a eoll. Just flip the boolean vaiable. NOTE: Swing GUI s MUST BE ABLE to show the sequence of olls fo ease of testing. To do this, use a JTextAea that can show 6 ows of numbes. Each oll can be appended to the JTextAea so I can see the sequence of olls. 4. A pefect numbe is a positive intege such that the sum of the divisos equals the numbe. Thus, 28 = 1 + 2 + 4 + 7 + 14 is a pefect numbe. If the sum of the divisos is less than the numbe, it is deficient. If the sum exceeds the numbe, it is abundant. Wite a pogam that takes a positive intege as input and displays a message box that indicates whethe the numbe enteed is pefect, deficient, o abundant. You pogam should define the following thee methods: NOTE: MAKE SURE YOU HAVE ALL METHODS AND PARAMETERS, YOU WILL NOT RECEIVE FULL CREDIT UNLESS YOU STRUCTURE YOUR PROGRAM AS YOU SEE BELOW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! main boolean isdiviso (int num, int diviso) int divisosum (int numbe) The method isdiviso etuns tue if the diviso paamete is a diviso ofthe numbe paamete, and false othewise. The divisosum method uses isdiviso to accumulate and etun the sum of the pope divisos of the numbe paamete. Be sue to design and test the pogam incementally, that is, veify that isdiviso woks coectly befoe using it in divisosum. Fom a console pogam, the thee methods might look like this; /* pompts the use fo a numbe and then epots whethe the numbe is pefect, 8
deficient o abundant, calls the divisosum method to find the numbe of pope divisos fo any numbe*/ public static void main(sting[] ags) { //How do you call divisosum fom hee? // int sum = divisosum(num); //calls method and stoes etun value in sum } /* takes in an intege and calls isdiviso in a loop to detemine whethe o not each possible diviso evenly divides the numbe*/ public static int divisosum (int numbe) } /* takes in an two integes, etuns tue if the second is a diviso of the fist*/ public static boolean isdiviso (int num, int diviso) { } public static void main() Gathe input fom use Call divisosum to find out sum of pope divisos 15 9 public static int divisosum(int num) Loops though possible candidates, calls isdiviso to see if each potential diviso is actually a diviso LOOP MULTIPLE TIMES TO CALL isdiv 15,2 false public static boolean isdiviso(int num, int div) etuns tue o false depending upon the elationship between num and div 9
5. A standad expeiment is to dop a ball to see how high it bounces. Once the "bounciness" of the ball is detemined, the atio gives a bounciness index. Fo example, if a ball dopped fom a height of 10 feet bounces 6 feet high, the index is 0.6 and the total distance taveled by the ball is 16 feet afte one bounce. If the ball continues bouncing, the distance afte two bounces would be 10 + 6 + 6+ 3.6 = 25.6 feet. Note that the distance taveled fo each bounce is the distance to the floo plus 0.6 of that distance as the ball comes back up. The ball, theefoe, hoves in the ai. Wite a pogam that takes as inputs the initial height of the ball (in feet), the index of the ball's bounciness, and the numbe of times the ball is allowed to continue bouncing. The pogam should output the total distance taveled by the ball. At some point in the pocess, the distance taveled by the ball afte a bounce might become negligible, fo example, less than 0.001 feet. If that stage is eached, teminate the pocess and output the total distance. (This could happen if fo example, we attempted to dop a ball fo 10,000 bounces). Hee ae un-thoughs that will be helpful to you. Fo Chis Du, Rahul Shah and Jason Cantebuy!!!! 10
Case # Initial Height Bounciness Bounces Distance Beakdown 1 50.4 5 115.472 see below 2 10.8 3 43.92 see below 3 1.2 8 1.4992 only 4 and a half bounces Make sue theshold set to.001 fo case 3!!! EXAMPLE 1 What Height to Stat? 50 Index of Bounce?(.1->.9.4 How many bounces? 5 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Down:50.0 Up: 20.0 Down:20.0 Up: 8.0 Down:8.0 Up: 3.2 Down:3.2 Up: 1.2800000000000002 Down:1.2800000000000002 Up: 0.5120000000000001 11
115.47200000000001 EXAMPLE 2 What Height to Stat? 10 Index of Bounce?(.1->.9).8 How many bounces? 3 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Down:10.0 Up: 8.0 Down:8.0 Up: 6.4 Down:6.4 Up: 5.120000000000001 43.92 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ EXAMPLE 3 What Height to Stat? 1 Index of Bounce?(.1->.9).2 12
How many bounces? 8 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Down:1.0 Up: 0.2 Down:0.2 Up: 0.04000000000000001 Down:0.04000000000000001 Up: 0.008000000000000002 Down:0.008000000000000002 Up: 0.0016000000000000005 Down:0.0016000000000000005 Up: 3.2000000000000013E-4 Since up is less than 0.001 we outta hee! 1.4992 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@ 13
6. Ceate an account on the codingbat.com web site. This site allows you to type in the bodies of methods and see if they ae coect online. Shae you account out to mhanleyc@hotmail.c om unde the pefs fo codingbat. You fist and last name in the pefeences must be you actual fist and last name so I don t have to guess who is who. Complete the following codingbat poblems; Complete the following Wamup 1 poblems and save them on codingbat so I can veify, comments helpful but not equied i. sleepin, monkeytouble, sumdouble, diff21, paottouble, makes10, icyhot, in1020, hasten, loneteen, intmax, close10, in3050, max1020, lastdigit Complete ALL the Logic 1 poblems (THERE ARE 30 HERE!!!!) Complete ALL the Logic 2 poblems (THERE ARE 9 HERE!!!!) You can do it, don t copy the answes fom the web, stuggle though and email me if you ae having gande toubles, hanlchi@shenet.og 14
Poject Name Class 1 Name Class 2 Name Class 3 Name Class 4 Name Summe Assignment TiangleCalculato PefectNumbeFinde Caps BounceCalculato Rubic TiangleCalculato 25 PefectNumbeFinde 25 Caps 25 Bounciness Simulation 25 Powepoint on Object oiented 30 pogamming Comments 10 CodingBat Poblems 100 TOTAL 240 15