Win a copy of Securing DevOps this week in the Security forum!

Aaron Rose

Greenhorn
+ Follow
since Sep 08, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Aaron Rose

I am trying to make a method which can be called in main that calculates the average participation of a group of students. In the student class I have a method which will generate and return a random number 1 through 10 when called upon. However I want a method in my group class that will gather and return the total participation of a group. Here is the source code. I feel like this should be so easy from here but I can't understand the logical way to do this in java. Also, if there are any baseball fans out there, don't make fun of my Pirates :P.





4 years ago
Thank you for the fast responses! I hope to be able to call this place my new home for Java.

I don't think I understood what it meant to "call" a method. Thus I have wrote something that should call the method in java.app: System.out.println("student name is" + st.getName());

Now what I am not sure of is, where in a class can a method be called? Or rather, where would be the best place to insert that line to get it to display the student information.

Thanks in advance for the help.
4 years ago
I am an IT major and am required to take Java. I have a very basic understanding of C++ as I took a course over 5 years ago and do not remember much. Programming has always been tough for me to understand and I am having trouble completing the first homework for this course. I don't expect or really want to be given the answer to such a simple problem. I hope that this site will be able to help me for this semester and the future as I embark on a journey to be able to truthfully say I can write basic java programs. Of the program I am going to post, I get the gist of what everything in the code is however I do not know where or what I should type in the student.java file in order to return student information when the program is run. I guess what I am asking is, where do I need to create this method and what is REQUIRED to connect these two classes and display the data I want. Any tips would be greatly appreciated to a novice such as me.

This problem should be very simple but here is where I am stuck. I don't know how to create a method inside of student.java that returns

Using the classes below (app and student) create a solution for returning the complete student information using a method in the class student.


public class app
{
public static void main(String args[])
{
String initName = "John";
String lastName = "Smith";
int age = 22;
student st = new student(initName,lastName,age);
}
}



class student
{
String firstName;
String lastName;
int age;

student(String informedFirstName, String informedLastName, int informedAge)
{
firstName = informedFirstName;
lastName = informedLastName;
age = informedAge;
}

String getName()
{
return firstName +" "+lastName;
}

}
4 years ago