Question: Activity 16.2: More Method Practice (10 pts) Open Eclipse and create a new project called Methodic with a Java class called Methodic.java Copy and paste
Activity 16.2: More Method Practice (10 pts)
Open Eclipse and create a new project called Methodic with a Java class called Methodic.java
Copy and paste the below starter code into your file:
/* * @author * CIS 36A * */ public class Methodic {
public static void main(String[] args) { System.out.println("***Testing areaRectangle*** "); System.out.printf("Should print 15.0: %.1f ", areaRectangle(5.0, 3.0)); System.out.printf("Should print 5.3: %.1f ", areaRectangle(3.5, 1.5)); System.out.println(); System.out.println("***Testing areaTriangle*** "); System.out.printf("Should print 7.5: %.1f ", areaTriangle(5.0, 3.0)); System.out.printf("Should print 2.6: %.1f ", areaTriangle(3.5, 1.5)); System.out.println(); System.out.println("***Testing minNum*** "); System.out.println("Should print 2: " + minNum(9, 2)); System.out.println("Should print 9: " + minNum(9, 9)); System.out.println("Should print 2: " + minNum(2, 9)); System.out.println(); System.out.println("***Testing firstLetter*** "); System.out.println("Should print A: " + firstLetter("Abracadabra")); System.out.println("Should print z: " + firstLetter("zebra")); System.out.println("Should print h: " + firstLetter("hello there!")); System.out.println(); System.out.println("***End of Tests***"); } }
Then, either above or below main (not in the {} for main), but inside the { } of the class Methodic, write the following methods:
Name: areaRectangle
Takes in 2 double parameters - one for the length and one for the width
returns the area of the rectangle as a double
Name: areaTriangle
Takes in 2 double parameters - one for the base one for the height
returns the area of the triangle as a double
Name: minNum
takes in two integer parameters
returns the smaller of the two numbers as an integer
Name: firstLetter
takes in one String parameter
returns the first character in the string
After writing your methods, compile and run your code.
Adjust any methods that do not give the correct output in the tests
When all of your tests pass, submit your program to Canvas.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
