Reputation: 141
Now, I know this isn't the BankAccount.class, but it's similar to it, and I'm having problems with the final part. It's for an assignment at my college and I just need someone to point me in the right direction on what to next. I've done the first part, but I need someone to explain how to print records using PersonTester.
public class Person {
private String forename;
private String surname;
private int age;
private double height;
private String gender;
public void setForename(String x)
{
forename = x;
}
public String getForename()
{
return forename;
}
public void setSurname(String x)
{
surname = x;
}
public String getSurname()
{
return surname;
}
public void setAge(int x)
{
age = x;
}
public int getAge()
{
return age;
}
public void setHeight(double x)
{
height = x;
}
public double getHeight()
{
return height;
}
public void setGender(String x)
{
gender = x;
}
public String getGender()
{
return gender;
}}
And now the tester class:
public class PersonTester {
public static void main(String[] args)
{
}}
Thanks for the help in advance, it's quite late where I live now, so it may take a some time for me to reply if I have anymore problems.
Upvotes: 0
Views: 100
Reputation: 5
What you're probably looking for is the system.out.println() method, I am going to assume that you haven't used it before.
I will try not to give you exactly what would go into your PersonTester class, but a series of examples that will definitely help you:
system.out.println("Hello World"); // "Hello World" is printed (without quotations)
For the following examples, lets assume that the Person p's surname was set to be Brown. In other words, getSurname() would return the string "Brown".
system.out.println(p.getSurname());
/* Prints "Brown" (without quotations). */
The last concept you will probably need is concatenation, or the + symbol. Simply put, it joins strings together:
system.out.println("P's surname is " + p.getSurname() + ", nice to meet you.");
/* Prints "My surname is Brown, nice to meet you." (without quotations). */
Hopefully these few examples help you out.
Upvotes: 0
Reputation: 348
Using the Person
class that you have written, you can set the values to attributes and print them using get methods.
Person p = new Person();
p.setForename("Elizabeth");
String forename = p.getForename();
System.out.println("Forename: " + forename);
Upvotes: 3