0% found this document useful (0 votes)
13 views5 pages

Q3) Write A Java Code For Given Question - Write A ...

Uploaded by

Lucky Asr Awais
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Q3) Write A Java Code For Given Question - Write A ...

Uploaded by

Lucky Asr Awais
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Alert when this question is answered

× ★★★★★ GE T APP
4,500+ five-star reviews

  Textbook Solutions Expert Q&A Practice 

home / study / engineering / computer science / computer science questions and answers / q3)...
Find solutions for your homework

Question: Q3) write a java code for given question:  Write a


class having name RegisteredCourses. It c...

Q3) write a java code for given question:

Write a class having name RegisteredCourses. It contains coursecode , credithours and grades as
[Link] elds have getter and setter functions. Add an interface which contains a method name
submitFee that takes an argument as int and return type as String. Write another function name Show with
return type String in that interface with no arguments. Implements the above interface to
RegisteredCourses class. De ne two constructors, one default and other is parameterized to initialize the
class members . Now submitFee has to be implemented in such a way that its displays “Submitted” if
functions takes non zero value otherwise “not Submited”.Show function will display coursecode ,
credithours and [Link] Main method in another class and call only submitFee and Show method. Of
class [Link] interface don’t have constructors

Expert Answer

Anonymous
answered this

SS of the output:

SS of the RegisteredCourses class:


SS of the Interface FeeStatus:

SS of the Runner Class:

Source code for RegisteredCourses:

//the class RegisteredCourses that implements FeeStatus


public class RegisteredCourses implements FeeStatus {
private String coursecode;
private oat credithours;
private String grades;

// Parameterized constructor
public RegisteredCourses(String coursecode, oat credithours, String grades) {
super();
[Link] = coursecode;
[Link] = credithours;
[Link] = grades;
}

// default constructor
public RegisteredCourses() {
this("", 0, "");
}

// getters and setters


public String getCoursecode() {
return coursecode;
}
public void setCoursecode(String coursecode) {
[Link] = coursecode;
}

public oat getCredithours() {


return credithours;
}

public void setCredithours( oat credithours) {


[Link] = credithours;
}

public String getGrades() {


return grades;
}

public void setGrades(String grades) {


[Link] = grades;
}

//submitFee returns displays “Submitted” if fee is non zero value otherwise “not Submitted”.
@Override
public String submitFee(int fee) {
return fee > 0 ? "Submitted" : "Not Submitted";
}

//Show function returns a string containing coursecode , credithours and grade.


@Override
public String show() {
return [Link]("CourceCode: %s\nCreditHours: %.2f\nGrades: %s\n\n", coursecode,
credithours, grades);
}

Source code for Interface fee status:

public interface FeeStatus {

//the submitFee method


public String submitFee(int fee);

//the show method


public String show();

Source code for Runner class:

public class Runner {


public static void main(String[] args) {
RegisteredCourses rc = new RegisteredCourses("CS123", 23, "A+");
[Link]("Calling submit fee method: ");
[Link]("Submition status for fee=1000: " + [Link](1000));
[Link]("Submition status for fee=0: " + [Link](0));
[Link]("Submition status for fee=-150: " + [Link](-150) + "\n");

[Link]("Calling the show() method:\n" + [Link]());

}
}

Why interface don’t have constructors:

A constructor of a class is used to initialize its non-static members with respect to an object. As all data
members in interfaces are public static nal by default, there are no data members in an interface to
initialize, hence we dont need an constructor for them, so we dont have a constructor for them.

3 Comments

Was this answer helpful? 1

0
Up next for you in Computer Science

A Saiban Associates
determines the discount
percentage for house rent
by looking at the Marita…
See more questions
for subjects you study

See answer

COMPANY

LEGAL & POLICIES

CHEGG PRODUCTS AND SERVICES

CHEGG NETWORK

CUSTOMER SERVICE
© 2003-2021 Chegg Inc. All rights reserved.

You might also like