Author Archives: Mr. M

Final Alice Assignment

This is your “cumulative Assignment”

  • It must tell a story
  • Minimum of 5 objects

 

Programming Requirements

  • Some kind of interactive event (#27) . Something should happen when a mouse is pressed, key is pressed etc

 

10 points of the following

 

  • Loop    (2 points )
  • variable (1 point)
  •  function (1 point)
  • custom object (save to file etc)  2 points

Alice Unit 5

5.1: Exercise Competition:

excercise_competition_emo

Three girls Jenny, Kelly, and Barb are enrolled in an exercise class. One day after class the three decide to have a friendly competition to see how many sets of 10 repetitions of running in place each can do before getting tired. Barb decides to go first and gets tired at 10 repetitions. Kelly goes next and she gets tired at 20 repetitions. Jenny, who has been in the exercise class for the longest, goes next. She gets tired at 30 repetitions.

Create a world that suites the competition.

  • Note: Basically, you are just using a parameter to determine how many times the girl “runsInPlace”
  • Important: Each of the girls should be an instance of ExerciseGirl class that you created in chapter 5.

 

excercise compe


 

EACH Assignment below requires the use of a parameter in some way.  If you do not have a parameter, as described, you will lose a lot of credit.

 

Here is a helpful link on how to create and use parameters, in case you forget.

 


5.2 : Jumping Jacks

jumping-jacks-optimized

Add a jumpingJack method to the ExerciseGirl class. The method should make the object perform jumping jacks .

  • Important: this method should have a parameter for the number of repetitions to perform.

5.3 : Marcello The Magician:

 

Marcello the magician has finally mastered his disappearing act. To perform the act, he places several items on a table in front of him. He stands with his right arm extended over an item. He says the magic word “Alakazam, Alakazee” and the object disappears. He repeats this procedure for each object on the table. Create a world in which Marcello (an instance of the Magician class from the People Collection) demonstrates his new act . In the magician object

  • you should create two new class-level methods:
    • sayMagicWords
      • should cause Marcello to say the magic words.
    • makeDisappear
      • This method should have an object as its parameter
      • should cause Marcello to turn to face the object, say the magic words (by calling the sayMagicWords method) and then make the object disappear by setting its opacity to zero (note: for some reason the bunny object cannot be made to disappear this way!).
  • gigantaicize
    • This method should have an object as its parameter
    • the object should be made to 5 times its original size!
  • Want to get an “A+”: then create a transmute method tha
    • takes an object  parameter
    • Changes a locust to a boar (hide the one , make the other appear)
    • changes a bird to a locust

ALice Loop Assignments

ezgif.com-optimize

1)  Centigrade to Fahrenheit Modification: Modify the Fahrenheit to centigrade project as follows.

  1. Let the user do as many centigrade modifications as you want (like this link here)
  2. Then use a loop to do that many conversions

2) Miles Per Gallon Modification: Modify the miles per gallon projec. In this one, ask the user how many times they want the MPG program to run and use a loop like this. .Due wed/Thurs the 17th/18th

  1. Ask the user how many times, they want to do the MPG and use a loop like this
  2. Then use a loop to do that many conversions

3) Sea Plane Loop-the-Loop : Create a world with a sea plane (from the Vehiclescollection).Create an infinite loop that causes the sea plane to do a circular loop the loop. Adjust the style and duration editing tags to make the animation fast, and as smooth as possible.


EOU)  Open assignment. Your open project must have each of the following criteraDue before Winter vacation

  1. a variable
  2. store the return value of a function into that variable
  3. a loop of some kind

Objects In Java Unit

 

Unit 4  Objects && ArrayList

Unit 5 : Objects Continued

Unit 4** Alice Assignments

Assignment ): Tutorial 4-2 Gum Drop Fish Assignment will be graded (2 points) from packet #13 will be graded.  Download the GumdropBigFish world 

  • gum drop alice

Assignment 1 )   Miles Per Gallon: Create a world in which the

  •  Create 3 variables :  miles, gallons ,MPG  
    •  2 of the variables  store the return value of a function
      • The user is asked for the number of gallons  of fuel his or her car can hold. Use the return value of the ask use for a number function as shown below.screenshot21
      • Do the same thing for the the number of miles  that he or she can drive on a full tank. Use ask a user function to set the value of the miles variable.
  • a third variable called MPG.   This one will store the result of some math and will hold the car’s miles-per-gallon (MPG). Calculate the MPG with the following formulampg (2)
  • At the end , your character should say the value of the   mpg , as shown below.

How to use “what as a string”

what as string 2

 

mpg_brandon

 


Assignment  3) Fahrenheit to Centigrade :

First, watch the animated gifs on this web page that explain how to use math in Alice

 

  • Create a variable called degreesFahrenheit  .
  • Store the return value of the ask_user to enter a number function
    • You should ask them for the degrees in Fahrenheit
  • Create a variable called  degreesCentigrade
  • Use the following formula to convert the degreesFahrenheit   to Centigrade using the following formula
  • use a character from thePeople collection to say the centigrade temperature.
  • Don’t forget that you can’t say numbers, you must use what as a string

 

temp_convert_eric

 

 


 

Assignment 4) Modification of MPG

reopen the miles per gallon project

  • if the MPG variable <  20
    • say “What a Gas Guzzler”
  • else
    • say ” Your car is not a gas guzzler”

MPG Modification 1


Assignment 5) Modification of Fahrenheit to Centigrade

reopen the Fahrenheit to Centigrade project and add

  • if the degreesCentigrade  variable <30
    • say “It’s Very cold
  • else
    • say ” It is warm outside”

Assignment 6) Circle’s Area and Circumference: Create a world with your choice of person from the Peoplecollection. When you play the world, it should

  • ask the user for the radius of a circle. (This value should be stored in a variable ).
  • The person should then say the area and the circumference of the circle.( Links for the circumference formula , area of a circle)
  • (For an extra point do the same thing with a “Sphere“. Ask the user for the radius and calculate the surface area and the volume.

Assignment 8 

ezgif-com-optimize

Roman Numeral translator

Here’s a gif showing partial code and what the finished project should look like
Objective : to let the user type in a number between 1 and 10 and then have a character “translate” that into Roman Numerals ( I, II, III, IV, V, VI, VII, VIII, IX, X)

  • Ask the user for a number and store the return value into a variable called numberToTranslate
  • if the user enters a number greater than 10 then  OR less than 1 , have your character say, use either a or b “Only enter numbers between 1 and 10”screenshot59

 

 

  • use a series of “if/else tests to translate the number and say the write translation for each number between 1 and 10
  • screenshot61

We are going to use the roman Numeral Translator file again, so it’s important that you don’t lose the file and give it a good name that you can easily recognize in the future.


Assignment 7-extra credit ). Look up the formulas for the volume and surface area of a cylinder . Ask the user for the height of the cylinder and the radius, which should be stored in variables. Then calculate the surface area and volume of the cylinder . See if there is a cylinder shape in the gallery to use as a visual aid.


Assignment 8 ) Open Assignment

Create an Alice world that

  • uses a variable
  • uses a ask_user world function
  • uses a comment
  • uses an if/else
  • uses a math expression with more than one operation (ie addition and also multiplication or multiplication and also subtraction)
  • tells a story

 

Unit 4 . Objects & Arraylists

Unit 4  Objects && ArrayList

 

Part I

import java.util.ArrayList

 

RPN Calc Assignment

Use A Stack Class to create a RPN calculator

Part I : RPN Math Class

Input: String representing RPN syntax

Parse the String  (Maybe a separate method)

Calculate the return value of the RPN syntax.

Examples of Syntax

  • “3 -5 * “ -15

 

IF invalid syntax is entered, your method should throw an ArrithmeticException

Things to Support

  • negative numbers (vs subtraction)
  • decimal points
  • multiple spaces between characters

Part II: The GUI

  • Numbers 0-9
  • negative
  • 5 operators
  • Enter button
  • Clear button
  • System.exit(0) button
  • ** EC: support for keypresses including enter

Part III: **EC : Infix to postfix (allow users to enter numbers in infix)

 

Send me the jar file.

String Loop Assignments [Java]

Write the body for the methods described below.

Tester File here  (This one does not yet test the newest method)

As always, do not import any external libraries. All of the coding can be accomplished by using just  loops, arrays, strings and variables. Using anything else will lead to total loss of credit on associated methods.

Once you have completed each method, copy and paste the code in this file into your class. Then run the test() method and you will get feedback on your code. Note: This does not test all the methods. I have added new methods since writing that tester file. Also, please make sure that:

  • all methods are spelled/capitalized exactly  as shown on this page
  • variables are camelcase and have meaningful names
  • for i  loops use i as a variable
  • for-each  loops do not use i  as the variable

For each method below, you can assume that the parameters are not null

Part I

New Method 11.16 – Tester file updated 11.17 

boolean isAfterN(String str, String chrs, int index)

DescriptionThis method returns true if chrs  appears in  str  after index . 

screenshot.24

 

int countF(String str)

Description: This method returns the number of times that the the lower case letter ‘f’ occurs in str .

Method Call return value/output
countF(“abcdef”) 1
countF(“abcdfef”) 2
countF(“fff”) 3
countF(“xxx”) 0

boolean hasN_Fs(String str, int n )

Description: This method returns true if str has exactly n occurrences of the letter ‘f’ in it.

hasN_fs

String threeTimes(String str)

Description: This method returns the String str concatenated with itself three times

Method Call return value/output
threeTimes(“foog”) “foogfoogfoog”
threeTimes(“abc”) “abcabcabc”
threeTimes(“zt”) “ztztzt”
threeTimes(“”) “”

String nTimes(String str, int n)

Description: This method returns the String str concatenated with itself n times

Method Call return value/output
nTimes(“fg” , 2 ) “fgfg”
nTimes(“abc” , 0 ) “”
nTimes(“zt” , 3 ) “ztztzt”
nTimes(“uiz” , 4 ) “uizuizuizuiz”

int countMiddleChar(String str)

Precondition: str.length() ≥ 3.

Description: This method returns the number of times the middle letter of str appears in str.

Method Call return value/output
countMiddleChar(“acbcb” ) 2
countMiddleChar(“acbcx” ) 1
countMiddleChar(“bbbbb” ) 5
countMiddleChar(“xytbtzy”) 1

int indexOf(String haystack, String needle)

Description: Write your own indexOf() method.  Just to avoid any confusion – you cannot make use of the String’s built in indexOf() method. Our method returns the index of the 1st occurrence of needle in haystack . (Full credit if you can get this to work with Strings whose length is greater than 1).

indexOfSampleCall

int countChars(String str, String chars)

@precondtion : chars.length() <= str.lenght()  

Description: This method returns the number of times that chars  occurs in String str .

Method Call return value/output
countChars(“momdadmom” , “dad” ) 1
countChars(“foobofoo” , “foo”) 2
countChars(“foobofoofoo” , “foo”) 3
countChars(“foobofoofoo” , “xy” ) 0

Part II

String[] toArray(String str)

Description: This method returns an array comprised of the individual characters of str 

Method Call return value/output
toArray(“abc”  ) { “a”, “b”, “c”}
toArray(“xyz”  ) {“x”, “y”, “z”}

String[] toArraySansChar(String str, char ch)

DescriptionThis method returns an array of Strings comprised of  single letter strings extracted from the input String str ; however, we will always skip the char ch :

 

toArraySansChar

 

String[] reversedBy2s(String str)

DescriptionThis method returns an array of Strings comprised of pairs of characters from the input, — in reverse order as shown below:

reversed_by2s

 

String reverseBy3s(String str)

DescriptionThis is like the prior method, except you are going by 3’s and returning a String , not an array of Strings.

reverseby-3s

 

 

boolean isPalindrome(String str)

Description: This method returns true  if  str  is a palindrome

Method Call return value/output
isPalindrome(“abc”  ) false
isPalindrome(“aba”  ) true
 isPalindrome(“abba”  )  true

 

 

Java Stack Assignment

A Stack is a “LIFO” data structure (last in first out).

Here’ s an animation of how stacks are used in an RPN calculator.

More RPN practice

 

Create a stack Class that is based off of your linkedList code.

 

A stack has the following 3 methods

 

 

 

Create an RPN calculator Class