Welcome to the GitHub repository for the CS4421-2022 cohort (ISE) at the University of Limerick! Here you will find all the exercises and content regarding CS4421. You are free to submit PR's to improve the content.
Following the below directory structure, you will find your assignment in the file called Asssignment.java. There are 3 methods here that you will have to implement.
-
findSecondSmallestItem
This method takes in an array of integers and is to return the first index of the second smallest number in the array. You will need to find the second smallest number in the array and return the first index.
An example
// indexes: 0 1 2 3 4 5 int[] arr = new int[]{1, 2, 3, 4, 5, 6}; System.out.println("index of second largest number is " + findSecondSmallestItem(arr)); //Console output: //index of second largest number is 1
You will need to take into account for cases where the array only have one or no values aswell.
If an array has no values, return -1
-
showFrequency
This method takes in an array of integers and is to return a string that represents the frequency of each number in the array in the following format.
int[] arr = new int[]{1, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5}; System.out.println(showFrequency(arr)); //Console output: //1 - //2 -- //3 --- //4 ---- //5 -
As we can see from the example above, if a number exists in the array, then you should represent it with the number, a space, and a number of dashes(hyphen's) that match the amount of times it is present in the array. In the above example, there are 4 four's present in the array, this means that the output for that number will be the number four followed by 4 dashs.
If a number is not present in the array, then it should not be represented in the methods return. You should return your output in ascending(low - high) order.
HINT: you will need to know how to make a multi line string in java to be able to return the entire structure back through the method.
String output = "This is a multi line string in java. This will print out on the first line.\nwhile this line will print out on the second line of the console.\nThis is all made possible with the use of the new line escape character(google it..)" System.out.println(output); //Console output: //This is a multi line string in java. This will print out on the first line. //while this line will print out on the second line of the console. //This is all made possible with the use of the new line escape character(google it..)
-
lowestCommonDenominator
This method takes in an array of integers and is to return the lowest common denominator of all the elements in the array. The arrays that we are working on are whole integer numbers but for this method, we should treat these numbers as a representation of the denominator of a fraction. This means that you are to compute the lowest number that all numbers in the array can divide into.
An example
int[] arr = new int[]{1, 2, 3, 4, 5, 6}; System.out.println("The lowest common denominator is " + lowestCommonDenominator(arr)); //Console output: //The lowest common denominator is 60
There is a total of 3 marks awarded for this assignment. The will be 1 mark awarded for each method. There will be a number of automatic tests run on your code when you push it to github. You will need to pass each test for a method to gain a mark.
You can see the test being run here.
src
├───main
│ └───java
│ └───com
│ └───example
│ └───project
│ └───Assignment.java
└───test
└───java
└───com
└───example
└───project
└───AssignmentTest.java
- Adam J. Doherty Master student at UL
- Ivan Hugo Guevara PhD researcher at Confirm Centre@UL
- Dr. Salim Saay Lecturer at University of Limerick
- Prof. Tiziana Margaria Full professor and Co-Director of Immersive Software Engineering [1] at University of Limerick