Question
Hey i have java question i need emergency help could you help me

Customer; has private variables address ,name,customerld. Address; has private variables street,city,state Following demo and output below, implement needed methods and constructors. Address adres new AddressSogutozu Street,Cankaya, Ankara): Customerll customers new Customer(3]: customers(0]-new Customer(adres,Ali Yildiz,1001); customers[1]-new Customer(customers[O]) customers(2]-customers[0].clone) customers[2).setName(Deniz Yildiz): Address adres2-new Address(Gazi Street,Yenimahalle, Ankara customers[1].setAddress(adres2); customers[1].setCustomerld 1002); customersl1].setNameizel Olcay): Address adres3 new Address( Anadolu Street, Pola,Ankara) customers[2].setAddress(adres3); customers[2].getAddress().setStreet(X) adres.setStreet(Bestepe Street adres2.setStreet(Yazici Street for(int i=0;i<customers length ) System.out.printin(customersi]) Ali Yildiz(1001) (Sogutozu Street/Cankaya/Ankara) ?zel Olcay( 1002 )(Gazi Street/Yenimahalle/Ankara) Deniz Yildiz(1001)Anadolu Street/Polatli/Ankara)
media%2F237%2F2373c927-62d8-45e6-a583-53
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Demo.java

public class Demo                                                                                                                    //class Demo begins

{

       public static void main(String[] args)                                                                            //main() starts

       {

             Address adres = new Address("Sogutozu Street", "Cankaya", "Ankara");                 //Parameterized constructor of Address class called

             Customer[] customers = new Customer[3];                                                                    //Array of Customer objects declared

             customers[0] = new Customer(adres, "Ali Yildiz", 1001);                                             //Parameterized constructor of Customer class called

             customers[1] = new Customer(customers[0]);                                                                 //Copy constructor of Customer class called

             customers[2] = customers[0].clone();                                                                       //clone() of Customer class called

             customers[2].setName("Deniz Yildiz");                                                                      //setName() of Customer class called

             Address adres2 = new Address("Gazi Street", "Yenimahalle", "Ankara");                 //Parameterized constructor of Address class called

             customers[1].setAddress(adres2);                                                                           //setAddress() of Customer class called

             customers[1].setCustomerid(1002);                                                                          //setCustomerid() of Customer class called

             customers[1].setName("Izel Olcay");                                                                              //setName() of Customer class called

             Address adres3 = new Address("Anadolu Street", "Polatli", "Ankara");                 //Parameterized constructor of Address class called

             customers[2].setAddress(adres3);                                                                           //setAddress() of Customer class called

             customers[2].getAddress().setStreet("X");                                                                  //setStreet() of Address class called by the use of getAddress() of Customer class

             adres.setStreet("Bestepe Street");                                                                               //setStreet() of Address class called

             adres2.setStreet("Yazici Street");                                                                               //setStreet() of Address class called

             for(int i = 0; i < customers.length; i++)                                                                  //Loop for output

                    System.out.println(customers[i]);                                                                   //Override method toString() of Customer class called

            

             System.out.println("-----------------------------------------------------------------------------");

            

             Address adres0 = new Address("D Street", "E City", "F State");                                 //Parameterized constructor of Address class called

             VipCustomer vipcustomer = new VipCustomer(adres0, "Merve Altan", 2001, 1);           //Parameterized constructor of VipCustomer class called

             Customer customerCopy = vipcustomer.clone();                                                        //clone() of VipCustomer class called

             VipCustomer customerCopy2 = new VipCustomer(vipcustomer);                                    //Copy constructor of VipCustomer class called

             System.out.println(customerCopy);                                                                          //Override method toString() of Customer class called

             System.out.println(customerCopy2);                                                                               //Override method toString() of Customer class called

       }                                                                                                                                            //main() ends

}                                                                                                                                                  //class Demo ends

Address.java

class Address                                                                         //class Address begins

{

       private String street, city, state;                                       //Private members declared

      

       Address()                                                                              //Default constructor

       {

             this.street = "";

             this.city = "";

             this.state = "";

       }

      

       Address(String street, String city, String state)           //Parameterized constructor

       {

             this.street = street;

             this.city = city;

             this.state = state;

       }

      

       void setStreet(String street)                                             //Function to set street

       {

             this.street = street;

       }

      

       void setCity(String city)                                                 //Function to set city

       {

             this.city = city;

       }

      

       void setState(String state)                                                     //Function to set state

       {

             this.state = state;

       }

      

       String getStreet()                                                              //Function to access or get street

       {

             return(street);

       }

      

       String getCity()                                                                //Function to access or get city

       {

             return(city);

       }

      

       String getState()                                                               //Function to access or get state

       {

             return(state);

       }

}                                                                                                   //class Address ends

Customer.java

class Customer                                                                                      //class Customer begins

{

       private Address address;                                                        //Variable declaration

       private String name;

       private int customerid;

      

       Customer()                                                                                    //Default constructor

       {

             this.address = new Address();

             this.name = "";

             this.customerid = 0;

       }

      

       Customer(Address address, String name, int customerid)             //Parameterized constructor

       {

             this.address = new Address();

             this.setAddress(address);

             this.name = name;

             this.customerid = customerid;

       }

      

       Customer(Customer cust)                                                                //Copy constructor

       {

             this.address = new Address();

             this.setAddress(cust.getAddress());

             this.name = cust.name;

             this.customerid = cust.customerid;

       }

      

       public Customer clone()                                                                //Function to return a duplicate of another object of Customer class

       {

             Customer cust = new Customer();

             cust.setAddress(this.address);

             cust.name = this.name;

             cust.customerid = this.customerid;

             return(cust);

       }

      

       void setAddress(Address ad)                                                            //Function to set address

       {

             this.address.setStreet(ad.getStreet());

             this.address.setCity(ad.getCity());

             this.address.setState(ad.getState());

       }

      

       void setName(String name)                                                       //Function to set name

       {

             this.name = name;

       }

      

       void setCustomerid(int id)                                                      //Function to set customerid

       {

             this.customerid = id;

       }

      

       Address getAddress()                                                                   //Function to access or get address

       {

             return(new Address(this.address.getStreet(), this.address.getCity(), this.address.getState()));

       }

      

       String getName()                                                                       //Function to access or get name

       {

             return(name);

       }

      

       int getCustomerid()                                                                    //Function to access or get customerid

       {

             return(customerid);

       }

      

       public String toString()                                                        //Function to override toString() which prints some other details of the class

       {

             return(name + "(" + customerid + ")(" + address.getStreet() + "/" + address.getCity() + "/" + address.getState() + ")");

       }

}                                                                                                         //class Customer ends

VipCustomer.java

class VipCustomer extends Customer                                                                        //class VipCustomer extending Customer begins

{

       private int vipNo;                                                                                         //Variable declaration

      

       VipCustomer(Address address, String name, int customerid, int vipNo)       //Parameterized constructor

       {

             setAddress(address);

             setName(name);

             setCustomerid(customerid);

             this.vipNo = vipNo;

       }

      

       VipCustomer(VipCustomer cust)                                                                       //Copy constructor

       {

             setAddress(cust.getAddress());

             setName(cust.getName());

             setCustomerid(cust.getCustomerid());

             this.vipNo = cust.vipNo;

       }

      

       public Customer clone()                                                                                    //Function to return a duplicate of another object of VipCustomer class

       {

             Customer cust = new Customer();

             cust.setAddress(getAddress());

             cust.setName(getName());

             cust.setCustomerid(getCustomerid());

             return(cust);

       }

}                                                                                                                             //class VipCustomer ends

The output screenshot is also provided for the sample code.

Kindly give a thumbs up, if found useful. Comment for any queries. :)

Add a comment
Know the answer?
Add Answer to:
Hey i have java question i need emergency help could you help me Customer; has private...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I have a java class that i need to rewrite in python. this is what i...

    I have a java class that i need to rewrite in python. this is what i have so far: class Publisher: __publisherName='' __publisherAddress=''    def __init__(self,publisherName,publisherAddress): self.__publisherName=publisherName self.__publisherAddress=publisherAddress    def getName(self): return self.__publisherName    def setName(self,publisherName): self.__publisherName=publisherName    def getAddress(self): return self.__publisherAddress    def setAddress(self,publisherAddress): self.__publisherAddress=publisherAddress    def toString(self): and here is the Java class that i need in python: public class Publisher { //Todo: Publisher has a name and an address. private String name; private String address; public Publisher(String...

  • C++ getline errors I am getting getline is undefined error messages. I would like the variables...

    C++ getline errors I am getting getline is undefined error messages. I would like the variables to remain as strings. Below is my code. #include <iostream> #include<string.h> using namespace std; int index = 0; // variable to hold how many customers are entered struct Address //Structure for the address. { int street; int city; int state; int zipcode; }; // Customer structure struct Customer { string firstNm, lastNm; Address busAddr, homeAddr; }; // Functions int displayMenu(); Customer getCustomer(); void showCustomer(Customer);...

  • Can you please help me to run this Java program? I have no idea why it...

    Can you please help me to run this Java program? I have no idea why it is not running. import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.text.DecimalFormat; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.ListSelectionModel; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; @SuppressWarnings({"unchecked", "rawtypes"}) public class SmartPhonePackages extends JFrame { private static final long serialVersionID= 6548829860028144965L; private static final int windowWidth = 400; private static final int windowHeight = 200; private static final double SalesTax = 1.06; private static JPanel panel;...

  • (Reading & Writing Business Objects) I need to have my Classes be able to talk to...

    (Reading & Writing Business Objects) I need to have my Classes be able to talk to Files. How do I make it such that I can look in a File for an account number and I am able to pull up all the details? The file should be delimited by colons (":"). The Code for testing 'Select' that goes in main is: Account a1 = new Account(); a1.select(“90001”); a1.display(); Below is what it should look like for accounts 90000:3003:SAV:8855.90 &...

  • Please help me do the java project For this project you will be reading in a...

    Please help me do the java project For this project you will be reading in a text file and evaluating it in order to create a new file that represents the Class that will represent the properties of the text file. For example, consider the following text file: students.txt ID              Name                              Age                    IsMale           GPA 1                Tom Ryan                       22                       True              3.1 2                Jack Peterson                31                       True              2.7 3                Cindy LuWho                12                       False             3.9 When you read in the header line, you...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • URGENT I have 3 hours for Submit this Homework so you can share yout codes with...

    URGENT I have 3 hours for Submit this Homework so you can share yout codes with me in 150mins Preliminary Notes: You have 4 hours to submit your solution. No late submission is accepted. Do not leave your submission to the last minute. You are not allowed to copy any code from anywhere. Your code will be checked by a software for similarity. Implement the code on your own and never share it with someone else. A test code is...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • I need help with my IM (instant messaging) java program, I created the Server, Client, and...

    I need help with my IM (instant messaging) java program, I created the Server, Client, and Message class. I somehow can't get both the server and client to message to each other. I am at a roadblock. Here is the question below. Create an IM (instant messaging) java program so that client and server communicate via serialized objects (e.g. of type Message). Each Message object encapsulates the name of the sender and the response typed by the sender. You may...

  • I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java...

    I need help writing my main method**** Computer Science 111 Introduction to Algorithms and Programming: Java Programming Project #4 – Classes and Objects (20 Points) You will create 3 new classes for this project, two will be chosen from the list below and one will be an entirely new class you invent.Here is the list: Shirt Shoe Wine Book Song Bicycle VideoGame Plant Car FootBall Boat Computer WebSite Movie Beer Pants TVShow MotorCycle Design First Create three (3) UML diagrams...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT