aspose file tools*
The moose likes Beginning Java and the fly likes I Promise I won't bother you again today Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I Promise I won Watch "I Promise I won New topic
Author

I Promise I won't bother you again today

Elaine Banks
Greenhorn

Joined: Dec 16, 2003
Posts: 18
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

Joined: Aug 20, 2001
Posts: 1815
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:


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Elaine Banks
Greenhorn

Joined: Dec 16, 2003
Posts: 18
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

Joined: Jan 09, 2001
Posts: 1492
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

Joined: Dec 16, 2003
Posts: 18
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

Joined: Dec 16, 2003
Posts: 18
Now I've modified it to include the initials...but it still doesn't add the full degree name....
EB
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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

Joined: Dec 16, 2003
Posts: 18
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I Promise I won't bother you again today
 
Similar Threads
help please
Sorting things.... **a generic meltdown**
Thanks anyway
need help plss
How to set default values in an spring form input?