Operation (what the user sees) The user enters the target number of cubic units
ID: 3563804 • Letter: O
Question
Operation (what the user sees)
The user enters the target number of cubic units and the dimensions for the sphere and box, then selects the Set Initial Quantities button. If a negative value or 0 is entered, a dialog message box will ask the user to correct the value.
The user then selects the Calculate Volumes button. The volumes are calculated for both objects, displayed with one decimal place, and a message box indicates whether the objects' volumes are over, under, or on target.
When the user selects the Close button, the program terminates.
Specifications (what the programmer sees) Worker Class (Volume.java) Instance variables for the target value, radius, length, width, and height
At least two constructors, one must be a default constructor
Methods for calculating the volumes for each object and the difference between the calculated volumes and the target volume. You may add any additional methods that are necessary for your design. GUI Driver Class (you may use one or more classes for the driver, depending on your design)
The objects' volume fields should not be editable (user cannot enter values).
A dialog message box should inform the user if the volumes are over, under, or equal to the target.
Use a Layout Manager Implement the ActionListener and provide an actionPerformed method
A dialog message box should alert the user if any quantities are negative or 0. Display a volume or difference only if the input numbers are positive. Use a dialog message box to ask the user to correct the value(s) for any items that are not positive.
Create a Volume object and use the methods from Volume to calculate the objects' volumes and differences.
Example of what Program should look like
http://imgur.com/rrVHoue
Explanation / Answer
Java Programming for Engineers
Julio Sanchez
Maria P. Canton
ISBN: 0849308100
Publisher: CRC Press
*/
// File name: Area.java
//Reference: Chapter 5
//
//Java program to calculate the area of a circle
//Topics:
// 1. Using numeric variables and constants
// 2. Obtaining keyboard input
// 3. Displaying program data
// 4. Performing simple numeric calculations
//
//Requires:
// 1. Keyin class in the current directory
public class Area {
// Constant PI is defined at the class level
static final double PI = 3.141592653589793;
public static void main(String[] args) {
// Local variables
double radius, area;
// Input radius from keyboard
radius = Keyin.inDouble("Enter radius: ");
// Perform calculations and display result
area = PI * (radius * radius);
System.out.println("The area is: " + area);
}
}
//**********************************************************
//**********************************************************
//Program: Keyin
//Reference: Session 20
//Topics:
// 1. Using the read() method of the ImputStream class
// in the java.io package
// 2. Developing a class for performing basic console
// input of character and numeric types
//**********************************************************
//**********************************************************
class Keyin {
//*******************************
// support methods
//*******************************
//Method to display the user's prompt string
public static void printPrompt(String prompt) {
System.out.print(prompt + " ");
System.out.flush();
}
//Method to make sure no data is available in the
//input stream
public static void inputFlush() {
int dummy;
int bAvail;
try {
while ((System.in.available()) != 0)
dummy = System.in.read();
} catch (java.io.IOException e) {
System.out.println("Input error");
}
}
//********************************
// data input methods for
//string, int, char, and double
//********************************
public static String inString(String prompt) {
inputFlush();
printPrompt(prompt);
return inString();
}
public static String inString() {
int aChar;
String s = "";
boolean finished = false;
while (!finished) {
try {
aChar = System.in.read();
if (aChar < 0 || (char) aChar == ' ')
finished = true;
else if ((char) aChar != ' ')
s = s + (char) aChar; // Enter into string
}
catch (java.io.IOException e) {
System.out.println("Input error");
finished = true;
}
}
return s;
}
public static int inInt(String prompt) {
while (true) {
inputFlush();
printPrompt(prompt);
try {
return Integer.valueOf(inString().trim()).intValue();
}
catch (NumberFormatException e) {
System.out.println("Invalid input. Not an integer");
}
}
}
public static char inChar(String prompt) {
int aChar = 0;
inputFlush();
printPrompt(prompt);
try {
aChar = System.in.read();
}
catch (java.io.IOException e) {
System.out.println("Input error");
}
inputFlush();
return (char) aChar;
}
public static double inDouble(String prompt) {
while (true) {
inputFlush();
printPrompt(prompt);
try {
return Double.valueOf(inString().trim()).doubleValue();
}
catch (NumberFormatException e) {
System.out
.println("Invalid input. Not a floating point number");
}
}
}
}
Java Programming for Engineers
Julio Sanchez
Maria P. Canton
ISBN: 0849308100
Publisher: CRC Press
*/
// File name: Area.java
//Reference: Chapter 5
//
//Java program to calculate the area of a circle
//Topics:
// 1. Using numeric variables and constants
// 2. Obtaining keyboard input
// 3. Displaying program data
// 4. Performing simple numeric calculations
//
//Requires:
// 1. Keyin class in the current directory
public class Area {
// Constant PI is defined at the class level
static final double PI = 3.141592653589793;
public static void main(String[] args) {
// Local variables
double radius, area;
// Input radius from keyboard
radius = Keyin.inDouble("Enter radius: ");
// Perform calculations and display result
area = PI * (radius * radius);
System.out.println("The area is: " + area);
}
}
//**********************************************************
//**********************************************************
//Program: Keyin
//Reference: Session 20
//Topics:
// 1. Using the read() method of the ImputStream class
// in the java.io package
// 2. Developing a class for performing basic console
// input of character and numeric types
//**********************************************************
//**********************************************************
class Keyin {
//*******************************
// support methods
//*******************************
//Method to display the user's prompt string
public static void printPrompt(String prompt) {
System.out.print(prompt + " ");
System.out.flush();
}
//Method to make sure no data is available in the
//input stream
public static void inputFlush() {
int dummy;
int bAvail;
try {
while ((System.in.available()) != 0)
dummy = System.in.read();
} catch (java.io.IOException e) {
System.out.println("Input error");
}
}
//********************************
// data input methods for
//string, int, char, and double
//********************************
public static String inString(String prompt) {
inputFlush();
printPrompt(prompt);
return inString();
}
public static String inString() {
int aChar;
String s = "";
boolean finished = false;
while (!finished) {
try {
aChar = System.in.read();
if (aChar < 0 || (char) aChar == ' ')
finished = true;
else if ((char) aChar != ' ')
s = s + (char) aChar; // Enter into string
}
catch (java.io.IOException e) {
System.out.println("Input error");
finished = true;
}
}
return s;
}
public static int inInt(String prompt) {
while (true) {
inputFlush();
printPrompt(prompt);
try {
return Integer.valueOf(inString().trim()).intValue();
}
catch (NumberFormatException e) {
System.out.println("Invalid input. Not an integer");
}
}
}
public static char inChar(String prompt) {
int aChar = 0;
inputFlush();
printPrompt(prompt);
try {
aChar = System.in.read();
}
catch (java.io.IOException e) {
System.out.println("Input error");
}
inputFlush();
return (char) aChar;
}
public static double inDouble(String prompt) {
while (true) {
inputFlush();
printPrompt(prompt);
try {
return Double.valueOf(inString().trim()).doubleValue();
}
catch (NumberFormatException e) {
System.out
.println("Invalid input. Not a floating point number");
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.