Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a question regarding Java.
I have this class
public class TestProgram {
  public static void main(String[] args) {
  Student s = new Student("Olof", "Andersson", 2);
  s.addCourse("Declarative programming");
  s.addCourse("Logic I");

    Student q = new Student(); 
    q.setName("Goran", "M."); 
    q.setCurrentCourse("Philosophy of Information"); 
    System.out.println(s.getName() + " is taking course in " + s.getCurrentCourse()); 
    System.out.println(q.getName() + " is taking course in " + q.getCurrentCourse());

// I have the following methods

public Student() //constructor
public Student(String, String) //constructor
public Student(String, String, int) // constructor
public void setName(String, String)
public String getName()
public void setCurrentCourse(String)
public String getCurrentCourse()
public void setYear(int)
public int getYear()
public void addCourse(String) // add the argument to finishedCourses
public void print() // print out info about student and call printCourses()
private void printCourses()

The class Student have the following class variables
name, surname, year, currentCourse, and finishedCourses

I want the following result from the program

Name: Olof Andersson
Year: 2
Currently taking course in ItaSAfA
Finished courses:
Declarative programming
Logic I

Incomplete information about the student.

Name: Goran M.
Year: 3
Currently taking course in Philosophy of Information
Finished courses:

Olof Andersson is taking course in ItaSAfA
Goran M. is taking course in Philosophy of Information

Can do the class Student looks like?

Best regads


What I have tried:

Pls help me, new in Java. Do not how to start.
Updated 21-Sep-21 3:23am

"Do not how to start."
You start by writing the code for the declared methods. If you really do not understand what to do then I suggest going to Java Tutorials Learning Paths[^], where all will be revealed.
Share this answer
ninaandersson 21-Sep-21 9:23am    
Can you give some code examples
Richard MacCutchan 21-Sep-21 9:24am    
There are plenty of examples in the tutorials. You cannot expect anyone here to do your work for you.
CPallini 21-Sep-21 9:33am    
While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Share this answer
CPallini 21-Sep-21 9:33am    
OriginalGriff 21-Sep-21 10:03am    
It's amazing how much more complicated beginner exercises are these days - when I was starting out we had to print "Hello world!" rather than write a full DB application from scratch in the first week ... :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900