Question

Unit 5: Discussion - Part 1 No unread replies.No replies. Question Read the lecture for Chapter...

Unit 5: Discussion - Part 1

No unread replies.No replies.

Question

Read the lecture for Chapter 5 and then answer the following:.

Among other topics, this week's lecture covered Application Programming Interface (API) and Wrapper classes. This discussion thread will require material from both of them. Show syntactically correct Java code that requests at least one number from the user. The program will store all the numbers the user provides into separate String variables, and it will use the appropriate methods from the wrapper classes to convert these Strings into numerical values. Afterwards, the program should use these numerical values to compute any mathematical formula that uses at least one method from the Math class and display the outcome with appropriate titles. Show also a screen capture with a sample input/output session of your program.

Hint: Figure 5.3 from the textbook shows an example that is similar to what is requested here. The only difference is that, in the textbook, figure 5.3 reads the base of the triangle using the nextDouble method. However, in this discussion thread, you must use the nextLine method to read the user input into a String and then use the wrapper class parseDouble to convert the String into a double. Like this:

      Scanner stdIn = new Scanner(System.in);

    String baseStr;
    double base;

    System.out.print("Enter the Width of the Square: ");
    baseStr = stdIn.nextLine();
    base = Double.parseDouble(baseStr);

Come up with a similar example of your own.

Homework Answers

Answer #1

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.

import java.util.Scanner;
class Main
{
   public static void main (String[] args)
   {
   //take the scanner
   Scanner sc=new Scanner(System.in);
  
   // we will calculate the circumference and area of the circle
       System.out.print("Enter Radius of the Circle: ");
       String radiusStr = sc.nextLine(); // read as string
      
       //parse it here with a (WRAPPER)
       Integer radius = Integer.parseInt(radiusStr);
      
       // Calculate the circumference and area
       // area = PI * r^2
       double area = Math.PI * Math.pow(radius,2);
       double circumference = 2 * Math.PI * radius;
      
       System.out.println("Area: "+area);
       System.out.println("circumference: "+circumference);
      
   }
}

====================

SCREENSHOT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Unit 5: Discussion - Part 2 No unread replies.No replies. Question Read the lecture for Chapter...
Unit 5: Discussion - Part 2 No unread replies.No replies. Question Read the lecture for Chapter 5 and then answer the following:. Present an ORIGINAL example of the correct use of the printf method. This example must show how integers, doubles and Strings are properly formatted for display. At least one integer, one double, and one String must be printed using printf. You are encouraged to consult the textbook and any other sources you deem relevant, but come up with...
Unit 3: Discussion - Part 2 No unread replies.No replies. Question Read the lecture for Chapter...
Unit 3: Discussion - Part 2 No unread replies.No replies. Question Read the lecture for Chapter 3, and then answer the following: Chapter 3 introduces us to the String class. It shows some of the methods one can apply to this type of variable (i.e. length(), toLowerCase(), substring(), indexOf(), etc). This class has many more, all described in the Java documentation. Review these methods and present an example of their usage, properly written in Java code. Explain the purpose of...
Task #4 Calculating the Mean Now we need to add lines to allow us to read...
Task #4 Calculating the Mean Now we need to add lines to allow us to read from the input file and calculate the mean. Create a FileReader object passing it the filename. Create a BufferedReader object passing it the FileReader object. Write a priming read to read the first line of the file. Write a loop that continues until you are at the end of the file. The body of the loop will: convert the line into a double value...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import...
please write the code in java so it can run on jGRASP import java.util.Scanner; 2 import java.io.*; //This imports input and output (io) classes that we use 3 //to read and write to files. The * is the wildcard that will 4 //make all of the io classes available if I need them 5 //It saves me from having to import each io class separately. 6 /** 7 This program reads numbers from a file, calculates the 8 mean (average)...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT