Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

--> CSc 102 -- Practical 4 <--

50 + 25 = 75 MARKS

Deadlines
You must ​complete and submit your solutions​ up to and including​ ​Task 4​ by ​5pm ​on the day of
your practical. Instructions for how to submit your work are given in each section. Work that is not
submitted by this deadline ​will not be marked​.

All remaining questions must be completed and submitted by ​2pm​ on the ​Monday​ after the practical.

You only need to submit the ​.java​ file for each task on RUConnected.

Task 1: A bad case [5 marks]


Write a Java method that will change a lowercase word in a sentence to all capitals. However, if the
word is already all capitals, the method should instead change the first and last letters of the word to
lowercase.

The main should prompt the user to enter a sentence and the word that needs to be changed. For
Example:

Example 1:
Please enter a sentence: I can bend a tin.
Which word would you like to change: can
Bad case: I CAN bend a tin.

Example 2:
Please enter a sentence: I CAN bend a tin.
Which word would you like to change: can

Bad case: I cAn bend a tin.

Task 2: Anagrams [10 marks]


An anagram is a word that is made up by rearranging the letters in another word. Write a Java
program that will read in two words and determine if they are anagrams of each other.

For example:
Please enter the first word: dusty
Please enter the second word: study
dusty and study are anagrams
Task 3: Arr(ay) me Matey [25 marks]
Download the skeleton called ​ArrMateySkel.java​. Complete the Java program so that it will do
the following:
● Read in an array of integers from the command line.
● Write a method that will:
○ Find the smallest number entered
○ Find the largest number entered
○ Find the sum of the numbers entered
● Write a method that will calculate the square of each value in the array.
● Write a method that will find the difference between neighbouring values in the array.
● Write a method that will find the absolute difference between the squares of neighbouring
values in the array.
Your program should display the following:

For example:
java ArrMatey -5 -10 0 5 10 15
The original array was: -5 -10 0 5 10 15
The min value is: -10
The max value is: 15
The sum of the values is: 15
The squares of each element is: 25 100 0 25 100 225
The differences are: 5 -10 -5 -5 -5
The abs differences of the squares are: 75 100 25 75 125

Task 4: Alphabetical [10 marks]


Write a Java program (​FristAlpha.java​) that reads in an array of words from the command line
and returns the one that appears first alphabetically.

For example:
java FirstAlpha sat cart hat
cart

Code Submission:​ In order for your tutor to mark your program, you need to upload it to
RUConnected using the submission link. If you do not submit your code on RUConnected your tutor
can not mark it and you will get zero for this question.

Homework follows below


Homework

Task 5: More Anagrams [15 marks]


An anagram is a word that is made up by rearranging the letters in another word. Extend your Java
program that it will read in two sentences and check if they are anagrams, ignoring punctuation,
spaces and capitalization.

For example:
java Anagram
Please enter the first word: Eleven plus two!
Please enter the second word: Twelve plus one?
Eleven plus two! and Twelve plus one? are anagrams

Task 6: Alphabetical [10 marks]


Write a Java program (​FristAlphaI.java​) that reads in an array of words from the command line
and returns the one that appears first alphabetically, ignoring capitalization.

For example:
java FirstAlpha SAT Cart hat
Cart

Code Submission:​ In order for your tutor to mark your program, you need to upload it to
RUConnected using the submission link. If you do not submit your code on RUConnected your tutor
can not mark it and you will get zero for this question.

You might also like