• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I Promise I won't bother you again today

 
Elaine Banks
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay - Here is the class called "Student"
public class Banks_Student
{
private String firstName;
private String middleInit;
private String lastName;
public String degreeInit;
public Banks_Student (String firstNameIn, String middleInitIn, String lastNameIn, String degreeInitIn)
{
firstName = firstNameIn;
middleInit = middleInitIn;
lastName = lastNameIn;
degreeInit = degreeInitIn;
}

public StringBuffer getFullName ()
{
StringBuffer wholeName = new StringBuffer ();
wholeName = new StringBuffer().append(firstName).append(middleInit).append(lastName).append (degreeInit);
return wholeName;
}
=========================================================================
...and here is create student
public class Banks_CreateStudent
{
String [] [] degreeList = {
{"AS", " AA", " BS", " BA", " MS", " MA", " PhD"},
{"Associate of Science", "Associate of Arts", "Bachelor of Science", "Bachelor of Arts", "Master of Science", "Master of Arts", "Doctor"}
};
public String addTitle(String title)
{
for (int i=0; i<7; ++i)
if (degreeList[0][i].equals(title))
{
title = degreeList [1] [i];
break;
}
return title;
}
public static void main (String [] args)
{

Banks_Student student1 = new Banks_Student ("Catherine ", "G ", "Banks ", "PhD ");
Banks_Student student2 = new Banks_Student ("Average ", "A ", "Joe ", "AA");
System.out.print (student1.getFullName());
System.out.println (student1.addTitle());
}
}
The goal is to print out the whole name along with the degree initials and the degree spelled out. It goes along fine until the "degree spelled out" part. Am I even barking up the right tree? How do I pass the "degreeInit" value to the addTitle method?
Many Thanks in Advance,
EB
 
Joel McNary
Bartender
Posts: 1824
Eclipse IDE Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me that your degree list and the addTitle() method are in the wrong class -- shouldn't they be in the Student class? This line should not compile:
 
Elaine Banks
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well...I've messed around with putting them in different classes...I had them in "student" to start with. You're right...that line won't compile...
Here...I'll post with that stuff moved over to the student class.
public class Banks_Student
{
private String firstName;
private String middleInit;
private String lastName;
public String degreeInit;
String [] [] degreeList = {
{"AS", " AA", " BS", " BA", " MS", " MA", " PhD"},
{"Associate of Science", "Associate of Arts", "Bachelor of Science", "Bachelor of Arts", "Master of Science", "Master of Arts", "Doctor"}
};
public Banks_Student (String firstNameIn, String middleInitIn, String lastNameIn, String degreeInitIn)
{
firstName = firstNameIn;
middleInit = middleInitIn;
lastName = lastNameIn;
degreeInit = degreeInitIn;
}

public StringBuffer getFullName ()
{
StringBuffer wholeName = new StringBuffer ();
wholeName = new StringBuffer().append(firstName).append(middleInit).append(lastName).append (degreeInit);
return wholeName;
}
public String addTitle(String title)
{
for (int i=0; i<7; ++i)
if (degreeList[0][i].equals(title))
{
title = degreeList [1] [i];
break;
}
return title;
}

}
=================================================================
public class Banks_CreateStudent
{

public static void main (String [] args)
{

Banks_Student student1 = new Banks_Student ("Catherine ", "G ", "Banks ", "PhD ");
Banks_Student student2 = new Banks_Student ("Average ", "A ", "Joe ", "AA");
System.out.print (student1.getFullName());
//System.out.println (student1.addTitle());
//I have this commented out because it will not compile.
}
}
====================================================
What do I need to do to print out the title spelled out next to the degree initials?
EB
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elaine,
You should avoid having the title be added by an outside source. Just have it added into your student constructor. That way you only need to store an index to get both types and names.

------------------------------------------------------------------

Regards,
Manfred.
 
Elaine Banks
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you a million times.
However, in the println - the name needs to print with the degree initials as well as the degree spelled out too.
i.e. Catherine G Banks PhD Doctor
The way you've written it it only outputs the name...no initials or degrees.
EB
 
Elaine Banks
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I've modified it to include the initials...but it still doesn't add the full degree name....
EB
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elaine,
The code I showed you gives all the information that is known to the Student class:
Catherine G Banks PhD Doctor

FirstName MiddleInitial LastName DegreeInitials DegreeName
Regards,
Manfred.
 
Elaine Banks
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate your help very much, and when I cut, pasted, compiled and ran the program it did not output the "doctor" part.
Merry Merry Christmas.
EB
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic