This week's book giveaways are in the Jython/Python and Object-Oriented programming forums.
We're giving away four copies each of Machine Learning for Business: Using Amazon SageMaker and Jupyter and Object Design Style Guide and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

I Promise I won't bother you again today

 
Greenhorn
Posts: 18
  • 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
 
Bartender
Posts: 1840
Eclipse IDE Ruby Java
  • 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
  • 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
 
Ranch Hand
Posts: 1492
  • 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
  • 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
  • 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
  • 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
  • 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
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!