🌙 DARK

CUSTOMER ADDRESS USING STRING BUILDER - Wrapper Class

 


Customer Address Using String Builder

Write a Java Program to display the address of the customer in a particular format using StringBuilder.
 
[Note :
Strictly adhere to the object-oriented specifications given as a part of the problem statement.
Use the same class names and member variable names. ]
 
Consider another class file Address with the following private members.
Data TypeVariable name
Stringline1
Stringline2
Stringcity
Stringcountry
IntegerzipCode
Include appropriate getters and setters.
 
Use the 'toString' method in the Address class and append using String Builder.

Consider the class Main. In the main method read address details as input and display the details by printing the address objects.
 

The link to download the template code is given below
Code Template
 

Input and Output Format:
Refer sample input and output for formatting specifications. 
 
[All text in bold corresponds to input and the rest corresponds to output] 
 

Sample Input & Output:

Enter Address Details :
Enter Line 1 :
152, South Block
Enter Line 2 :
Raisina Hill
Enter City :
New Delhi
Enter Country :
India
Enter Zip Code :
110011
Address Details :
152, South Block,
Raisina Hill,
New Delhi - 110011
India



Object Oriented Requirements:

@MRProgrammer89 


CREATE CLASS < Address :

public class Address {

    private String line1;

    private String line2;

private String city;

private String country;

private int zipCode;

public   Address() {

super();

// TODO Auto-generated method stub

}

public Address(String line1,String line2,String city,String country,int zipCode) {


           super();

           this.line1 = line1;

           this.line2 = line2;

           this.city = city;

           this.country = country;

           this.zipCode = zipCode;

}

           

           

public String getLine1() {

return line1;

}

public void setLine1(String line1) {

this.line1 = line1;

}

public String getLine2() {

return line2;

}


public void setLine2(String line2) {

this.line2 = line2;

}

public String getCity() {

return city;

}


public void setCity(String city) {

this.city = city;

}

public String getCountry() {

return country;

}

public void setCountry(String country) {

this.country = country;

}

public int getZipCode() {

return zipCode;

}

public void setZipCode(int zipCode) {

this.zipCode = zipCode;

}

@Override

public String toString() {

return "Address Details :\n"+new StringBuilder().append(this.getLine1())+",\n"+new StringBuilder().append(this.getLine2())+",\n"+new StringBuilder().append(this.getCity())+

"-"+new StringBuilder().append(this.getZipCode())+"\n"+new StringBuilder().append(this.getCountry());

}


}


@MRProgrammer89 


CREATE CLASS < Main :



import java.io.IOException;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {

    

        Scanner sc =new Scanner(System.in);

        System.out.println("Enter Address Details :\nEnter Line 1 :");

        String line1=sc.nextLine();

        System.out.println("Enter Line 2 :");

        String line2=sc.nextLine();

        System.out.println("Enter City :");

        String city=sc.nextLine();

        System.out.println("Enter Country :");

         String country=sc.nextLine();

        System.out.println("Enter Zip Code :");

         int zipCode=sc.nextInt();

        

        

        Address address =new Address(line1,line2,city,country,zipCode);

        System.out.println(address.toString());

}

}




String API : split()

 

Write a program to split a string based on spaces (there may be multiple spaces too) and returns the string into separate word.

 

Input Format:

 

Input consists of a string.

 

Output Format:

 

Refer sample output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to output.]

 

Sample Input and Output :

 

Enter the string

ABCD Technologies is a private organization

The words in the string are

ABCD

Technologies

is

a

private

organization


@MRProgrammer89 


CREATE CLASS < Main :

import java.util.Scanner;

public class Main {

    public static void main(String[] args)  {

Scanner sc = new Scanner(System.in);

    System.out.println("Enter the string");

String name = sc.nextLine();

String arr[] = name.split(" ");

System.out.println("The words in the string are");

for(String i:arr) {

System.out.println(i);

}

}

}





String API : startsWith() : Illustration


Write a program to illustrate the use of the method startsWith() defined in the string API.

 

Input and Output Format:
 

Refer sample input and output for formatting specifications.

All text in bold corresponds to input and the rest corresponds to output.

 

Sample Input and Output 1:
 

Enter the string

Technology

Enter the start string

Logic

"Technology" does not start with "Logic"

 

Sample Input and Output 2:

Enter the string

Technology

Enter the start string

Tech

"Technology" starts with "Tech"


@MRProgrammer 


CREATE CLASS < Main :


import java.util.Scanner;

public class Main {

public static void main(String[] args) throws Exception {

      Scanner sc = new Scanner(System.in);

      System.out.println("Enter the string");

      String name = sc.nextLine();

      System.out.println("Enter the start string");

      String start = sc.nextLine();

      

      if(name.startsWith(start)) {

          System.out.println("\""+name+"\""+" starts with "+"\""+start+"\"");

          

      }

      else {

          System.out.println("\""+name+"\""+" does not start with "+"\""+start+"\"");

          

      }

      

      

}

}




@MRProgrammer89 






MOTIVATION :


    “The way we spend our time defines who we are 


Although we may not see each other as often as we’d like, distance is no match for the bond that we share. Thank you for coming to visit. It was fantastic to catch up.


VISITE MORE BLOGS




THANK YOU....😊

Post a Comment

Thanks for reading the blog. We hope it was useful to you and that you learned something new. Will always be writing on new and interesting topics, so you can visit our website to know the latest updates of our blogs. Thank You!

Previous Post Next Post

Contact Form