Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JOptionPane output spacing

807606Feb 20 2007 — edited Feb 20 2007
Can someone please help a student a.k.a. me with JOptionPane output formating?

I need to my output to look like this

SS# Hours Age etc..
123456789 12 19 etc
import javax.swing.JOptionPane;
import java.text.DecimalFormat;

public class CollegeTuition
{
  public static void main (String args[])
  {
    
    String strStatus,
    	   strGender,
    	   strSocial,
    	   strLocation,
    	   strHours,
    	   strAge;
    	   
    	   /* *****Reserved for possible future use*****
    	   strTuition,
           strActF, // Activity Fee
           strLoc, // Location
           */
           
           
  DecimalFormat df = new DecimalFormat ( "0.00" );
    double /* *****Reserved for possible future use*****
    	   inCnty = 30.00,
           outCnty = 35.00,
           outState = 40.00,
           outCtry = 45.00,
           */
           actFee = 10.00,
           tuition,
           cost,
           status;
   
    //Start Menu
    
    
    JOptionPane.showMessageDialog (null, "Welcome to Tiny College.");
    
    strStatus = JOptionPane.showInputDialog ("Please input your residential status. \n 1 = In-County \n 2 = Out of County \n 3 = Out of State \n 4 = Out of Country");
    status = Double.parseDouble (strStatus);
    
    if (status == 1)
    {
	    cost = 30.00;
	    strLocation = "In-County";
    }
    else if (status == 2)
    {
	    cost = 35.00;
	    strLocation = "Out of County";
    }
    else if (status == 3)
    {
	    cost = 40.00;
	    strLocation = "Out of State";
    }
	else
	{
		cost = 45.00;
		strLocation = "Out of Country";
	}
	    
	if ((status == 1) || (status == 2) || (status == 3))
	{
		tuition = cost + actFee;
	}
	else
	{
		tuition = cost;
	}
        
    strGender = JOptionPane.showInputDialog ("Please enter your gender. \n M for male \n F for female");
    strAge = JOptionPane.showInputDialog ("Please enter your Age");
    strHours = JOptionPane.showInputDialog ("Please enter your credit hours");
    strSocial = JOptionPane.showInputDialog ("Please enter you Social Security Number with no dashes");
	
    //output += "/strSocial/strHours/strLocation/strGender/strAge/df.format(tuition)\n";
    //JScrollPane jsp = new JScrollPane(new JTextArea(output));
    //jsp.setPreferredSize(new java.awt.Dimension(400, 200));
	//JOptionPane.showMessageDialog (null, jsp, "College Enrollment", JOptionPane.INFORMATION_MESSAGE, null /* "SS#" + strSocial + "Hours" + "Location" + strLocation + "Gender" + strGender + "Age" + strAge + "Tuition" + df.format(tuition)*/);
	//JOptionPane.showMessageDialog (null, "SS#" + strSocial + "Hours" + strHours + "Location" + strLocation + "Gender" + strGender + "Age" + strAge + "Tuition" + df.format(tuition));
	JOptionPane.showMessageDialog (null, "/*not working %5s%7s%10s%8s%5s%9s */, SS#, Hours, Location, Gender, Age, Tuition \n" 
   	       + strSocial + strHours + strLocation + strGender + strAge + df.format(tuition));
   }
 }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 20 2007
Added on Feb 20 2007
6 comments
1,618 views