1. Homepage
  2. Exam
  3. [2022] UOW - CSIT121 Object Oriented Design and Programming - Final Exam - Q1 Java Static Methods

[2022] UOW - CSIT121 Object Oriented Design and Programming - Final Exam - Q1 Java Static Methods

This question has been solved
Engage in a Conversation

Question 1  CourseNana.COM

Write a Java program containing the static methods described in the following paragraphs. You need not include exception handling and validation in your solution. You must not use the following in your solution:  CourseNana.COM


CourseNana.COM


CourseNana.COM

  • • Lambda expression 
  • • The Stream API 
  • • Methods in the Arrays class (java.util.Arrays) 
  • • Methods in the Collections class (java.util.Collections) 

Method 1 public static void printNumbers(int startNum,  CourseNana.COM

int endNum,  CourseNana.COM

int numPerLine){  CourseNana.COM

// Your code  CourseNana.COM

}  CourseNana.COM

The method will print numbers from startNum to endNum, inclusive of both ends.  CourseNana.COM

The method will print numPerLine numbers per line.  CourseNana.COM

Example 1:  CourseNana.COM

printNumbers(21, 29, 4) will produce the following:  CourseNana.COM

21 22 23 24  CourseNana.COM

25 26 27 28  CourseNana.COM

29  CourseNana.COM

Example 2:  CourseNana.COM

printNumbers(4, 12, 6) will produce the following:  CourseNana.COM

4 5 6 7 8 9  CourseNana.COM

10 11 12  CourseNana.COM

You may assume:  CourseNana.COM


CourseNana.COM


CourseNana.COM

  • startNum >= 0, numPerLine > 0 
  • startNum < endNum 


CourseNana.COM

You must not use int[] or ArrayList in your solution.  CourseNana.COM


Method 2 public static boolean hasDuplicateChars(String data){  CourseNana.COM

// Your code  CourseNana.COM

}  CourseNana.COM

The method will return true if there are duplicate characters in data and false otherwise.  CourseNana.COM

Examples:  CourseNana.COM

hasDuplicateChars("abca1a2") will produce true.  CourseNana.COM

hasDuplicateChars("morning") will produce true.  CourseNana.COM

hasDuplicateChars("ab$wx$y") will produce true.  CourseNana.COM

hasDuplicateChars("35 x 12") will produce true. (2 blank spaces)  CourseNana.COM

hasDuplicateChars("methods") will produce false.  CourseNana.COM

You may assume the letters: a, b, c … z are in lower case.  CourseNana.COM

You must not use char[] or ArrayList in your solution.  CourseNana.COM


Method 3 public static String replaceWith(String data,  CourseNana.COM

char ch1,  CourseNana.COM

char ch2){  CourseNana.COM

// Your code  CourseNana.COM

}  CourseNana.COM

The method will return an instance of String containing all characters in data but with all occurrences of ch1 replaced by ch2. You must use recursion.  CourseNana.COM

Examples: Return value  CourseNana.COM


CourseNana.COM

replaceWith("programming", 'r', 'R');  CourseNana.COM

 "pRogRamming" 
CourseNana.COM


CourseNana.COM

replaceWith("java", 'a', 'A');  CourseNana.COM

"jAvA". 
CourseNana.COM


CourseNana.COM

replaceWith("1+2x3+4", '+', '%');  CourseNana.COM

 "1%2x3%4". 
CourseNana.COM


CourseNana.COM

replaceWith("22 Jun 2022", ' ', '-')  CourseNana.COM

"22-Jun-2022" 
CourseNana.COM


CourseNana.COM

CourseNana.COM


CourseNana.COM

Get the Solution to This Question

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
CSIT121代写,Object Oriented Design and Programming代写,University of Wollongong代写,UOW代写,CSIT121代编,Object Oriented Design and Programming代编,University of Wollongong代编,UOW代编,CSIT121代考,Object Oriented Design and Programming代考,University of Wollongong代考,UOW代考,CSIT121help,Object Oriented Design and Programminghelp,University of Wollongonghelp,UOWhelp,CSIT121作业代写,Object Oriented Design and Programming作业代写,University of Wollongong作业代写,UOW作业代写,CSIT121编程代写,Object Oriented Design and Programming编程代写,University of Wollongong编程代写,UOW编程代写,CSIT121programming help,Object Oriented Design and Programmingprogramming help,University of Wollongongprogramming help,UOWprogramming help,CSIT121assignment help,Object Oriented Design and Programmingassignment help,University of Wollongongassignment help,UOWassignment help,CSIT121solution,Object Oriented Design and Programmingsolution,University of Wollongongsolution,UOWsolution,