• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

someone please help me with this codings

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
create a class name studrec that has two private member variable. studname of type string and test of type float.ok
implement an accessor method test() that return the test marks
implement a constructor that takes in an argument S of type String for studname and the test mark us assignemnt valued.
implement a constructor that takes two argument S of type string pass to the constructorwith an argument S and test of type float for member test
implement a display()that print member variable
save the file as recstud that has an array of 5 students the students are
john
mike 84
peter 60
handsome
pretty 70
//below is what i have coded so far
class StudRec {
private String StudName;
private float test;

public StudRec(String S) { StudRec = john,mike,peter,handsome,pretty;}
public StudRec(String S, float test) {test = 84,60,70;}
public float GetTest() {return test;}
public void PrintMember() {
System.out.println ("Student Record" +S);
}
class RecStud{
public static void main(String[]args)
{array studarray=new array();
System.out.println("Student Record" +StudRec());
}//end main
}// end
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


implement a constructor that takes in an argument S of type String for studname and the test mark us assignemnt valued.


What the hell? Are you in the same class with the other poster, -- your assignment looks remarkably the same as the other one. I'll tell you, those professors are not terribly creative. Anyway, what's your question, -- you don't expect us to do your homework, do you?
P.S. Please use the "code" tags next time you post. Also, here at Java Ranch, we are very religious about the cowboys' names. You can be "Nuke X. Clear", but not "nuclearx".
Eugene.
[ March 03, 2003: Message edited by: Eugene Kononov ]
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey NuclearX, hows it going.
Im going to give this one a shot.
by the way (btw) please type your code in this format:
give me a few. Im sure that one of the other guys will help you out as well.
and btw, you are going to get a warning about your name.
peace out.
 
Brian Ngo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok sorry i had change my user name. btw can u explain to me how the heck do i implement a constructor for the code above??
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

implement a constructor that takes two argument S of type string pass to the constructor with an argument S and test of type float for member test


Sorry but I just have to jump in here.
Is this suppose to be a sentence in english? Because I have no idea what it is asking. No one here has a chance of trying to help you if they can't understand the question. And are we to believe that you were given an assignment in which the variable name was suppose to be "S"? That is hard to believe. Please try to clarify, as we would be pleased to help you out - if we understood the question.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


btw can u explain to me how the heck do i implement a constructor for the code above??


Here is a standard way of doing it:

Eugene.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


And are we to believe that you were given an assignment in which the variable name was suppose to be "S"? That is hard to believe.


Yeah, I find it hard to believe, too. But if this is the case, fire your professor before (s)he can damage your brain as a programmer. The first rule in programming is to "use meaningful variables names". This applies equally to beginners and experts as well.
Eugene.
[ March 03, 2003: Message edited by: Eugene Kononov ]
 
Brian Ngo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the string variable is S n i need help to implement a constructor to take in the argument for studname and test marks then take 2 argument of String S to pass to the constructor and test. the test is a float.
 
Brian Ngo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
u mean he has been teaching me the wrong things?? oh god he suppose to be 1 of those who knows what he is teaching.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


u mean he has been teaching me the wrong things?? oh god he suppose to be 1 of those who knows what he is teaching.


If he asks you to name a variable "S", then yes, he is a Java anti-Christ.
I encourage you to set a revolt in your class, have your professor chastised, and sue your school for hiring incompetent instructors and inflicting damage to students' brains.
Oh, and have your English professor fired, too.
Eugene.
[ March 03, 2003: Message edited by: Eugene Kononov ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brian,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

he suppose to be 1 of those who knows what he is teaching.


Well you tell him to post here and explain why he is telling his students use variable names which are only one letter long. We will set him straight.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Goes from bad to worse... :roll:
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Oh, and have your English professor fired, too.



looooooooooooooool
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To Steve: That might be funny if English is his first language, but not otherwise. And there isn't reason to assume that English is his first language, so your post is not appropriate.
Check out the forum "Meaningless Drivel" you will find lots of people there who appreaciate your sense of humor.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Check out the forum "Meaningless Drivel" you will find lots of people there who appreaciate your sense of humor.


The "Meaningless Drivel" is actually well moderated and frequently has some very serious discussions. Just check out the Porn Star - Ron Jeremy is an Al-Qaida Aide! post.
Eugene.
 
Brian Ngo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have change some part of my codes and it seems that the 1st part is correct(to me anyway)
so how to i get the code to read in the names and marks and then print out as following
john
mike 84
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


so how to i get the code to read in the names and marks and then print out as following


Here is one way of doing it:

Eugene.
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To "make" (instanciate) a StudRec for someone with a name only:

To "make" a StudRec for someone with a name and a score:

But since you will want to have multiple StudRec objects you will want to store them in an array. The array you have for StudName is an example.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brian,
Dirk did mention this before, so please do it! Thanks
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Brian, to optimize the support you get, could you possibly cut 'N' paste in here the exact assignment specification/requirements? It may help prevent a couple of wild goose chases like we have been experiencing lately around here in this forum.
Don't worry, we won't code all of it for you.
Thanks
-Barry
[ March 04, 2003: Message edited by: Barry Gaunt ]
 
Gabriel White
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Eugene, you got me in trouble bro.
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hey Eugene, you got me in trouble bro.


Well, the cowboys here have a New England, puritan-like sense of morality and Victorian appropriateness when it comes to posting. But don't worry, -- the worst that could happen to you is that the bouncer can prevent you from posting here forever (sounds like an eternity in Hell. )
Eugene.
 
Brian Ngo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well belive it or not what i have post was the exact question my lect. give us i do not understand the question also.
here is the questions again


create a class name studrec that has two private member variable. studname of type string and test of type float
implement an accessor method test() that return the test marks
implement a constructor that takes in an argument S of type String for studname and the test mark us assignemnt valued.
implement a constructor that takes two argument S of type string pass to the constructorwith an argument S and test of type float for member test
implement a display()that print member variable
save the file as recstud that has an array of 5 students the students are
john
mike 84
peter 60
handsome
pretty 70


can some1 show me how to get the result in this format
john 0.0
mike 84.0
what i am geting with my code is
john 0.0
john 84.0
john 60.0
it is printing the same name with all the float then continue to the second name eith all the numbers again

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your for loops are the same as:

So you will get 5 times 5 equals 25 lines.
I think that you want only five lines.
For every value of j, there is a name S[j] and a test mark test[j]. So you need only the outer loop (over j).
[ March 05, 2003: Message edited by: Barry Gaunt ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's my birthday today so I will make a little exception.
I'll try to follow the assignment you have just given exactly as I can.
Here's the empty class to be put in a file studrec.java:

Now here are the members, the name and test mark.

Now we add the accessor to get the test marks:

Here's the first constructor that just takes the name:

Now add the second constructor that takes a name and test mark:

Here's the method that displays the name and test mark:

Now we add a main method so you can test the class. There is an array of 5 studrecs made with the two diffrent constructors. Then there is a loop that displays the name and test mark of each of the students:

Ok that's all we can do. Compile: javac studrec.java and run: java studrec.
[ March 05, 2003: Message edited by: Barry Gaunt ]
 
William Barnes
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Barry is the only guy I know who seems to celebrate his Birthday by writing a bunch of code.
 
Brian Ngo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks alot barry u really help me alot. now i can understand better
 
Brian Ngo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and almost forgot, happy birthday barry
 
Brian Ngo
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry i have another question if i want to display only those with test marks. where is the area to change. is it here?


studrec[] students = {new studrec( "john" ), new studrec( "mike" , 84 ), new studrec( "peter", 60 ), new studrec( "handsome " ), new studrec( "pretty", 70 )};


or is it in the println area.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When printing the student's details you need to use an if to check to see whether a student (students[i]) has a test score (students[i].test()) that is greater than zero.

[ March 07, 2003: Message edited by: Barry Gaunt ]
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic