Question

What is wrong with this Code? Fix the code errors to run correctly without error. There...

What is wrong with this Code? Fix the code errors to run correctly without error. There are four parts for one code, all are small code segments for one question.

public class StudentTest {
public static void main(String[] args){

// Part Time Student Test
Student ft1 = new PartTimeStudent("George", "Bush", "123-12-5678",
1, 2 );
System.out.println(ft1);

Student ft2 = new PartTimeStudent("Abraham", "Lincoln", "001-90-5323",
6, 22 );
System.out.println(ft2);

// Full Time Student Test
Student pt1 = new FullTimeStudent("Nikola", "Tesla", "442-00-0998",
8, 26 );
System.out.println(pt1);

Student pt2 = new FullTimeStudent("Albert", "Einstein", "675-78-2311",
10, 32 );
System.out.println(pt2);
}
}

public class Student {
private String firstName; private String lastName; private String ssn;
private int numberOfCourses; private int numberOfCredits;
private final double HOURLY_RATE = 84.0;

public Student(String firstName, String lastName, String ssn,
int numberOfCourses, int numberOfCredits) {
this.firstName = firstName;
this.lastName = lastName;
this.ssn = ssn;
this.numberOfCourses = numberOfCourses;
this.numberOfCredits = numberOfCredits;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public int getNumberOfCourses() {
return numberOfCourses;
}

public void setNumberOfCourses(int numberOfCourses) {
this.numberOfCourses = numberOfCourses;
}

public int getNumberOfCredits() {
return numberOfCredits;
}

public void setNumberOfCredits(int numberOfCredits) {
this.numberOfCredits = numberOfCredits;
}

public String getSSN() {
return ssn;
}

public void setSSN(String ssn) {
this.ssn = ssn;
}

public double calculateCostForSemester(){
return (HOURLY_RATE * numberOfCredits);
}

public String toString(){
return String.format(
"\nName: %s %s \n SSN: %s \n Course Count: %d \n Credit Hours: %d",
getFirstName(), getLastName(), getSSN(),
getNumberOfCourses(), getNumberOfCredits());
}
}

public class PartTimeStudent {

private final String STATUS = "Part Time";

public PartTimeStudent(String firstName, String lastName, String ssn,
int numberOfCourses, int numberOfCredits) {

super(firstName, lastName, ssn, numberOfCourses, numberOfCredits );
}

@Override
public double calculateCostForSemester(){

return super.calculateCostForSemester() * .9;
}

@Override
public String toString(){
return String.format(" %s\n Status: %s\n Amount Due: $%.2f",
super.toString(),
STATUS,
calculateCostForSemester());
}
}

public class FullTimeStudent extends Student {

private final String STATUS = "Full Time";

public FullTimeStudent(String firstName, String lastName, String ssn,
int numberOfCourses, int numberOfCredits) {
}

@Override
public String ToString(){
return String.format(" %s\n Status: %s\n Amount Due: $%.2f",
super.toString(),
STATUS,
super.calculateCostForSemester());
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

There is no correction in Student.java and StudentTest.java

In PartTimeStudent.java, the correction is

mistake public class PartTimeStudent
correction public class PartTimeStudent extends Student

In FullTimeStudent.java, the corrections are

mistake Constructor is missing call to the super class constructor
correction super(firstName, lastName, ssn, numberOfCourses, numberOfCredits );
mistake typographical mistake in  public String ToString()
correction public string toString()

===============================================================================================

========================================================================================

Add a comment
Know the answer?
Add Answer to:
What is wrong with this Code? Fix the code errors to run correctly without error. There...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are seven parts for one code, all are small code segments for one question. All the 'pets' need to 'speak', every sheet of code is connected. Four do need need any Debugging, three do have problems that need to be fixed. Does not need Debugging: public class Bird extends Pet { public Bird(String name) { super(name); } public void saySomething(){} } public class Cat...

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • What is wrong with this Code? Fix the code errors to run correctly without error. There...

    What is wrong with this Code? Fix the code errors to run correctly without error. There are two parts for one code (one question) the two parts branch off, one part has 2 sheets of code, the other has 3 sheets of code, all are small code segments for one question. Pt.1 - 2 sheets of code: public class Computer { private String make; private String type; private String modelNumber; private double cpuSpeed_GHz; private int ramSize_GB; private int hardDriveSize_GB; private...

  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student {    private String firstName;    private String lastName;    private String id;    private boolean tuitionPaid;       public Student(String firstName, String lastName, String id, boolean tuitionPaid)    {        this.firstName=firstName;        this.lastName=lastName;        this.id=id;        this.tuitionPaid=tuitionPaid;    }   ...

  • JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you...

    JAVA PROGRAMMING In this final review lab from our intro course, use the Name class you created in the previous lab. In this lab, create a Student class with the following class variable: Student name: Name (Note: Name is a datatype) Student Id: String Create the getter and setter methods. In addition to these methods, create a toString() method, which overrides the object class toString() method. This override method prints the current value of any of this class object. Complete...

  • Language Java Step 1: Design a class called Student. The Student class should contain the following...

    Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

  • I need help in getting the second output to show both the commission rate and the...

    I need help in getting the second output to show both the commission rate and the earnings for the String method output package CompemsationTypes; public class BasePlusCommissionEmployee extends CommissionEmployee { public void setGrossSales(double grossSales) { super.setGrossSales(grossSales); } public double getGrossSales() { return super.getGrossSales(); } public void setCommissionRate(double commissionRate) { super.setCommissionRate(commissionRate); } public double getCommissionRate() { return super.getCommissionRate(); } public String getFirstName() { return super.getFirstName(); } public String getLastName() { return super.getLastName(); } public String getSocialSecurityNumber() { return super.getSocialSecurityNumber(); } private...

  • I have currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT