Difference between revisions of "CISC181 F2017 Lab1"
From class_wiki
(→static void main(String[] args)) |
|||
Line 11: | Line 11: | ||
* Ask the user (using <tt>println()</tt> or <tt>printf()</tt>) to input a string on its own line. Read this with a <tt>Scanner</tt> object and pass it to <tt>mostCommonChar()</tt>. Print the returned value. | * Ask the user (using <tt>println()</tt> or <tt>printf()</tt>) to input a string on its own line. Read this with a <tt>Scanner</tt> object and pass it to <tt>mostCommonChar()</tt>. Print the returned value. | ||
− | * Ask the user to enter two chars and a positive | + | * Ask the user to enter two chars and a positive number. Read these with your <tt>Scanner</tt> object and pass them to <tt>drawInvertedPyramid</tt>. |
* For all user inputs, check for legality here in <tt>main()</tt>. If there is a problem, print an informative error message and let the program end. | * For all user inputs, check for legality here in <tt>main()</tt>. If there is a problem, print an informative error message and let the program end. | ||
Revision as of 22:58, 11 September 2017
- Make a new project (but now n = 1) following these instructions
- Name your class "Lab1". This happens when you are creating a new module, in the Java class name field
- Add your name and section number in a comment before the class declaration
- As explained in the subsections below, modify static void main() and create two other methods: static void countOccurrences() { ... } and static void printLayeredPyramid() { ... }
- Submit your Lab1.java on Sakai by Monday, September 18
static void main(String[] args)
Your main() should do the following:
- Ask the user (using println() or printf()) to input a string on its own line. Read this with a Scanner object and pass it to mostCommonChar(). Print the returned value.
- Ask the user to enter two chars and a positive number. Read these with your Scanner object and pass them to drawInvertedPyramid.
- For all user inputs, check for legality here in main(). If there is a problem, print an informative error message and let the program end.
static char mostCommonChar(String queryString)
Iterate through the String queryString and count how many times each character occurs. Whichever character occurs the most times, return it. Ties should be broken in alphabetical order--that is, prefer 'a' to 'b', and so on.
static void drawLayeredPyramid(int numLayers, char firstChar, char secondChar)
Consider the following pattern:
$$$$$$$$$$ ¢¢¢¢¢¢¢¢¢ $$$$$$$$ ¢¢¢¢¢¢¢ $$$$$$ ¢¢¢¢¢ $$$$ ¢¢¢ $$ ¢
It consists of 10 alternating rows of $ and ¢ characters. The first row has 10 columns of characters, and each successive row has one less. drawLayeredPyramid() should make a similar pattern with numRows rows, alternating characters firstChar and secondChar.