CIS36A Homework 3
Topic: Use variables, graphical dialogs (using JOptionPane),complex expressions, Java Math class.
This homework uses materials covered in Lecture 6/29/22.
Create a new Java project titled “Homework3” and Java classHomework3_XXXXX where XXXXX are the last 5 digits of your studentID.
The program should use the JOptionPane class (in javax.swingpackage) to read from user input the value of the semi-major axis(major radius) and the semi-minor axis (minor radius) of anellipse then it calculates and displays the focus, the area and thecircumference. Input numbers can have decimalfractions. You can always assume that the input semi-majoraxis is greater than the semi-minor axis and there is no need tocheck this in code.
The focus of the ellipse is calculated as:
where a is the semi-major axis length and b is the semi-minoraxis length.
You can always assume that the 2 inputs satisfies thiscondition:
The area of the ellipse is πab, where π is the PI value.
The circumference of the ellipse must be approximated using thisformula:
Use this exact formula and do not use other less preciseformulas that you find on the Internet.
Import the Math class so that you do not have to define the PIvalue since PI is a defined constant of the Math class. DO NOTDEFINE YOUR OWN PI CONSTANT. The square root function is also inthe Math class.
Your code should use the variable name majorRadius for a andminorRadius for b, not a and b.
Code Comments:
Put description comments in your code to describe the purpose ofthe code. Also put your name in the top code comment.
/**
Homework 3
@author: _________
Program purpose: _________
*/
Testing: Test your code with various valid input values.
Sample program runs:
Run 1
Run 2
Submit your code file Homework3_XXXXX.cpp in Canvas before thedue time.
CIS36A Homework 3 Topic: Use variables, graphical dialogs (using JOptionPane), complex expressions, Java Math class. Thi
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am