Click here to Skip to main content
15,885,546 members
Home / Discussions / Java
   

Java

 
GeneralRe: JAVA_REGEX_WHITESPACE _CHARACTER Pin
Sudhanshu_India2-Mar-22 0:43
Sudhanshu_India2-Mar-22 0:43 
GeneralRe: JAVA_REGEX_WHITESPACE _CHARACTER Pin
Richard Deeming2-Mar-22 2:06
mveRichard Deeming2-Mar-22 2:06 
GeneralRe: JAVA_REGEX_WHITESPACE _CHARACTER Pin
Sudhanshu_India2-Mar-22 14:28
Sudhanshu_India2-Mar-22 14:28 
GeneralRe: JAVA_REGEX_WHITESPACE _CHARACTER Pin
Richard MacCutchan2-Mar-22 21:39
mveRichard MacCutchan2-Mar-22 21:39 
GeneralRe: JAVA_REGEX_WHITESPACE _CHARACTER Pin
Sudhanshu_India3-Mar-22 4:23
Sudhanshu_India3-Mar-22 4:23 
GeneralRe: JAVA_REGEX_WHITESPACE _CHARACTER Pin
RedDk3-Mar-22 16:54
RedDk3-Mar-22 16:54 
GeneralRe: JAVA_REGEX_WHITESPACE _CHARACTER Pin
Richard Deeming3-Mar-22 21:25
mveRichard Deeming3-Mar-22 21:25 
GeneralDynamic Polymorphism Pin
Sudhanshu_India24-Feb-22 2:38
Sudhanshu_India24-Feb-22 2:38 
In the noted line i have problem.where i am doing error so that i am not getting old address and new address? Rest of the things are showing expected result.
-----------------------------------


Java
public void displayCustomerDetails(Address address) {
		System.out.println("Displaying customer details \n***************************");
		System.out.println("Customer Id : " + customerId); //can also use this.customerid
		System.out.println("Customer Name : " + customerName); //can also use this.customerName
		System.out.println("Contact Number :"+ contactNumber);
		System.out.println("Customer Address : " +this.getAddress());  //Here I want to print old address:confused: 
		
System.out.println();
	}
	
	
	public void updateDetails(Address address) {            //Association
		System.out.println("Updating customer address...");
		this.setAddress(address);
		System.out.println("New Customer Address :"+ " "+this.getAddress() ); //Here i want to print new address:confused:
	}



My Code
--------------

Customer Class
----------------------
Java
public class Customer {
	private String customerId;
	private String customerName;
	private long contactNumber;
	private Address address;        //Aggregation
	public Customer(String customerId, String customerName, long contactNumber, Address address) {   // Constructors and other methods
		this.customerId = customerId;
		this.customerName = customerName;
		this.contactNumber = contactNumber;                            
		this.address = address;
	}
	public String getCustomerId() {
		return customerId;
	}
	public String getCustonerId() {
		return customerId;
	}
	public String getCustomerName() {
		return customerName;
	}
	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}
	public long getContactNumber() {
		return contactNumber;
	}
	public void setContactNumber(long contactNumber) {
		this.contactNumber = contactNumber;
	}
	public Address getAddress() {
		return address;
	}
	public void setAddress(Address address) {
		this.address = address;
	}
	
	public void displayCustomerDetails(Address address) {
		System.out.println("Displaying customer details \n***************************");
		System.out.println("Customer Id : " + customerId); //can also use this.customerid
		System.out.println("Customer Name : " + customerName); //can also use this.customerName
		System.out.println("Contact Number :"+ contactNumber);
		System.out.println("Customer Address : " +this.getAddress());
		System.out.println();
	}
	
	public void updateDetails(long mobile) {
		System.out.println("Updating customer contact number...");
		this.setContactNumber(mobile);
		System.out.println("New Contact Number:"+ " "+this.getContactNumber());
	}
	public void updateDetails(Address address) {            //Association
		System.out.println("Updating customer address...");
		this.setAddress(address);
		System.out.println("New Customer Address :"+ " "+this.getAddress() );
	}
}






Address Class
----------------------------
Java
public class Address {
public String homeNo;
private String street;
private  String city;
private int pin;

public Address(String homeNo, String street, String city, int pin) {

	this.homeNo = homeNo;
	this.street = street;
	this.city = city;
	this.pin = pin;
}



public String getHomeNo() {
	return homeNo;
}



public String getStreet() {
	return street;
}


public String getCity() {
	return city;
}


public int getPin() {
	return pin;
}

}




Tester Class
---------------------------------
Java
public class Tester {
	public static void main(String[] args) {
		Address custAddress = new Address("D109", "Castle Street", "London", 65436);
		
		Customer customer = new Customer("C1016", "Stephen Abram", 7856341287L,custAddress);
		
		customer.displayCustomerDetails(custAddress );
		Address newAddress = new Address("D119"," St. Louis Street", "Springfield", 62729);	
		
		
		Long newContact = 7890098656L;
		
		
		
		customer.updateDetails(newContact); //calls the updateDetails(long mobile) - based on the parameter
        customer.updateDetails(newAddress); //calls the updateDetails(Address address) - based on the parameter	
       
}
}



output
--------------

Displaying customer details 
***************************
Customer Id : C1016
Customer Name : Stephen Abram
Contact Number :7856341287
Customer Address : Demo1.Address@123a439b    // see here it is not printing actual old address:confused:

Updating customer contact number...
New Contact Number: 7890098656
Updating customer address...
New Customer Address : Demo1.Address@7de26db8   // see it is not printing new address :confused:


modified 3-Mar-22 12:09pm.

QuestionRe: Dynamic Polymorphism Pin
Richard MacCutchan24-Feb-22 3:27
mveRichard MacCutchan24-Feb-22 3:27 
AnswerRe: Dynamic Polymorphism Pin
Sudhanshu_India24-Feb-22 4:26
Sudhanshu_India24-Feb-22 4:26 
GeneralRe: Dynamic Polymorphism Pin
Richard MacCutchan24-Feb-22 4:56
mveRichard MacCutchan24-Feb-22 4:56 
GeneralRe: Dynamic Polymorphism Pin
Sudhanshu_India25-Feb-22 0:42
Sudhanshu_India25-Feb-22 0:42 
GeneralRe: Dynamic Polymorphism Pin
Richard MacCutchan25-Feb-22 0:51
mveRichard MacCutchan25-Feb-22 0:51 
GeneralRe: Dynamic Polymorphism Pin
Sudhanshu_India25-Feb-22 1:09
Sudhanshu_India25-Feb-22 1:09 
GeneralRe: Dynamic Polymorphism Pin
Richard MacCutchan25-Feb-22 1:17
mveRichard MacCutchan25-Feb-22 1:17 
GeneralRe: Dynamic Polymorphism Pin
Sudhanshu_India25-Feb-22 1:20
Sudhanshu_India25-Feb-22 1:20 
GeneralRe: Dynamic Polymorphism Pin
englebart11-Mar-22 11:56
professionalenglebart11-Mar-22 11:56 
QuestionJava programming Pin
Member 1554066219-Feb-22 0:02
Member 1554066219-Feb-22 0:02 
AnswerRe: Java programming Pin
OriginalGriff19-Feb-22 0:03
mveOriginalGriff19-Feb-22 0:03 
GeneralRe: Java programming Pin
MarkTJohnson22-Feb-22 7:23
professionalMarkTJohnson22-Feb-22 7:23 
GeneralRe: Java programming Pin
ramisthand764-Mar-22 23:26
ramisthand764-Mar-22 23:26 
GeneralRe: Java programming Pin
OriginalGriff5-Mar-22 0:24
mveOriginalGriff5-Mar-22 0:24 
QuestionJSP -> JavaBean Connectivity Issue Pin
Josh Hebert6-Feb-22 12:40
Josh Hebert6-Feb-22 12:40 
AnswerRe: JSP -> JavaBean Connectivity Issue Pin
Josh Hebert6-Feb-22 12:42
Josh Hebert6-Feb-22 12:42 
QuestionRe: JSP -> JavaBean Connectivity Issue Pin
Richard MacCutchan7-Feb-22 0:44
mveRichard MacCutchan7-Feb-22 0:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.