Hey guys! I'm new to java and I'm taking a class for college credit. I've always been interested in programming and I'm finally getting my hands dirty and I'm really enjoying it! I made the mistake however of taking my class online and theres very little help or support as well as almost no explanation of the material. Its pretty much; "Look at this example, understand it without any explanation, now make your own."
Here is my problem, we are working with Dialog boxes, (JOptionPane) I put my code bellow. I want to know how to put some of the outputs on the same line of the dialog box so that its nicely formatted the way an address actually looks. Right now I have a separate line for address street number, street name, and city, state, and zip. Typically these items are included on the same line as each other and I would like my program to be formatted as such. If anyone can help me get it formatted nice and pretty to woo my teacher I would greatly appreciate it!! Code as follows;
package Assignment2;
import javax.swing.JOptionPane;
public class Assignment2 {
public static void main(String[] args) {
//Variables
String info="", name, address, city, state, item, value;
double cost;
int quant, zip, streetnum;
double tcost, tax, ship, fcost;
//Data
name = JOptionPane.showInputDialog(null,"Enter Name","Enter Data", JOptionPane.QUESTION_MESSAGE);
value = JOptionPane.showInputDialog(null,"Enter Street #","Enter Data", JOptionPane.QUESTION_MESSAGE);
streetnum = Integer.parseInt(value);
address = JOptionPane.showInputDialog(null, "Enter Street Name","Enter Data", JOptionPane.QUESTION_MESSAGE);
city = JOptionPane.showInputDialog(null,"Enter City Name","Enter Data", JOptionPane.QUESTION_MESSAGE);
state = JOptionPane.showInputDialog(null,"Enter State","Enter Data", JOptionPane.QUESTION_MESSAGE);
value = JOptionPane.showInputDialog(null,"Enter Zip","Enter Data", JOptionPane.QUESTION_MESSAGE);
zip = Integer.parseInt(value);
item = JOptionPane.showInputDialog(null,"Enter Item","Enter Data", JOptionPane.QUESTION_MESSAGE);
value = JOptionPane.showInputDialog(null,"Enter Price","Enter Data", JOptionPane.QUESTION_MESSAGE);
cost = Double.parseDouble(value);
value = JOptionPane.showInputDialog(null,"Enter Quantity","Enter Data", JOptionPane.QUESTION_MESSAGE);
quant = Integer.parseInt(value);
//Math time
tcost = cost * quant;
tax = tcost * .07;
ship = tax * .01;
fcost = tcost + tax + ship;
//Print Invoice
info=info+name+"\n";
info=info+streetnum+"\n";
info=info+address+"\n";
info=info+city+"\n";
info=info+state+"\n";
info=info+zip+"\n";
info=info+"Item = "+item+"\n";
info=info+"Item Price = "+cost+"\n";
info=info+"Quantity = "+quant+"\n";
info=info+"Total = "+fcost+"\n";
JOptionPane.showMessageDialog(null, info,"Ship To:", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}