그래서 내가하지만 두 번째자바 게터의 첫 번째 GET 후 얻는 방법이 아니라 두 번째
을의 방법은 첫째 메도에서 점점 일부 이미 작업을 캡슐화를 사용하여 코드 (임 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,[email protected]#$%^&*()_+=]");
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) + "%");
}
세터와 게터 클래스 :
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;
}
}
당신이 볼 수있는 것은 놀라운 것
'getDetails()'에 주어진 이름을'print()'에 표시하겠습니까? – kiheru
그것은 단지 내 테스트 방법입니다. 세부 정보를 얻고 그 결과를 표시하고 싶었습니다. 다른 방법으로는 getter setter 메서드로 바뀌지 않았습니다. – Callum
무엇이 모를 때 도움이 어렵습니다. 정확히 당신이 성취하려고 노력하고 있습니다. print()에서'fn.getFullName()'은 해당 FullName 인스턴스에 대해'setFullName()'이 호출되지 않았기 때문에'null '을 반환합니다 *. 아마도'getDetails()'를'FullName'을 리턴하게 만들고 싶지 않을 것입니다. 그렇지 않으면 인스턴스에 메소드가 있습니다. – kiheru