Question
Java: public class SecondProgram{ /*Print a message to the console, instructing the user to type a wise message for an owl to say. Collect that
Java:
public class SecondProgram{
/*Print a message to the console, instructing the user to type a wise message for an owl to say.
Collect that message into an appropriately named String variable.
Declare and initialize a single Scanner object. Use its nextLine() method to capture the users
input string from the console.
Based on the length of the message, print out the line of stars for the top and bottom
border of the text box, using a for-loop. Print the message with a single straight line
character on either side, leaving a space between the first and final characters of the
message.
Add the call to printMessage inside the printOwl method. Note that this is the only
modification necessary to the Assignment One version of printOwl.
Test printMessage inside the main method; once you see it works fine, then you can
test printOwl to see the complete drawing.*/
public static void printMessage(){
}
public static void printOwl(){
System.out.println("\t ^...^");
System.out.println("\t / o,o \\");
System.out.println("\t |):::(|");
System.out.println("\t===w=w===");
}
/*Instead of calculating the first 8 terms of the sequence, use the first 1, 000, 000 terms.
You must use a for-loop to do this.
Remembering that the formula for a circle is r2,
where r is the radius of the circle, ask
the user to provide the radius. The code for this action
is similar to the printMessage
method, where you created a Scanner object and asked the user for the value. In this
case, the value we want is a number, a double in fact, so instead of using the Scanners
nextLine() method, use nextDouble() instead.
Calculate the area of the circle where the radius is the users input and is the value
poduced by the million iterations of the series.
Print this value to the console.
Test the areaCircle method by adding a call in the main method.*/
public static void areaCircle(){
float nextTerm = 1;
float denom = 1;
float series = 0;
int i = 0;
while(i < 8){ //Loop 8 times
series = series + (nextTerm/denom);
denom = denom + 2;
nextTerm = nextTerm* -1;
i++;
}
series = series * 4;
System.out.println(series);
}
public static void main(String[] args){
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started