Question: *** I need this completed. I made the assignment bold and I left the code normal under. And under the code I will leae the
*** I need this completed. I made the assignment bold and I left the code normal under. And under the code I will leae the output we need. * LotsOfMethods Application
Overview
This programming assignment is intended to give you lots of practice writing methods.
Copy the code supplied below and paste it in to your development environment (e.g., jGRASP). Leave the main method EXACTLY as it is -- do not change a line of main. Write the code for the many missing methods. Once you have written all of the missing methods, and you run the main method supplied below, then it should generate the required output shown below.
Write the methods so that the methods will work for ANY reasonable input values and NOT JUST FOR THE EXACT values sent to the methods in the main method shown below. The first method, sampleMethod, has already been written -- you need to write the remaining methods.
Use good, descriptive variable names inside your methods.
Write the program so that it has good style.
Hint
Don't try to write all of the methods at once. Just do them one-at-a-time. To test them one-at-a-time, you will need to put most of main's instructions in a comment (comment out the calls to all methods below the method you are currently working on). Get that method working, then uncomment the next method to get called.
Start with this Code
/*
Copy this class and paste it in to your development environment (e.g., jGRASP).
Leave the main method EXACTLY as it is -- do not change a line of main.
Write the many missing methods.
Write the methods so that the methods will work for ANY reasonable input values
and NOT JUST FOR THE EXACT values sent in the main method below.
Use good, descriptive variable names inside your methods.
public class LotsOfMethods
{ public static void main(String [] args)
{ // Sample method getting called. Just reports the String sent to the method
// by printing "Received: " followed by the String.
sampleMethod("hello"); sampleMethod("there"); // For the received integer value, report whether or not it is odd.
// It should work for any integer value (not just those used below).
// It reports a message of the format "16 is not odd" or "1 is odd".
reportOdd(3);
reportOdd(100);
reportOdd(77);
// Assume that the two values represent the width and height of
// a rectangle. Report the area of the rectangle with a line of
// the form "Area is 100.0 for a rectangle of width 10.0 and height 10.0".
// Print one digit after the decimal point.
printArea(10.00, 10.0);
printArea(3.555, 19.4);
printArea(600.5, 1.1);
// Assume that the values sent to stockSale are a String representing
// the name of the company, an integer representing the number of shares
// of the stock that were sold, and the price the stock was sold at.
// Report the information about the sale in a line of output of this
// format:
//
// Sold 50 shares of IBM at $35.50 for $1,775.00
//
stockSale("IBM", 50, 35.5); stockSale("Apple", 100, 440.25); stockSale("GM", 25, 12.75); // Write the method determineTax. The method is sent the amount of the
// purchase and the tax rate. It returns a double value that is the
// amount of the tax.
// Note that the method determineTax does not print anything -- it
// just returns the value.
double m1 = determineTax(350.00, 0.06); // Michigan is 6%
double m2 = determineTax(79.99, 0.06);
double cal1 = determineTax(499.99, 0.0725); // California is 7.25%
System.out.printf("Here are the returned values: %.2f, %.2f, and %.2f ", m1, m2, cal1); // Reports the grade that corresponds to the test score supplied, according to this scale:
// A: 100-90, B: 89-80, C: 79-70, D: 69-60, E: 59-0. Report "Invalid" for any other score.
// Invalid scores should be reported like this: "110 is an invalid score".
// Valid scores should be reported like this: "70 has a grade of C".
testScore(93);
testScore(70);
testScore(110);
testScore(-3);
testScore(52);
testScore(88);
// In the gambling game of crapps the gambler rolls two dice. The first roll of the dice
// has several different outcomes. If a 2, 3, or 12 is rolled then the gambler "crapps out" (i.e,
// they lose). If they roll a 7 or 11 then they "win". If they roll any other number then
// they "keep rolling".
// Write a method that takes the two dice and reports one of the three possible outcomes:
// * "crapp out"
// * "win"
// * "keep rolling"
//
// This method just reports the status of just the first roll.
firstRoll(2, 3);
firstRoll(6, 1);
firstRoll(4, 5);
firstRoll(4, 3);
firstRoll(6, 6);
// Write a method waterState that takes a single double value as a parameter that indicates the
// temperature of the water. Your method will return a single String indicating the state of water
// at that temperature. The three possible states are "solid", "liquid", or "gas". I.e., water is
// solid, as ice, at 32 degrees or less, it is a gas (steam) at 212 degrees and above, and it is a
// liquid between 32 and 212.
String w1 = waterState(76.5); // 76 degrees -- liquid water
System.out.println("w1 is: " + w1); String w2 = waterState(17.7);
System.out.println("For 17 it is: " + w2); String w3 = waterState(32.0);
System.out.println("Right at 32 is is frozen: " + w3); System.out.println("Hot: " + waterState(250.0)); // Write a method that returns a boolean value of true or false.
// It takes three test scores, and return true or false to indicate
// if the average grade is a passing grade (i.e., return true if the average is
// 70.0 points or more).
boolean b = passes(99.0, 83.0, 90.2);
System.out.println("b is: " + b); boolean b2 = passes(72.0, 54.5, 69.5);
System.out.println("return value of: " + b2); System.out.println( passes(100.0, 5.0, 82.0) );
// Write a method that uses a loop to print the squares of numbers.
// The squares are reported in increments of one from the first
// number to the second number, inclusive:
squares(2, 9);
squares(100, 105);
squares(22, 30);
}
// ********* YOU SHOULD WRITE THE OTHER METHODS HERE *********
static void sampleMethod(String s)
{ System.out.println("Received: " + s); }
*** THIS IS THE REQUIRED OUTPUT ***
Received: hello
Received: there
3 is odd
100 is not odd
77 is odd
Area is 100.0 for a rectangle of width 10.0 and height 10.0
Area is 69.0 for a rectangle of width 3.6 and height 19.4
Area is 660.6 for a rectangle of width 600.5 and height 1.1
Sold 50 shares of IBM at $35.50 for $1,775.00
Sold 100 shares of Apple at $440.25 for $44,025.00
Sold 25 shares of GM at $12.75 for $318.75
Here are the returned values: 21.00, 4.80, and 36.25
93 has a grade of A
70 has a grade of C
110 is an invalid score
-3 is an invalid score
52 has a grade of E
88 has a grade of B
2 and 3: keep rolling
6 and 1: win!
4 and 5: keep rolling
4 and 3: win!
6 and 6: crapp out
w1 is: liquid
For 17 it is: solid
Right at 32 is is frozen: solid
Hot: gas
b is: true
return value of: false
false
2 squared: 4
3 squared: 9
4 squared: 16
5 squared: 25
6 squared: 36
7 squared: 49
8 squared: 64
9 squared: 81
100 squared: 10000
101 squared: 10201
102 squared: 10404
103 squared: 10609
104 squared: 10816
105 squared: 11025
22 squared: 484
23 squared: 529
24 squared: 576
25 squared: 625
26 squared: 676
27 squared: 729
28 squared: 784
29 squared: 841
30 squared: 900
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
