Simulations and game code I will like to improve my code in Java involving creating simulations and games. This is a problem-solving code so far in interest and percentage calculations.

import javax.swing.JOptionPane;
class interest {
    public static void main(String[] args){
        String name = JOptionPane.showInputDialog( "Item" );
        String message = String.format( "Word is, %s, is Items", name );

        JOptionPane.showMessageDialog( null, message ); 

        String firstNumber = JOptionPane.showInputDialog( "Enter QuantitySold Double " );
        String secondNumber = JOptionPane.showInputDialog( "Enter UnitCost Double " );
        String thirdNumber = JOptionPane.showInputDialog( "Enter OriginalPrice Double " );
        String fourthNumber = JOptionPane.showInputDialog( "Enter lowedPercentagePrice Double " );

        Double QuantitySold = Double.parseDouble( firstNumber );
        Double UnitCost = Double.parseDouble( secondNumber );
        Double OriginalPrice = Double.parseDouble( thirdNumber );
        Double LowedPercentagePrice = Double.parseDouble( fourthNumber );
        Double TotalCost = QuantitySold * UnitCost ;

        JOptionPane.showMessageDialog( null, " TotalCost is " + TotalCost, "TotalCost of Two Doubles", 
        JOptionPane.PLAIN_MESSAGE );

        Double PercentagePrice = LowedPercentagePrice / 100;
        Double PricePercentage = OriginalPrice * PercentagePrice ; 
        Double TotalPrice = OriginalPrice - PricePercentage; 

        JOptionPane.showMessageDialog( null, " TotalPrice is " + TotalPrice, "TotalPrice of Two Doubles", JOptionPane.PLAIN_MESSAGE );
    }
}
class interest


In Java, class names are CasedLikeThis (pascal cased). Interest would be a proper name.



Name those strings more appropriately.

String firstNumber = JOptionPane.showInputDialog( "Enter QuantitySold Double " );


is a case of inappropriate naming. firstNumber is not a numeric value, it's a string. It's also not a "first string", it's a string that is supposed to represent the sold quantity, which is to be parsed as a double.

String rawQuantitySold = JOptionPane.showInputDialog("Enter QuantitySold Double");


would be a first step towards improvement.



You don't check for input validity. What if the user inputs some garbage, and not a valid string representation of a numeric value? Consider extracting the input bits, and forming a loop that continues for as long as the user inserts invalid data.

NumericType getNumericValue(String messageForUser)
{
     while (true)
     {
          String rawInput = JOptionPane.showInputDialog(messageForUser);
          if (canBeParsedToNumericType(rawInput))
          {
                return parseToNumericType(rawInput);
          }
          else
          {
               showMessage("Value has an invalid format. Please enter a valid value.");
          }
     }
}


and use it like:

Double quantitySold = getNumericValue("Enter the quantity that's been sold (floating point value).");


This also makes you get rid of the extra temporary strings there.

Tip! The else branch there is unnecessary, due to the fact that return will return immediately. You may or may not want to remove it.



Consider improving the messages you're showing to your users. 


  Enter OriginalPrice Double


is not exactly a properly formatted and user aimed message. 


  Enter the original price.


With, maybe, some info about the format that it has to have, and/or some examples would be a huge improvement.



Keep naming consistent.

String fourthNumber = JOptionPane.showInputDialog( "Enter lowedPercentagePrice Double " );
Double QuantitySold = Double.parseDouble( firstNumber );


Why is QuantitySold pascal cased, and fourthNumber camel cased? quantitySold should be your choice there.



Improve your formatting.

JOptionPane.showMessageDialog( null, message );


could become

JOptionPane.showMessageDialog(null, message);


Also,

class interest
{
public static void main(String[] args){


could be turned into

class Interest {

    public static void main(String[] args) {


and you should take a look at where you drop your braces, as well as where you drop random empty lines. If you need to separate your code in pieces with empty lines for readability, chances are you have to extract methods from there.

Consider, for example, extracting

Double PercentagePrice = LowedPercentagePrice / 100;
Double PricePercentage = OriginalPrice * PercentagePrice; 
Double TotalPrice = OriginalPrice - PricePercentage; 


into a function that calculates the total price based on some parameters that you set to it.

Double totalPrice = calculateTotalPrice(...);


Rule of thumb: if you have to split your functions in chunks using empty lines or verbose comments, you should first take a look if you couldn't extract those chunks in separate functions.