The below code runs fine the only problem is when I run this code there is a value of "3" in the input textbox which should be null, I have no idea why its doing this any help will be appreciated. THANKS

import javax.swing.JOptionPane;

//inherits from Monument class--->
public class MonumentBase extends Monument {
	private double baseThickness;
	private double baseDiameter;

public MonumentBase() {
	super();
	baseThickness = super.getThickness();
	baseDiameter = super.getWidth();
	}

public MonumentBase(int quantity) {
	super(quantity);
	baseThickness = super.getThickness();
	baseDiameter = super.getWidth();
	}

public MonumentBase(int quantity, double width, double thickness,
double height, double baseThickness, double baseDiameter) {
	super(quantity, width, thickness, height);
	setBaseThickness(baseThickness);
	setBaseDiameter(baseDiameter);
	}

public double getBaseDiameter() {
	return baseDiameter;
 	}

public void setBaseDiameter(double diameter) {
if (diameter < super.getWidth() || diameter > super.getWidth() + 24)
    baseDiameter = super.getWidth();
else
	baseDiameter = diameter;
	}

public double getBaseThickness() {
	return baseThickness;
	}

public void setBaseThickness(double thickness) {
if (thickness < super.getThickness()
    || thickness > super.getThickness() + 3)
	   baseThickness = super.getThickness();
else
	baseThickness = thickness;
	}

public double getBaseRadius() {
	return baseDiameter / 2.0;
    }

@Override
public double getCubicInches() {
	return Math.PI * baseDiameter * baseDiameter *
	baseThickness * super.getQuantity() * 0.25 +
	super.getCubicInches();
	}

@Override
public double getCubicFeet() {
    return this.getCubicInches() / 1728;
    }


public static void main(String args[]) {
	int selection = 0;
	Monument order = null;
	MonumentBase orderBase = null;
	selection = getSelection();
	createOrder(selection);
	System.exit(0); // GUI closing
	}

/**
  * Method getSelection to get user input
  f*/
private static int getSelection() {
	String stringSelection = " ";
	int numericSelection = 0;

stringSelection = JOptionPane.showInputDialog(null,
"Make a Selection\n"
+ "1:   For Default Monument Only Order\n" +
  "2:   For Default MOnument Plus Base Order\n" +
  "3:   Default Monument Only Dimensions >>> Greather Than 5\n" +
  "4:   Defualt Monument and Base Dimensions >>> Greather Than 5\n" +
  "5:   Monument only >>> Enter All Dimensions And Quantity\n" +
  "6:   Monument AND Base >>> Enter All Dimensions And Quantity\n" +
  "7:   EXIT PROGRAM\n" +
  "Enter 1, 2, 3, 4, 5, 6 or 7 ONLY!", JOptionPane.QUESTION_MESSAGE);
   numericSelection = Integer.parseInt(stringSelection);
   return numericSelection; //Return selection
	}

/**
  * Static method createOrder
  */

private static void createOrder(int selection)
	{
		Monument order = null;
		MonumentBase orderBase = null;
		int quantity = 0;
		double width = 0;
		double thickness = 0.0;
		double height = 0.0;
		double baseThickness = 0.0;
		double baseDiameter = 0.0;
		boolean base = false;

//Switch statements for selection ---->

switch(selection) {
case 1:
	 order = new Monument();
	 break;

case 2:
	 orderBase = new MonumentBase();
	 base = true;
	 break;

case 3:
      quantity = (int)getNumericInput
      ("Enter Number of Monuments Desired: ");
	  order = new Monument(quantity);
	  break;

case 4:
	 quantity = (int)getNumericInput
	 ("Enter Number of Monuments Desired: ");
	 orderBase = new MonumentBase(quantity);
	 base = true;
	 break;

case 5:
	 quantity = (int)getNumericInput
	 ("Enter Number of Monuments Desired: ");
	 width = getNumericInput("Enter the Width of Monuments: ");
	 thickness = getNumericInput
	 ("Enter the Thickness of Monuments: ");
	 height = getNumericInput("Enter the Height of Monuments: ");
	 order = new Monument(quantity, width, thickness, height);
	 break;

case 6:
	quantity = (int)getNumericInput
	("Enter Number of Monuments Desired: ");
	width = getNumericInput("Enter the Width of Monuments: ");
	thickness = getNumericInput
	("Enter the Thickness of Monuments: ");
	height = getNumericInput("Enter the Height of Monuments: ");
	baseThickness = getNumericInput
	("Enter the Thickness of Monument's Bases: ");
	baseDiameter = getNumericInput
	("Enter the Diameter of Monument's Bases: ");
	orderBase = new MonumentBase
   (quantity, width, thickness, height, baseThickness, baseDiameter);
	base = true;
	break;

case 7:
	 JOptionPane.showMessageDialog
	 (null, "EXITING PROGRAM PER USER REQUEST\nTHANK YOU!!",
	 "Message", JOptionPane.INFORMATION_MESSAGE);
	 break;
//Switch statements ends here ---->

//Degault statement if incorrect choice entered:
default:
	 JOptionPane.showMessageDialog
	 (null, "An Incorrect Choice Was Entered\n"+
	 "Please Re-Run Program", "****ERROR****",
	 JOptionPane.ERROR_MESSAGE);
	 System.exit(1);
	 }

//Checking if order contains Base or not:
if (base == true)
    displayOutputBase(orderBase);
else
    displayOutput(order);
	}

//Displays Output for Monument Order ---->
private static void displayOutput(Monument order)
 {
	if(order.getTotalPrice() > 0)
	 {
		JOptionPane.showMessageDialog(null,
		 String.format("Number of Monuments: %d\n" +
		 "Width of Monuments: %.2f Inches\n" +
		 "Height of Monuments: %.2f Inches\n" +
		 "Thickness of Monuments: %.2f Inches\n" +
		 "Cubic Inches of WunderRock Required: %.2f\n" +
		 "Cubic Feet of WunderRock Required: %.2f\n" +
		 "Retail Price of Order: $%.2f",
		  order.getQuantity(), order.getWidth(), order.getHeight(),
		  order.getThickness(), order.getCubicInches(),
		  order.getCubicFeet(),
		  order.getTotalPrice()),
		 "ORDER SPECIFICATIONS", JOptionPane.INFORMATION_MESSAGE);
	 }
	 // Message if error while placing order:
	 else
		 JOptionPane.showMessageDialog(null,
		 "*****Order Contains Errors*****" +
		 "\n*****Do Not Process!*****", "*****ERROR*****",
		  JOptionPane.ERROR_MESSAGE);
	}

//Display Output for MonumentBase Order --->
private static void displayOutputBase(MonumentBase order) {
if(order.getTotalPrice() > 0)
   {
    JOptionPane.showMessageDialog(null,
	String.format("Number of Monuments: %d\n" +
	"Width of Monuments: %.2f Inches\n" +
	"Height of Monuments: %.2f Inches\n" +
	"Thickness of Monuments: %.2f Inches\n" +
	"Radius of Base: %.2f Inches\n" +
	"Diameter of Base: %.2f Inches\n" +
	"Thickness of Base: %.2f Inches\n" +
	"Cubic Inches of WunderRock Required: %.2f\n" +
	"Cubic Feet of WunderRock Required: %.2f\n" +
	"Retail Price of Order: $%.2f",
	 order.getQuantity(), order.getWidth(), order.getHeight(),
	 order.getThickness(), order.getBaseRadius(),
	 order.getBaseDiameter(),
	 order.getBaseThickness(), order.getCubicInches(),
	 order.getCubicFeet(),
	 order.getTotalPrice()),
	 "ORDER SPECIFICATIONS", JOptionPane.INFORMATION_MESSAGE);
	}
//Error while placing MonumentBase Order --->

else
	JOptionPane.showMessageDialog
	(null, "*****Order Contains Errors*****" +
    "\n*****Do Not Process!*****", "*****ERROR*****",
	JOptionPane.ERROR_MESSAGE);
	}

private static double getNumericInput(String prompt) {
	return Double.parseDouble(JOptionPane.showInputDialog
	(null, prompt));
	}
 }

Edited 4 Years Ago by maverick420: n/a

I'm sorry it's not textbox but JOptionPane which shows user a list and asks to make a choice, there should be no value in it but when you run the code there is value of "3" which is choice 3 already present in it. Below is the code for it, thank you for your reply

public static void main(String args[]) {
int selection = 0;
Monument order = null;
MonumentBase orderBase = null;
selection = getSelection();
createOrder(selection);
System.exit(0); // GUI closing
}
 
/**
  * Method getSelection to get user input
  f*/
private static int getSelection() {
String stringSelection = " ";
int numericSelection = 0;
 
stringSelection = JOptionPane.showInputDialog(null,
"Make a Selection\n"
+ "1: For Default Monument Only Order\n" +
"2: For Default MOnument Plus Base Order\n" +
"3: Default Monument Only Dimensions >>> Greather Than 5\n" +
"4: Defualt Monument and Base Dimensions >>> Greather Than 5\n" +
"5: Monument only >>> Enter All Dimensions And Quantity\n" +
"6: Monument AND Base >>> Enter All Dimensions And Quantity\n" +
"7: EXIT PROGRAM\n" +
"Enter 1, 2, 3, 4, 5, 6 or 7 ONLY!", JOptionPane.QUESTION_MESSAGE);
numericSelection = Integer.parseInt(stringSelection);
return numericSelection; //Return selection

You are passing JOptionPane.QUESTION_MESSAGE (which is a final static int in the JOptionPane class) as parameter where JOptionPane expects the input that you want as default. change your JOptionPane to:

stringSelection = JOptionPane.showInputDialog(null,
"Make a Selection\n"
+ "1: For Default Monument Only Order\n" +
"2: For Default MOnument Plus Base Order\n" +
"3: Default Monument Only Dimensions >>> Greather Than 5\n" +
"4: Defualt Monument and Base Dimensions >>> Greather Than 5\n" +
"5: Monument only >>> Enter All Dimensions And Quantity\n" +
"6: Monument AND Base >>> Enter All Dimensions And Quantity\n" +
"7: EXIT PROGRAM\n" +
"Enter 1, 2, 3, 4, 5, 6 or 7 ONLY!","", JOptionPane.QUESTION_MESSAGE);

the difference is in the last line

Thank you so much Problem solved!! That was the dump mistake made by me :P

stringSelection = JOptionPane.showInputDialog(null,
"Make a Selection\n"
+ "1: For Default Monument Only Order\n" +
"2: For Default MOnument Plus Base Order\n" +
"3: Default Monument Only Dimensions >>> Greather Than 5\n" +
"4: Defualt Monument and Base Dimensions >>> Greather Than 5\n" +
"5: Monument only >>> Enter All Dimensions And Quantity\n" +
"6: Monument AND Base >>> Enter All Dimensions And Quantity\n" +
"7: EXIT PROGRAM\n" +
"Enter 1, 2, 3, 4, 5, 6 or 7 ONLY!","", JOptionPane.QUESTION_MESSAGE);
numericSelection = Integer.parseInt(stringSelection);
return numericSelection; //Return selection
This article has been dead for over six months. Start a new discussion instead.