Difference between revisions of "CISC181 F2017 Lab1"

From class_wiki
Jump to: navigation, search
(static char mostCommonChar(String queryString))
(static char mostCommonChar(String queryString))
Line 18: Line 18:
 
===<tt>static char mostCommonChar(String queryString)</tt>===
 
===<tt>static char mostCommonChar(String queryString)</tt>===
  
Iterate through the characters in <tt>queryString</tt> 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, if 'a' occurs 7 times and 'b' occurs 7 times, return 'a'.
+
Iterate through the characters in <tt>queryString</tt> 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, if 'a' occurs 7 times and 'b' occurs 7 times, return 'a'.  You should do this ''without'' any external data structures such as arrays.
  
 
===<tt>static void drawLayeredPyramid(int numLayers, char firstChar, char secondChar)</tt>===
 
===<tt>static void drawLayeredPyramid(int numLayers, char firstChar, char secondChar)</tt>===

Revision as of 06:27, 12 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 the three other methods described below.
  • 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.
  • Suppose you want to calculate how far away a cannonball will land on Earth if fired at an inclination angle of theta degrees and an initial velocity of v meters / second. Ask the user to enter theta and v, pass them to computeDistanceToLanding(), and print the returned result.
  • 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 characters in 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, if 'a' occurs 7 times and 'b' occurs 7 times, return 'a'. You should do this without any external data structures such as arrays.

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 numLayers rows, alternating characters firstChar and secondChar.

static float computeDistanceToLanding(float thetaDegrees, float velocityMetersPerSecond)

Cannon.jpg

Assume that the ground is perfectly planar, the cannon is at a height of 0, and neglect drag from atmospheric resistance. I am not going to provide the relevant physics formula -- finding it and turning it into Java is your assignment here. Once you have calculated the distance, return the answer in meters.