Help with a Java Program The purpose of this assignment is to allow you to demon
ID: 3665061 • Letter: H
Question
Help with a Java Program
The purpose of this assignment is to allow you to demonstrate your understanding of aggregation. You will need the Address class you wrote in Assignment 1, so be sure to make any corrections mentioned in the feedback for Assignment 1. Task Write a class named Company with: two attributes a name and an address. The name is the name of the company and the address should be of type Address that you created in Assignment 1 The class should also have a constructor with parameters that sets the name and address attributes appropriately You must use the copy constructor created in Assignment 1 to set the address attribute. Include your usual complement of getters and setters. Lastly, include a tostring method that will be used to display the name and address of the company. Next, write a driver that will Create a Company object. Retrieve from the user, the information necessary to create the object. Remember that the Company constructor is expecting an Address object, not the street, city, state, and zip of an address. Output your company object. Here's a sample: hat is the name of the company ABC Ltd hat is the address of the company? Street ain Street 12345 ity Nowheresville State Anywhere ip Code 10011. Ltd Main Street 12345 Nowheresville, Anywhere 10011Explanation / Answer
Program:
import java.util.Scanner;
public class Company {
String name;
String []address=new String[4];
Company(String n,String[] a)
{
name=n;
address=a;
}
public static void main(String arg[])
{
String name;
String []address=new String[4];
Scanner sca=new Scanner(System.in);
System.out.print(" What is the name of your company? ");
name=sca.nextLine();
System.out.print("What is the address of the company? ");
System.out.print("Street: ");
address[0]=sca.nextLine();
System.out.print("City : ");
address[1]=sca.nextLine();
System.out.print("State : ");
address[2]=sca.nextLine();
System.out.print("Zip Code : ");
address[3]=sca.nextLine();
Company obj=new Company(name,address);
System.out.println(" "+name);
System.out.println(address[0]);
System.out.print(address[1]+ ", "+ address[2] + " "+address[3] );
}
}
Result:
What is the name of your company? ABC Ltd.
What is the address of the company?
Street: 12345 Main Street
City : Nowheresville
State : Anywhere
Zip Code : 10011
ABC Ltd.
12345 Main Street
Nowheresville, Anywhere 10011
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.