Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Begineer in coding please help me
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


chandumundlore
Begineer in coding please help me
1 Answer(s)      a year and 3 months ago
Posted in : Java Beginners


I have Person class{

int pid; String Pname;

//and have a Address filed of type Address not String!!!

Address add;

}

i know i should create a

class Address{

String state; Sting country; int pincode;

}

how to use this Address data type in my Person class to set address to a person object.. please help me


Advertisement
View Answers

June 4, 2013 at 5:05 PM


hi friend,

Try the following code may this will be helpful for you.

Address.java

package net.roseindia.simpleExample;

public class Address {

    String state;
    String country;
    int pincode;
    public String getState() {
        return state;
    }
    public void setState(String state) {
        this.state = state;
    }
    public String getCountry() {
        return country;
    }
    public void setCountry(String country) {
        this.country = country;
    }
    public int getPincode() {
        return pincode;
    }
    public void setPincode(int pincode) {
        this.pincode = pincode;
    }   
}

Person.java

package net.roseindia.simpleExample;

public class Person {

    int pid;
    String pName;
    Address add;

    public int getPid() {
        return pid;
    }
    public void setPid(int pid) {
        this.pid = pid;
    }
    public String getpName() {
        return pName;
    }
    public void setpName(String pName) {
        this.pName = pName;
    }
    public Address getAdd() {
        return add;
    }
    public void setAdd(Address add) {
        this.add = add;
    }   
}

Main.java

package net.roseindia.simpleExample;

public class Main {

    public static void main(String args[])
    {
        Address address = new Address();
        address.setCountry("India");
        address.setPincode(110085);
        address.setState("Delhi");

        Person person = new Person();
        person.setPid(1);
        person.setpName("Deepak");
        person.setAdd(address);     

        int pid = person.getPid();
        String name = person.getpName();
        Address add = person.getAdd();
        String country = add.getCountry();
        int pincode = add.getPincode();
        String state = add.getState();


        System.out.println(pid+" "+name+" "+state+" "+country+" "+pincode);
    }
}

Thanks.



Related Tutorials/Questions & Answers:
Begineer in coding please help me
Begineer in coding please help me  I have Person class{ int pid; String Pname; //and have a Address filed of type Address not String!!! Address... address to a person object.. please help me
problem in writing coding. Please help me.
problem in writing coding. Please help me.  Hi sir, my name is Logeswaran. I have problem in writing JSP coding for my university assigments... like? I'm really stuck on this. Please help me. By the way, I'm using Access
Advertisements
Begineer Help Help Please Thanks A million ) I am using Jcreator
Begineer Help Help Please Thanks A million ) I am using Jcreator  System.out.println(" Income Statement...(Arrays.toString(Year)); The problem of this coding is that it will show null values before
Please give me coding for this..
Please give me coding for this..  Write an application that inputs one number consisting of five digits from the user.separates the number ibto its individual digits and prints the digits separated from one another by three
please help me
please help me  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another... before. This name list should get from the database. Please help me. By the way, I'm
urgent...pleAse help me.....please!
urgent...pleAse help me.....please!  please help me urgent! how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
please help me.
please help me.  Please send me a code of template in opencms and its procedure.so i can implement the code. Thanks trinath
please help me.
please help me.  How to read a properties file in java with a suitable example. Please send me. Thanks Trinath   Please visit the following link: Java read properties file
please help me.
please help me.  Please send me the validation of this below link. the link is http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html Thanks Trinath
please help me.
please help me.  How to move the edits.jsp in below link? http://www.roseindia.net/answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html
please help me.
please help me.  I have a jsp page under that i add a list box under i get the countries through my database. so how can i do
help me please
help me please   Hello I want helping for this question , Please Write a program that reads some friendsââ?¬â?¢ names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
please help me...
please help me...  write an application that print number in the following order using a FOR-Loop 1 2 3 4 5 2 4 6 8 10 3 6 9 1215 4 8 121620 5 10152025
please help me.
please help me.  I have three table in mysql,and i hava create a excel sheet and add this sheet.but my question is in every sheet i can display one one table result.how can i do
Please help me.
Please help me.  Hi i am trinath in below there is a url.In that url there is a code of edit a jsp page.I understand that code but only one thing i not get it i.e; What is the work of "id".and what is the data type of id? http
please help me to this problem..
please help me to this problem..  i wrote a program like keyboard... inside the JTextField) but i want to make this program to let me write where i clicked (i.e allows me to write any thing at the field where i clicked
Please help me urgent...........
Please help me urgent...........  For what kind of a problem would use a Tree Set and not a Tree Map For what kind of a problem would use a Tree Map and not a Tree Set   Hello Friend, If you want to display the list
Please help me
Please help me  program for when a user enter his card number, it has to create default security pin in the database
Please help me
Please help me  Hi Sir, please send me the code for the following progrems... 1) all sets are integer type: input: set1={10,20,30,40} set2={15,25,35} output: union={10,15,20,25,30,35,40} 2) input: "Hi what
please help me
please help me  interface Test1 { String toString(); } public class Test { public static void main(String[] args) { System.out.println(new Test1() { public String toString() { return "test
help me please
help me please  how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
Please help me out
Please help me out    Description* You are hired to develop a laptop inventory information system for Sheridan College in order to keep track of the information about the laptops lent to the students. Users can add or remove data
Please help me??
Please help me??  Question_1: Using one-dimension array of primitive type elements. Objective: The purpose of this lab exercise is to practice how to declare, create and manipulate a one-dimension array of primitive type
please help me?
please help me?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
please help me
please help me  how to use two browse buttons, one browse button for displaying the first image and second for the second image along with its file path and also to display text file along with its path using layouts or panels
please help me
please help me  how to use two browse buttons, one browse button for displaying the first image and second for the second image along with its file path and also to display text file along with its path using layouts or panels
please help me here
please help me here  please show me how can this show the right output that i need please continue doing this program using only if else and do while please please" here is the problem Automatic Teller Machine [B] Balance [D
please help me here
please help me here  please show me how can this show the right output that i need please continue doing this program using only if else and do while please please" here is the problem Automatic Teller Machine [B] Balance [D
Please help me to create this coding for pizza order application using a handheld computer.....
Please help me to create this coding for pizza order application using... in the kitchen which displays the orders to be cooked. anybody please help me... ? Lemonade RM3.80 ? Fizzy orange RM4.90 The system must contain the HELP
Please help me to learn - WebSevices
Please help me to learn  Please help me to learn Java Fast
please help me to overcome this problem
please help me to overcome this problem  how to make it easy to write java code. can u please give me suggestions
 

 

 

DMCA.com