Answer:
public class Registration {
private String fname;
private String lname;
private int noCredits;
private double additionalFee;
public Registration(String fname, String lname, int noCredits, double additionalFee) {
this.fname = fname;
this.lname = lname;
this.noCredits = noCredits;
this.additionalFee = additionalFee;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public int getNoCredits() {
return noCredits;
}
public void setNoCredits(int noCredits) {
this.noCredits = noCredits;
}
public double getAdditionalFee() {
return additionalFee;
}
public void setAdditionalFee(double additionalFee) {
this.additionalFee = additionalFee;
}
public void showBill(){
System.out.println("The bill for "+fname+ " "+lname+ " is "+(70*noCredits+additionalFee));
}
}
THE CLASS WITH MAIN METHOD
public class RegistrationTest {
public static void main(String[] args) {
Registration student1 = new Registration("John","James", 10,
5);
Registration student2 = new Registration("Peter","David", 9,
13);
System.out.println("Initial bill for the two students: ");
student1.showBill();
student2.showBill();
int newCreditStudent1 = student1.getNoCredits()+3;
int newCreditStudent2 = student2.getNoCredits()-3;
student1.setNoCredits(newCreditStudent1);
student2.setNoCredits(newCreditStudent2);
System.out.println("Bill for the two students after adjustments of credits:");
student1.showBill();
student2.showBill();
}
}
Step-by-step explanation:
- Two Java classes are created Registration and RegistrationTest
- The fields and all methods (getters, setters, constructor) as well as a custom method showBill() as created in the Registration class as required by the question
- In the registrationTest, two objects of the class are created and initialized student1 and student2.
- The method showBill is called and prints their initial bill.
- Then adjustments are carried out on the credit units using getCredit ()and setCredit()
- The new Bill is then printed