所以我正在使用封装(我是一名 tafe 学生)重新编写一些已经工作的代码,并且该方法进入第一个方法,但没有进入第二个
第一种方法:
public void getDetails() throws IOException
{
do
{
String fullName = JOptionPane.showInputDialog(null, "Enter your full name", "Input Request", JOptionPane.QUESTION_MESSAGE);
f = true;
if (fullName == null)
{
System.out.println("Program has been aborted!");
System.exit(0);
} else
{
f = true;
}
Pattern numbers = Pattern.compile("[1-9,!@#$%^&*()_+=]");
Matcher match = numbers.matcher(fullName);
if (match.find())
{
JOptionPane.showMessageDialog(null, "Incorrect!\nLetters Only", "Error", JOptionPane.ERROR_MESSAGE);
f = false;
} else if (fullName.isEmpty())
{
JOptionPane.showMessageDialog(null, "pelase enter a name!", "Error", JOptionPane.ERROR_MESSAGE);
f = false;
} else
{
f = true;
FullName fn = new FullName();
fn.setFullName(fullName);
System.out.println(fn.getFullName());
}
} while (f == false);
}
第二种方法:
public void print()
{
DecimalFormat df, df1;
df = new DecimalFormat("0.00");
FullName fn = new FullName();
System.out.println(fn.getFullName());
JOptionPane.showMessageDialog(null, fn.getFullName()+ "\nYour tax outcome is: " + "\nIncome Tax $" + incomeTax + "\nMedicare Levy $" + df.format(medicareLevy)
+ "\nTax Paid $" + taxWitheld + sReturn + "\nActual Tax Rate " + df.format(actualTaxRate) + "%");
}
setter 和 Getter 类:
public class FullName
{
private String fullName;
public FullName()
{
fullName = null;
}
public FullName(String n1)
{
fullName = n1;
}
public String getFullName()
{
return fullName;
}
public void setFullName(String name)
{
this.fullName = name;
}
}
你可能看到的任何东西都会很棒