CISC181 S2019 Lab1
- 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 your partner's name in a comment before the class declaration. Remember that there are new pairs this week!
- As explained in the subsections below, modify static void main() and create the three other methods described below.
- Submit your Lab1.java on Canvas by midnight of Tuesday, February 26. As before, each partner should submit identical .java files and add a comment about how your partner interaction was this week.
static void main(String args)
Your main() should do the following:
- As with Lab #0 last week, give your user the choice of several options (using println() or printf()), to be chosen by inputting a single number (which is read with a Scanner object). This time, the options are: 1 to solve a basic physics problem, 2 to draw a particular pattern with print commands, and 3 to find the most common character in a string. Whichever choice is given (after error-checking), take the steps specified below and call the corresponding function.
- Option 1: Ask the user to enter theta and v, read them, pass them to computeDistanceToLanding(), and print the returned results, each on its own line and with 2 digits of precision after the decimal.
- Option 2: Ask the user to enter two chars and a positive number. Read these and pass them to drawLayeredPyramid().
- Option 3: Ask the user to input a string on its own line. Read this and pass it to minMaxFrequencyChar(). Print the returned characters on one line, separated by a space.
- For all user inputs, check for legality here in main(). If there is a problem, print an informative message with the word "error" somewhere in it, and let the program end.
static float computeDistanceToLanding(float thetaDegrees, float initialVelocityMetersPerSecond)
Suppose you want to calculate how far away a cannonball will land if fired at an inclination angle of theta degrees and an initial velocity of v meters / second. Furthermore, you want to answer this question for four solar bodies: (1) Earth, (2) Earth's moon, (3) Jupiter, and (4) the sun. Assume that the ground is perfectly planar, the cannon is at a height of 0 m, 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 4 distances, return the answers in meters in an array.
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 char minMaxFrequencyChar(String queryString)
Iterate (aka loop) through the characters in queryString and count how many times each character occurs. Whichever characters occurs the least times and the most times, return them in an array (min in slot 0, max in slot 1). Ties should be broken in alphabetical order--that is, if 7 is the max frequency of any character but both 'a' and 'b' occur 7 times, return 'a'. To make a comparison, use Character.compare().