CMPS 200 Homework Assignment 4, Fall 2012
American University of Beirut · Introduction to Programming · 2 pages
More CMPS 200 files
- Homework 11 · Fall 2018HomeworkView
- Homework Last Assignment · Fall 2018HomeworkView
- Homework Asst10 · Fall 2017HomeworkView
- Homework 9 · Spring 2017HomeworkView
- Homework Assignment 2 · Fall 2016HomeworkView
- Homework Assignment 5 · Fall 2016HomeworkView
- Homework Assignment 6 · Fall 2016HomeworkView
- Homework 1 · Spring 2016HomeworkView
Show the text of this homework
Faculty of Arts & Sciences
Department of Computer Science
CMPS 200—Introduction to Programming
Assignment 4 – Due Friday Oct 19, 2012
Notes and Announcements
Reading Material: review Chapters 1-4.
This assignment is exceptionally due this week on Friday Oct 19 at 8:00pm.
A reminder that the first exam will take place on Saturday Oct 20, 2011, 9:00-11:00am, in Bliss Hall.
Attached are the APIs you may need during the exam. A copy of this page will be distributed to you. The exam is
closed-book and closed-notes otherwise. No access to any local or internet recourses is allowed.
You may use your own laptop during the exam, but you have to make sure it has enough battery power to last
you for the whole exam period.
We will have a “Programming Clinic” open to all on Friday 2:00-5:00pm in Bliss 209. This is intended to provide
additional help and you are encouraged to take advantage of it as needed.
Exercises
1. Triangle. Write a program Triangle.java that takes one command line parameter N and prints out a two
dimensional N-by-N triangular pattern as shown below. (Hint. Think about the pattern's structure).
* * * * * *
. * * * * *
. . * * * *
. . . * * *
. . . . * *
. . . . . *
2. RandomString. Write a program that takes a positive integer N and a string as command line arguments (N is
assumed to be smaller than the length of the string). The program should pick N random characters from the
string and construct and print a new string composed of these random characters.
3. RemoveSpaces. Write a method removeSpaces that accepts a string as argument and returns a string with the
white space characters removed from it (the method should not print anything to the console). The signature of
the method should be:
public static String removeSpaces(String str)
Hint: The method should build a string one character at a time using the + operator, starting with the empty
string ””.
Use this method to write a program above that takes an integer command line argument N followed by N strings
and prints each of the strings without spaces. Hint: The strings must be quoted on the command line.
4. Palindromes. Write a method isPalindrome that accepts a string as argument and returns true or false
indicating if the string is a palindrome or not. A palindrome is a string that can be read the same way forward
and backward. Your method must handle upper and lower case characters (the string “Madam” is a palindrome).
The signature of the method should be:
public static boolean isPalindrome(String str)
You are not allowed to generate a new string in the your implementation of this method. Rather, you should walk
through the string to determine if is a palindrome or not.
Hint: Use the method Character.toLowerCase() and/or one or more of the other methods on variables of
type char; see page 280 of your textbook.
Use this method to write a program Palindromes that takes an integer command line argument N followed by N
strings and prints the strings that are palindromes.
Submission Instructions
As usual, submit your commented source code and sample runs in a zip file named s#_asst4_netid, where # is
your section number (between 1 and 9) and netid stands for your AUBnet user name.
Introduction to Computer Programming (CMPS 200)
Fall 2012
2 of 2