我正在尝试创建一种方法,以便可以将“tuitionFees”和“scholarships”设置为程序用户个人资料的双倍。我不确定我是否设置正确。
import java.util.Scanner;
/**
StudentInvoice.java
Defines StudentInvoice objects
@author: Evan Fravert
*/
public class StudentInvoice {
// declare instance variables here
// constructor
// methods
// toString method (for String output)
private String studentName;
private String studentNumber;
private double tuitionFees;
private double scholarships;
public String toString() {
String output = "Name: " + studentName + "\n";
output += "Student ID Number: " + studentNumber + "\n";
output += "Tuition & Fees: " + tuitionFees + "\n";
output += "Scholarship: " + scholarships + "\n";
return output;
}
public StudentInvoice(String name, String number, double fees, double scholarship){
studentName = name;
studentNumber = number;
tuitionFees = fees;
scholarships = scholarship;
}
public boolean setStudentName(String name){
if(name.length() == 0)
{
return false;
}
else
{
studentName = name;
return true;
}
}
public boolean setStudentNumber(String number){
if(number.length() == 0)
{
return false;
}
else
{
studentNumber = number;
return true;
}
public boolean setTuitionFees(double fees){
if(fees < 0.0) {
return false;
}
else {
tuitionFees = fees;
return true;
}
}
public boolean setScholarships (double scholarship){
if(scholarship < 0.0) {
return false;
}
else {
Scholarships = scholarship;
return true;
}
}
}
}
我的班级与互动:
public class StudentInvoiceApp {
public static void main (String[] args) {
StudentInvoice Evan = new StudentInvoice("Evan Fravert");
Evan.setName("Evan Fravert");
Evan.setNumber(01234);
Evan.setTuitionFees(0.00);
Evan.setScholarship(0.00);
System.out.print(Evan);
}
}