如何解决如何从另一个类调用变量
当我运行它时,我刚刚完成了Java代码,它不输出任何值。 我有两个类,一个是使用jOption输入值的类,另一个是使用第一类输入值来计算利息的类。
第1类:
public class Employee_Details {
String custName;
String custNuum;
String priice;
String Month;
int custNum;
double price;
int reMonth;
double total;
double reAmount;
public void getDetails (){
Finance_Period fin1 = new Finance_Period();
custName = JOptionPane.showInputDialog("Please enter Customer Name");
custNuum = JOptionPane.showInputDialog("Please enter Customer Number");
custNum = Integer.parseInt(custNuum);
priice = JOptionPane.showInputDialog("Please enter price of product");
price = Double.parseDouble(priice);
Month = JOptionPane.showInputDialog("Please enter number of repayment months");
reMonth = Integer.parseInt(Month);
reAmount = price/reMonth;
if (reMonth >3){
fin1.getInterest();
}
else {
total = price;
JOptionPane.showMessageDialog(null,"Customer Name: " + custName + "\n" + "Customer Conatct: " + custNum + "\n" + "Product Amount: " + "R"+price + "\n" + "Repayment Months: " + reMonth + "\n" +"Monthly Repayments: " + "R" +reAmount + "\n" + "Total Due: " + "R" + total );
}
}
}
第二堂课
public class Finance_Period {
double interest;
String name;
int num;
double product;
double amount;
public double getInterest(){
Employee_Details cust1 = new Employee_Details();
interest = (0.25 * cust1.reAmount) + cust1.reAmount;
JOptionPane.showMessageDialog(null,"Customer Name: " + cust1.custName+ "\n" + "Customer Conatct: " + cust1.custNum + "\n" + "Product Amount: " + "R"+cust1.price + "\n" + "Repayment Months: " + cust1.reMonth + "\n" +"Monthly Repayments: " + "R" + cust1.reAmount + "\n" + "Total:" + "R" + (cust1.reAmount + interest) );
return interest;
在第一堂课中,有一个if语句,如果还款月数大于3,则运行其他方法,一旦我输入的数字大于3,它将运行getinterest方法,但输出为:
我认为我没有正确链接这两个类,但是我不知道该怎么做, 我似乎在这里找不到逻辑错误,请帮帮我
这是我的主要课程
public static void main(String [] args){
Employee_Details cust1 = new Employee_Details();
cust1.getDetails();
Finance_Period fin1 = new Finance_Period();
JOptionPane.showMessageDialog(null,"Customer Name: " + cust1.custName+ "\n" + "Customer Conatct: " + cust1.custNum + "\n" + "Product Amount: " + "R"+cust1.price + "\n" + "Repayment Months: " + cust1.reMonth + "\n" +"Monthly Repayments: " + "R" + cust1.reAmount + "\n" + "Total:" + "R" + (cust1.reAmount + fin1.interest) );
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。