Write a program which returns the phrase “Hello World!” to the screen.Extension: You can extend this program by getting the program to take a name as a string argument. The program should then return “Hello Name!” to the screen.LO: Sequence; Basic String I/O
Upper or Lower
Write a program that given a mixed case sentence outputs upper and lower case versions. The program should be dynamic so that the user can enter a string.Example Output:You entered: Once Upon A Timelowercase: once upon a timeUPPERCASE: ONCE UPON A TIMELO: String Operations.
Create a program(s) that will calculate the area of:
Extension: You might look at using: IFs to decide on the shape; Methods to split up the code; and Maths Libraries for PI but simple programs can be created without any of these.LO: Variables, Arithmetic Operations, Basic I/O
- A Rectangle
- A Triangle
- A Circle
- A Polygon
Write a simple GUI that converts any given number into another computer unit unit. Computer units: byte, kilobyte, megabyte etc...LO: Doubles; Methods; Java GUIs.
Write a program that replaces all the vowels in a word with a dash (-). You should use a String.replace() method.Note: you will need to call replace more than once to remove all vowels unless you complete the extension.Extension: Advance your program so it uses regular expressions to replace any character(s) in your string with a dash (-).LO: String Operations.
One of my favourites. Write a program that tests the length of a string. If the String is even it will output 'even'. If the string is odd it will output 'odd'.You will need to use an IF statement and find the length of the string using the String.length() method.Note: The modulus of the string's length e.g. length % 2 will return either 0 or 1 which you can use to determine odd or evenLO: String Operations; IF Selection; Modulus.
Write a program that splits a sentence into words and outputs each word on a separate line.To complete this task you will need to look at the String.split() method and be able to use a 'for' to loop through the array results.LO: String Operations; For Loops; Arrays.
Write a program that takes a word and returns its plural version. This is a good opportunity to use certain tools so make sure you check out the LOs below. If you are not sure on the plural rules then check out http://bit.ly/VJ416zLO: Select Case Selection; SubString; Concatenation.
Write a function called IsValidByte which takes a string as its argument and returns TRUE if the string has exactly 8 characters which are all “0” or “1”. For example: IsValidByte(“01101010”) should return TRUE IsValidByte(“1101010”) and IsValidByte(“01201101”) should both return FALSE.LO: String Operations
Write a function called AddBytes which takes two valid strings representing bytes as its arguments and returns a string which represents the sum of the two bytes using Binary arithmetic. For example AddBytes(“10010100”, “01001101”) should return “11100001”Note that you are NOT ALLOWED to convert these strings to their equivalent integers!Extension: How does your function cope with overflow?).LO: String Operations; While Loops.
Write a function called CountOccurences which takes two arguments. The first is a single-character string and the second is a string of any length. The function should return the number of times that the character occurs in the second argument. For example: CountOccurences(“a”,“Bananarama”) should return the integer 5.Extension: For a challenge: add a third argument of type Boolean. If this argument is TRUE then the search is case-sensitive, if it is FALSE then the search ignores case. It should default to FALSE. If the language used by the centre allows it, this third argument could be optional – defaulting to TRUE.LO: Methods, String Operations.
Wake Up, it's time to die.
Write a program that takes two dates (one could be today/now) and the other one which is sometime in the future and calculates the time to go. Basically create a countdown timer and/or birthday calculator.Extensions:
- Determine the day that a given date occurs on.
- Make it work for dates in the past.
Read in a file containing a nursery rhyme before reversing all the lines and writing out the result.Extensions:
LO: String Operations, File I/O
- Reverse the order of words in each line before writing back to the file.
- Sort out the sentence case for each new reversed line.
Produce a program which will read unencrypted ‘plaintext’ text from a file and encode it with a shift of 2 before writing the encoded ‘ciphertext’ to a new file.More information can be found on the shift cipher at Wikipedia.Extensions:
LO: File I/O; String Operations.
- Allow any shift value to be given.
- Write a Function called Atbash which encodes the file using AtBash e.g. A ↔Z, B ↔Y, C ↔X etc.
Problem 17 from Project Euler.
Write a program which works out how many letters are used if a number is written as words. For Example:
Note: this is a really good opportunity to employ recursive techniques.LO: Recursion.
- 1 becomes One and uses 3 letters,
- 7 becomes Seven and uses 4 letters (S,E,V,N),
- 256 becomes two hundred and fifty-six and uses 15 letters.
Topic 16Word CounterYou have been provided with the Christmas Carol by Charles Dickens in text file format. There are a number of tasks that you are to perform with this file:
You will need to explore different data structures. It is possible to complete this task with arrays but it will not provide the most efficient solution. As an extension you could explore linked lists and hash tables. The example program uses Java ArrayLists and HashMaps and shows how the latter provides a more rapid solution.Another version of this task is at http://w2.compu2learn.co.uk/word-counter/222LO: File I/O; Data Structures;
- Read the contents of the file into a data structure counting the number of times each word occurs.
- Write the results back out to another results file using CSV format.
- It should also be possible to search for a word returning the number of times it occurs.
- Calculate the time taken to load the words and to find a search word.
Taken from Task 3 2008 AS OCR Computing (~22.5 Hours).Wari is a game played on a board that consists of 12 cups placed in two parallel rows of six cups and a large cup at each end. The game is for two players; each player has a row of six cups and one large cup for prisoners.For more details go to http://compu2learn.co.uk/wari-game
Taken from Task 3 2006 AS OCR Computing (~22.5 Hours).A manufacturing company wishes to make a new calculator that allows a user to input two numbers using Roman numerals and displays the numbers in both Roman and Arabic decimal forms. The calculator then allows a user to add or subtract the two numbers and again displays the result in both Roman and Arabic decimal forms.For the full information go to http://w2.compu2learn.co.uk/roman-numbers/213
Snakes and Ladders
Taken from Task 3 2005 AS OCR Computing (~22.5 Hours)A manufacturer of games has decided to design a new snakes and ladders board consisting of 100 squares. The manufacturer has asked a systems analyst to design a simulation of the game using different designs.For full information go to http://w2.compu2learn.co.uk/snakes-and-ladders/217
Taken from Task 3 2007 AS OCR Computing (~30 hours).One of the ways in which votes may be counted in an election is by a transferable vote system. There are a number of such systems in use in different parts of the world. One of them is called the Alternative Vote (AV) system. For this task the AV system is implemented in the way described below and this is the only method to be used in this task.For full details go to http://w2.compu2learn.co.uk/votes/218