Need idea for start this program.....?

Consider the following Student class specification:

public Student() //CONSTRUCTOR
Initialized the attributes

public String name ()
This Student’s name

public String address()
This Student’s address

public String matric ()
This Student’s matric number

public int creditHours ()
Number of credit hours this Student enrolled in

public int fees ()
This Student’s fees for the semester

public int feesPaid ()
Amount this Student has paid so far for this semester

public void changeName(String newName)
Change the name of this Student

public void changeAddress (String newAddress)
Change the address of this Student

public void changeMatric(String newMatric)
Change the matric of this Student

public void payFees(int amout)
Pay specified amount of fees

public void registerCourses(Course course)
Register course(s) for this Student

public void displayCourses(Course course)
Display courses registered by this Student

#The methods registerCourses and displayCourses in the class Student use another class - class Course. The specification for the class Course is given:

public void registerCourses (String courses[], int numberOfCourses)
Register the courses to this Student

public void displayCourses()
Display courses registered by this Student

1. Write the complete program for the classes Student and Course above (Assume that the fees are $100 per credit hour, student can only register a maximum of 5 courses and minimum of 1 course per semester, all the attributes should be declared as private).

2. Test the above class program in a new class which has the main()method (your main() program should be interactive)

Dani AI

Generated

The code in Post #3 has a few common beginner mistakes: Java is case sensitive (class name should be Student not student), String must be capitalized, private is spelled correctly, and fields should be private per the assignment. ’ prompt ("What have you tried?") is the right attitude — a concrete, small working example makes the rest clear. Below is a compact, correct implementation that follows the original spec: private attributes, fees = $100 per credit hour, 1–5 courses enforced, and an interactive main() to test registration and payments.

// Course.java
public class Course {
    private static final int MAX = 5;
    private String[] courses = new String[MAX];
    private int numberOfCourses = 0;

    public void registerCourses(String courses[], int numberOfCourses) {
        if (numberOfCourses < 1 || numberOfCourses > MAX) {
            System.out.println("Must register between 1 and 5 courses.");
            return;
        }
        this.numberOfCourses = numberOfCourses;
        for (int i = 0; i < numberOfCourses; i++) this.courses[i] = courses[i];
    }

    public void displayCourses() {
        if (numberOfCourses == 0) {
            System.out.println("No courses registered.");
            return;
        }
        System.out.println("Courses:");
        for (int i = 0; i < numberOfCourses; i++) System.out.println((i+1) + ". " + courses[i]);
    }
}
// Student.java
public class Student {
    private String name, address, matric;
    private int creditHours, fees, feesPaid;
    private Course course;

    public Student() { this("", "", "", 0); }

    public Student(String name, String address, String matric, int creditHours) {
        this.name = name;
        this.address = address;
        this.matric = matric;
        setCreditHours(creditHours);
        this.feesPaid = 0;
    }

    public String name() { return name; }
    public String address() { return address; }
    public String matric() { return matric; }
    public int creditHours() { return creditHours; }
    public int fees() { return fees; }
    public int feesPaid() { return feesPaid; }

    public void changeName(String n) { name = n; }
    public void changeAddress(String a) { address = a; }
    public void changeMatric(String m) { matric = m; }

    private void setCreditHours(int ch) {
        creditHours = Math.max(0, ch);
        fees = creditHours * 100;
    }

    public void payFees(int amount) {
        if (amount <= 0) { System.out.println("Enter positive amount."); return; }
        int remaining = fees - feesPaid;
        if (amount > remaining) amount = remaining;
        feesPaid += amount;
    }

    public void registerCourses(Course course) { this.course = course; }
    public void displayCourses(Course course) {
        if (this.course == null) System.out.println("No courses for this student.");
        else this.course.displayCourses();
    }

    public void displaySummary() {
        System.out.println("Name: " + name + " | Matric: " + matric);
        System.out.println("Credit hours: " + creditHours + " | Fees: $" + fees + " | Paid: $" + feesPaid);
    }
}

A few practical tips and gotchas (addresses points seen in the thread): always consume the leftover newline after nextInt() when using Scanner (sc.nextLine()), validate course count is 1–5 before copying the array, and prevent negative or overpayments in payFees(). This should be a solid starting point to expand features (edit courses, persist to file, etc.).

Recommended Answers

All 3 Replies

Public class Student
{
  //TODO: Implement.
}

And

Public class Course
{
  //TODO: Implement.
}

What have you tried so far? Where do you get stuck?

public class student
{
public string name;
public string address;
public string matric ;
public int crediHours;
public int fees;
public int feesPaid;
privet int numberOfSubject;


public student(String Name,String ADDRESS,String MATRIC)

{


how to do the implement.....

there is not a single "Java for Dummies" or beginners tutorial that does not answer that question.
have you tried ask our old buddy Google yet?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.