Upload Chapter3.java with a main method as below, plus two methods as follows: (
ID: 3715789 • Letter: U
Question
Upload Chapter3.java with a main method as below, plus two methods as follows:
(note: be certain to have correct 1. return type, 2. method names, 3. parameters passed.
PLUS get the Class Chapter3 correct, AND your name in comments, else zero (0:(
A. pentagonArea computes the area of a pentagon, given one real parameter as one side of the pentagon, and returns a real number from a formula I'm sure you can find in your online math resources. You should have done TODO Exercise#16, which is similar to this in many ways.
B. addSpaces returns a String with one space added between each character of a single String parameter, for example passing ("Dr. Iverson") will return "D r . I v e r s o n" You should have done TODO Exercise#17, which is similar to this in many ways.
Grading: Iverson's 1,2,3 of coding can get you half the credit here, the other half requires only a few lines of code. If you have more than ten lines of code for these, think again...
Explanation / Answer
Chapter3.java
public class Chapter3 {
public static void main (String args[]) {
System.out.println(pentagonArea(3.14));
// 16.963218978846978... return a real number, area of a pentagon
System.out.println(addSpaces("aBcD"));
// the String "a B c D" is returned, one space between each char
}
public static double pentagonArea(double a) {
return (Math.sqrt(5 * (5 + 2 * Math.sqrt(a)) )* a *a)/4;
}
public static String addSpaces(String s) {
String str="";
for(int i=0;i<s.length();i++) {
str=str+s.charAt(i)+" ";
}
return str.trim();
}
}
Output:
16.11072766097994
a B c D
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.