# Homework Help

Greenhorn
Posts: 7
Hi I am trying to create code for a student details, marks and grades.

so far, that is all I could do

The ranges for each of the assessment task marks are given below, also it is explained how to calculate the final grade:
Lab Test Mark – is an integer from 0 to 10;
Assignment1 Mark – is an integer from 0 to 20;
Assignment2 Mark – is an integer from 0 to 20;
Final exam Mark – is an integer from 0 to 50;
A total mark is the sum of the previous four marks, so it is an integer from 0 to 100.
A student passes the unit if and only if
(Assignment1 Mark + Assignment2 Mark) >= 20 and (Lab Test Mark + Final Exam Mark) >= 30
There are 5 grades, which are calculated according to the following rules:
F – if the Total Mark is less then 40;
MF – if (40 <= Total Mark < 50) or (Total Mark >= 50 but student didn’t pass);
P – if (50 <= Total Mark < 60) and student passed;
C – if (60 <= Total Mark < 70) and student passed;
D – if (70 <= Total Mark < 80) and student passed;
HD – if Total Mark >= 80;

1) The third constructor creates a student object with full name and all the marks specified. ??

(2) The “set” methods allow the user to set the assessment task marks within the specified margins, e.g. setExamMark must ensure that the examMark is in the range from 0 to 50. ??

(3) The method getGrade() returns the student’s grade, calculated as specified in the Introduction. The rest of the “get” methods simply return the values of the corresponding fields. ??

Programming2Student
private String firstName
private String surname
private int assignment1Mark;
private int assignment2Mark;
private int labTestMark;
private int examMark;
public Programming2Student()
public Programming2Student(String name, String surname)
public Programming2Student(String name,String surname,int a1, int a2, int test, int exam)
public boolean passed()
public String toString( )

(4) The method passed() returns true if this student has passed the course, and returns false otherwise.

(5) The method toString() returns a string representation of a Programming2Student object in the following printable format:
John Smith:
Assignment 1 8
Assignment 2 16
Lab Test 0
Exam 34

Jeff Verdegan
Bartender
Posts: 6109
6
Welcome to the Ranch, Angeli!

In the future, when posting code, please UseCodeTags(←click) so it will be easier to read. I've added them for you this time.

As for your question, people here will be happy to help, but you have to ask a specific question. Pick one piece of your assignment, try to do it, and post a more specific question about exactly where you're getting stuck.

Greenhorn
Posts: 7
Jeff Verdegan wrote:Welcome to the Ranch, Angeli!

In the future, when posting code, please UseCodeTags(←click) so it will be easier to read. I've added them for you this time.

As for your question, people here will be happy to help, but you have to ask a specific question. Pick one piece of your assignment, try to do it, and post a more specific question about exactly where you're getting stuck.

I'm stuck with these questions..I tried so hard, but nothing.

(1)The third constructor creates a student object with full name and all the marks specified.

(2) The “set” methods allow the user to set the assessment task marks within the specified margins, e.g. setExamMark must ensure that the examMark is in the range from 0 to 50.

(3) The method getGrade() returns the student’s grade, calculated as specified in the Introduction. The rest of the “get” methods simply return the values of the corresponding fields.

Programming2Student
private String firstName
private String surname
private int assignment1Mark;
private int assignment2Mark;
private int labTestMark;
private int examMark;
public Programming2Student()
public Programming2Student(String name, String surname)
public Programming2Student(String name,String surname,int a1, int a2, int test, int exam)
public boolean passed()
public String toString( )

(4) The method passed() returns true if this student has passed the course, and returns false otherwise .

(5) The method toString() returns a string representation of a Programming2Student object in the following printable format:
John Smith:
Assignment 1 8
Assignment 2 16
Lab Test 0
Exam 34

Henry Wong
author
Marshal
Posts: 21115
78
Angeli Angel wrote:
I'm stuck with these questions..I tried so hard, but nothing.

(1)The third constructor creates a student object with full name and all the marks specified.

What have you "tried so hard"? and what do you deem as "nothing"? We can't actually give you a hint in the right direction, if we don't know what you tried, what you achieved, or what are you confused with.

Henry

Greenhorn
Posts: 7
Henry Wong wrote:
Angeli Angel wrote:
I'm stuck with these questions..I tried so hard, but nothing.

(1)The third constructor creates a student object with full name and all the marks specified.

What have you "tried so hard"? and what do you deem as "nothing"? We can't actually give you a hint in the right direction, if we don't know what you tried, what you achieved, or what are you confused with.

Henry

Confused because I am not an expert in java. The code given is what I have tried to do but it is incomplete.

Bartender
Posts: 2854
10
Angeli Angel wrote:The code given is what I have tried to do but it is incomplete.

Hint: The second constructor is trying to do the following.
Angeli Angel wrote:(1)The third constructor creates a student object with full name and all the marks specified.

You need to fix that first.

Jeff Verdegan
Bartender
Posts: 6109
6
Angeli Angel wrote:Confused because I am not an expert in java. The code given is what I have tried to do but it is incomplete.

Our questions at this point have nothing to do with whether you're an expert in Java. They have nothing to do with Java. It's all about you picking one piece at a a time to work on, and then asking a clear, precise question about what you didn't understand.

If all you can say is "I don't know how to do any of it," then it's not likely anybody here can help you. At that point, you need to go back to page one, step one of your text or tutorial and try to get Hello World working.

The problem right now isn't Java; it's communication.

fred rosenberger
lowercase baba
Bartender
Posts: 12123
30
• 2

Start over.

Not because this is bad. I honestly didn't look at a single line. But writing 100 lines of code and THEN looking to see if it works is a BAD idea.

I never write more than 3 lines of code before I compile/correct/debug. That means I write a lot of code I throw away, but I have confidence at every point that i know what I'm trying to do. I write a lot of System.out.print() statements that say things like "i'm in THIS method" or "I'm leaving THAT method" or "Setting variable X to <whatever>".

The first time I compile, i would have basically this:

I make sure that compiles and runs. And yes, I screw that up sometimes. Then, I may add ONE member variable:

I'd compile and test THAT. and yes, I screw that up sometimes. I may then add another variable, or possible work on a setter for that variable. Actually, I'd probably write a getter first, so that I can then use the getter to test my setter.

You build up your program in teeny, tiny increments. The LESS you change/add each time you compile, the easier it is to find where the problem is and to focus on what exactly is needed to be done next.

Greenhorn
Posts: 7
Angeli Angel wrote:The code given is what I have tried to do but it is incomplete.

Hint: The second constructor is trying to do the following.
Angeli Angel wrote:(1)The third constructor creates a student object with full name and all the marks specified.

You need to fix that first.

The first constructor creates a “default” student object – it should be you – and sets all the marks to 0.
The second constructor creates a student object with specified name and surname and zero marks for all assessment tasks.
The third constructor creates a student object with full name and all the marks specified.

The constructor I created are wrong?

According to me, the default one is alright, then what should the second and third constructor do?

Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15278
39
Angeli Angel wrote:The first constructor creates a “default” student object – it should be you – and sets all the marks to 0.
The second constructor creates a student object with specified name and surname and zero marks for all assessment tasks.
The third constructor creates a student object with full name and all the marks specified.

Lines 10 - 18 is the first constructor. That looks OK - but you shouldn't call this the "default constructor" (the comment, line 10) because "default constructor" has a specific meaning in Java and that is not a default constructor. (When you don't add a constructor at all to your class, the Java compiler will automatically add one - that automatically generated constructor is called the default constructor).

What you call the "second constructor", lines 20 - 29, actually does what is described in your text above as "the third constructor".

In lines 83 - 88 you have something that looks like two other constructors, but because the name is different than the class name (Programming2Student instead of programming2student) they are not actually constructors, and you'll get compile errors if you try to compile this.

Jeff Verdegan
Bartender
Posts: 6109
6
Angeli Strada wrote:public boolean passed(), how to do this one?

Once again: What have you tried and what specific problems are you having? Nobody's just going to give you the code.

Henry Wong
author
Marshal
Posts: 21115
78

Since this post is more related to an administration question, it belongs in the ranch office forum.

Your post was moved to a new topic here.

Henry

Ulf Dittmer
Rancher
Posts: 42967
73
It seems that a complete problem description can be found at www.getacoder.com. I guess someone else got desperate finishing this homework.

Greenhorn
Posts: 7
Ulf Dittmer wrote:It seems that a complete problem description can be found at www.getacoder.com. I guess someone else got desperate finishing this homework.

That's not me. Its different and I have completed my homework, by the help of someone very nice.

Henry Wong
author
Marshal
Posts: 21115
78