For my assignment I have created a class called Agency which will store data about talent agencies and i have created the required attributes. I've also been given a data file which i will need to read from. But first i am to test my class. I can use the getter and setters fine to display my desired output but now I want to create new instance of object Agency and add the details their but i get an error message saying no suitable constructor found. I have matched the settings to my constructor or at least can't see where my mistake is. Any help thanks.
public class Agency {
//Attributes for class Agency
private String name;
private String[] address;
private String[] adminStaff;
private int phoneNumber;
private String type;
/**
*Constructor that creates object Agency
*/
public Agency() {
}
/**
* Constructor that creates object Agency with values
* #param name
* #param address
* #param adminStaff
* #param phoneNumber
* #param type
*/
public Agency(String name, String[] address, String[] adminStaff, int phoneNumber, String type) {
this.name = name;
this.address = address;
this.adminStaff = adminStaff;
this.phoneNumber = phoneNumber;
this.type = type;
}
/**
*
* #return
*/
public String getName() {
return name;
}
/**
*
* #param name
*/
public void setName(String name) {
this.name = name;
}
/**
*
* #return
*/
public String[] getAddress() {
return address;
}
/**
*
* #return
*/
public String[] getAdminStaff() {
return adminStaff;
}
/**
*
* #return
*/
public int getPhoneNumber() {
return phoneNumber;
}
/**
*
* #param phoneNumber
*/
public void setPhoneNumber(int phoneNumber) {
this.phoneNumber = phoneNumber;
}
/**
*
* #return
*/
public String getType() {
return type;
}
/**
*
* #param type
*/
public void setType(String type) {
this.type = type;
}
private String getArrayAsString(String[] a) {
String result = "";
/*for(int i = 0; i<a.length; i++)
{
result += a[i] +" ";
}*/
for(String s: a)
{
result += s + " ";
}
result = result.trim();
return result;
}
private String[] getStringAsArray(String a) {
String[] result = a.split(":");
return result;
}
public void setAddress(String Address) {
this.address = getStringAsArray(Address);
}
public void setAddress(String[] Address) {
this.address = Address;
}
public String getAddressAsString() {
return getArrayAsString(address);
}
public void setAdminStaff(String adminStaff) {
this.adminStaff = getStringAsArray(adminStaff);
}
public void setAdminStaff(String[] adminStaff) {
this.adminStaff = adminStaff;
}
public String getAdminStaffAsString() {
return getArrayAsString(adminStaff);
}
#Override
public String toString(){
return name +"\t"+ getAddressAsString() +"\t"+
getAdminStaffAsString() +"\t"+ phoneNumber +"\t"+ type + "\n";
}
}
My main Class
public class AgencyTest {
public static void main(String[] args) {
/*a.setName("Potters Talent Agency");
a.setAddress("126-182 Ashwood Road:Potters Bar:Hertfordshire EN6 2:UK");
a.setAdminStaff("Megan Speagle:Daron Spilman");
a.setPhoneNumber(2598052);
a.setType("All");
System.out.println(a.getName());
System.out.println(a.getAddressAsString());
System.out.println(a.getAdminStaffAsString());
System.out.println(a.getPhoneNumber());
System.out.println(a.getType());*/
Agency a = new Agency("Potters Talent Agency, 126-182 Ashwood Rd: Potters Bar: Hertfordshire EN6 2: UK, "
+ "Megan Speegle:Daron Spilman:Leonel Striegel:Hubert Tesoro:Nathanial Pompey, 2598052, All");
System.out.println(a);
}
}
Commented out lines work but if i try to do it all from the 'Agency a = new Agency()' line it won't work.
plz help am a novice and am probably using bad terminology so not sure if it makes sense what im trying to do.
Ok added a new constructor which takes it as one string but get an error with integer value for phonenumber.
Here's the code:
`public Agency(String csvString) {
String[] attributes =csvString.split(",");
int i = 0;
for(String s : attributes)
{
switch(i)
{
case 0:
this.name = s;
break;
case 1:
this.address = getStringAsArray(s);
break;
case 2:
this.adminStaff = getStringAsArray(s);
break;
case 3:
this.phoneNumber = getIntAsString(s);
break;
case 4:
this.type = s;
break;
}
I have tried to convert it to string but doesn't seem to work.
More Code:
private String getIntAsString(int a){
String result = Integer.toString(a);
return result;
}
public String getPhoneNumberAsString() {
return getIntAsString(phoneNumber);
}
public void setPhoneNumber(int phoneNumber){
this.phoneNumber = phoneNumber;
}
i++;
}`
Agency a = new Agency("Potters Talent Agency ... EN6 2: UK, "
+ "Megan Speegle:Daron ... 2598052, All");
is trying to call a constructor with a single string and no such constructor exists.
You need to either provide such a constructor (which will split the string into its component fields), or split the string yourself and call the current constructor with those component fields.
In the line
Agency a = new Agency("Potters [...] All");
you are basically calling a constructor that takes a single string as its argument. So the compiler is looking for such a constructor:
Agency(String properties) { ... }
This constructor does not exist. Instead you have a constructor
Agency(String name, String[] address, String[] adminStaff, int phoneNumber, String type) { ... }
which takes the arguments separately. So you must call it like so:
Agency a = new Agency(
"Potters Talent Agency",
new String[] {"126-182 Ashwood Rd", "Potters Bar", "Hertfordshire EN6 2", "UK"},
new String[] {"Megan Speegle", "Daron Spilman", "Leonel Striegel", "Hubert Tesoro", "Nathanial Pompey"},
2598052,
"All"
);
You could - alternatively - provide a constructor taking a single string, which then does some string magic to disassemble the parts. This is somewhat complex and error-prone, so I would advise not to do so.
See error is in
Agency a = new Agency("Potters Talent Agency, 126-182 Ashwood Rd: Potters Bar: Hertfordshire EN6 2: UK, "
+ "Megan Speegle:Daron Spilman:Leonel Striegel:Hubert Tesoro:Nathanial Pompey, 2598052, All");
You are simply passing one string to the constructor and there is no constructor in your class which accepts the only string as parameter.
So form your parameters properly.
Try to create object this way
String myAddress[] = "BLR India".split(" ");
String myAdmin[] = "my admin array".split(" ");
Agency a = new Agency("MyName", myAddress, myAdmin, 1235678, "myType");
You are using wrong constructor. What you have now is
Agency a = new Agency("Potters Talent Agency, 126-182 Ashwood Rd: Potters Bar: Hertfordshire EN6 2: UK, "
+ "Megan Speegle:Daron Spilman:Leonel Striegel:Hubert Tesoro:Nathanial Pompey, 2598052, All");
So it will expect a constructor with just single string argument which you don't have.
You should do something like
List<String> addr = new ArrayList<String>();
addr.add("126-182 Ashwood Rd");
addr.add("Potters bar");
addr.add("Hertfordshire EN6 2");
addr.add("UK");
List<String> adminStaff = new ArrayList<String>();
adminStaff.add("Megan Speegle");
adminStaff.add("Daron Spilman");
agency a = new Agency("Potters Talent Agency", addr.toArray(), adminStaff.toArray(),2598052, "All");
Related
My dad asked me to make a program for him that will randomly take a name, surname etc. from Excel (or CSV file) and assign employees to the work. Each person must be at work minimum once and maximum 4 times a month. Program output should look like this:
Day 1: John Smith, James Smith Day 2: Charlie Smith, Thomas Smith
And this is how my code looks like right now
public static void main(String[] args) {
String FileName = "excel.csv";
File f = new File(FileName);
String read = "";
Map<Integer, Surname>SurnameArray = new HashMap<Integer, Surname>();
try {
Scanner scanner = new Scanner(f);
while(scanner.hasNextLine()) {
read = scanner.nextLine();
String[] arraySplit = read.split(",");
int kod = Integer.parseInt(tablicaSplit[0]);
String rank = tablicaSplit[1];
String name = tablicaSplit[2];
String surname = tablicaSplit[3];
SurnameArray.put(kod, new Nazwiska(kod, rank, name, surname));
SurnameArray.get(kod).getAll();
}
} catch (FileNotFoundException e) {
System.out.println("No file!");
}
}
}
And the second class looks like this:
Class Surnames {
private int kod;
private String rank;
private String name;
private String surname;
public Surnames(int kod, String rank, String name, String surname) {
super();
this.kod = kod;
this.rank = rank;
this.name = name;
this.surname = surname;
}
public void getAll() {
System.out.println(rank + " " + name + " " + surname);
}
public int getKod() {
return kod;
}
public void setKod(int kod) {
this.kod = kod;
}
public String getRank() {
return rank;
}
public void setRank(String rank) {
this.rank = rank;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setNazwisko(String surname) {
this.surname = surname;
}
}
I'm stuck at this moment. I think that this code is more complicated than it should be. If someone could show me how can i make it or maybe there is simpler way to make something like this.
I would do it this way:
class Surnames{
private final HashSet<String> EMPLOYEES;
private ArrayList<String> positions;
Surnames(String csv){
HashSet<String> tempEMPLOYEES = new HashSet<>();
ArrayList<String> tempPositions = new ArrayList<>();
/*here the code for putting csv data ino an tempEMPLOYEE hashSet, or a static setter method doing this, as well for tempPositions, containing array list of positions remember to check
if the hashset's size is equal or lower than arrayList's*/
EMPLOYEES = tempEMPLOYEES;
positions = tempPosition;
}
public void printShift(){
for(int i = 0; i < EMPLOYEES.size(); i++){
System.out.println(positions.get(i) + "- " + EMPLOYEES.get(i));
}
}
}
Since hashSet gives different object position in the set every single run of the program, placing EMPLOYEES to positions will be random. I mentioned checking that HashSet EMPLOYEES should be less size than positions. I iterate on the hashset- every employee should get a position.
Hello I'm a bit confused with some coding problem I am trying to solve.
I have a few string arrays:
String[] firstNames= {"Fred","John","Amir", "James","Bob","Jay","Amber"};
String[] lastNames = {"Bond","Kates","Memar", "White","Marley","Brown","Nogofski"};
String[] idNumbers = {"R111111","A222222","AB11111", "KR22121","V311133","L242434","P102432"};
String[] employeeNum = {"1111","2222","3333", "4444","5555","6666","7777"};
I have to create one array and somehow organize the corresponding pieces of information provided above in the method Employee[] list = new Employee[firstNames.length];
list = listOfEmployees(firstNames,lastNames,idNumbers); // create the list of employees in one array
I started writing out the method:
public static Employee[] listOfEmployees(String[] firstName, String[]
lastName, String[] idNumber){
}
but not sure how to approach this. also not sure if my parameters are correct.
the end result is supposed to look like this:
Employee #1
first name:Fred Last Name:Bond
Id number:R111111
.
.
.
Employee #2
first name:John Last Name:Kates
Id number:A222222
and so on..
thanks in advance.
EDIT:
Employee class:
public class Employee{
private String firstName;
private String lastName;
private String idNumber;
private String employeeNumber;
private int employeeCount;
/**
* Constructor
* #param firstName first name
* #param lastName last name
* #param idNumber id number
*/
public Employee(String firstName, String lastName, String idNumber){
this.firstName = firstName;
this.lastName = lastName;
this.idNumber = idNumber;
employeeCount = 0;
}
/**
* Accessors here
*/
public String getFirstName(){
return firstName;
}
public String getLastName(){
return lastName;
}
public String getIdNumber(){
return idNumber;
}
public String getEmployeeNumber(){
return employeeNumber;
}
// mutators here
/**
* #param firstName first name
*/
public void setFirstName(String firstName){
this.firstName = firstName;
}
/**
* #param lastName last name
*/
public void setLastName(String lastName){
this.lastName = lastName;
}
/**
* #param idNumber id number
*/
public void setIdNumber(String idNumber){
this.idNumber = idNumber;
}
/**
* #param employeeNumber employee number
*/
public void setEmployeeNumber(String employeeNumber){
this.employeeNumber = "";
}
#Override
public String toString(){
String result = "First name: " + getFirstName() + "\nLast name: " + getLastName()
+ "\nId number: " + getIdNumber() + "\nEmployee number: ";
if(getEmployeeNumber() == null){
return result + "No employee number has been assigned yet!";
}
return result + getEmployeeNumber();
}
}
Please try the following:
private static Employee[] listOfEmployees(String[] firstNames, String[] lastNames, String[] idNumbers){
Employee[] list = new Employee[firstNames.length];
for(int i=0; i<list.length; i++){
list[i]=new Employee(firstNames[i], lastNames[i], idNumbers[i]);
}
return list;
}
To print the array returned by the above function, you may use:
private static void printEmployees(Employee[] employees){
for (Employee employee : employees) {
System.out.println("ID: "+employee.getIdNumber());
System.out.println("Name : "+employee.getFirstName()+" "+employee.getLastName());
System.out.println("------------------------------------");
}
}
And call them by following statement:
printEmployees(listOfEmployees(firstNames,lastNames,idNumbers));
Do a for loop and use the Employee constructor to initialize the objects:
Employee[] list = new Employee[firstNames.length];
for (int i = 0; i < firstName.length; i++) {
list[i] = new Employee(firstName[i], lastName[i] ...
}
Try this
public class Test{
public static void main(String[] args){
String[] firstNames= {"Fred","John","Amir", "James","Bob","Jay","Amber"};
String[] lastNames = {"Bond","Kates","Memar", "White","Marley","Brown","Nogofski"};
String[] idNumbers = {"R111111","A222222","AB11111", "KR22121","V311133","L242434","P102432"};
String[] employeeNum = {"1111","2222","3333", "4444","5555","6666","7777"};
List<Employee> list = new ArrayList<>();
for(int i=0;i<firstName.length();i++){
list.add(new(Employee(firstName[i],lastName[i],idNumbers[i],employeeNumber[i]))}
}}
I am sure this is something stupid, but I can't figure it out for the life of me.... In the main method, when I am trying to create new artists, I keep getting an error on the creating a new "Recording" line (ie: surfacing and pop). It is saying it requires String, String[] but is getting String, MusicCollection.Artist. And it says "actual argument MusicCollection.Artist cannot be converted to String[] by method invocation conversion.
public class MusicCollection {
private Artist[] artists = new Artist[100];
private Recording[] recordings = new Recording[200];
private int artistCount = 0;
private int recordingCount = 0;
//toString method for MusicCollection
public String toString() {
StringBuffer sb = new StringBuffer();
if (recordingCount > 0) {
sb.append(recordings[0].toString());
for (int i = 1; i < recordingCount; i++) {
sb.append("\n" + recordings[i]);
}
}
return sb.toString();
}
public class Artist {
private String name;
/**
* Construct an artist object and add it to the collection.
*
* #param name the name of the Artist
*/
public Artist(String name) {
this.name = name;
artists[artistCount++] = this;
}
/**
* Retrieve the artist as a string
*
* #return the string representation of the artist
*/
public String toString() {
return name;
}
}
public class Recording {
private String name;
private Artist[] artists = new Artist[100];
private Track[] tracks = new Track[200];
private int trackCount = 0;
public class Track {
private String name;
/**
* Construct track object and add it to the collection.
*
* #param name the name of the track
*/
public Track(String name) {
this.name = name;
tracks[trackCount++] = this;
}
/**
* Retrieve the track as a string
*
* #return the string representation of the track
*/
public String toString() {
return name;
}
}
public Recording(String name, String Artist[]) {
this.name = name;
this.artists = artists;
recordings[recordingCount++] = this;
}
public String toString() {
StringBuffer sb = new StringBuffer(name);
sb.append(" by " + artists + ": ");
if (trackCount > 0) {
sb.append(tracks[0].toString());
for (int i = 1; i < trackCount; i++) {
sb.append(", " + tracks[i]);
}
}
return sb.toString();
}
}
public static void main(String[] args) {
MusicCollection mc = new MusicCollection();
Artist sarahM = mc.new Artist("Sarah McLachlan");
Recording surfacing = mc.new Recording("Surfacing", sarahM);
Recording.Track surfacing1 = surfacing.new Track("Building a Mystery");
Recording.Track surfacing4 = surfacing.new Track("Adia");
Artist u2 = mc.new Artist("U2");
Recording pop = mc.new Recording("Pop", u2);
Recording.Track pop1 = pop.new Track("Discotheque");
Recording.Track pop5 = pop.new Track("Miami");
System.out.println(mc);
}
}
Needed to have:
public Recording(String name, Artist someArtist)
and in my Recording class, only have:
private Artist artist;
since I had already declared Artist as an array.
I also had to change this.artists = artists; to this.artists = someArtist;, since that was the variable I am passing. Worked like a charm after!
This is an Object Oriented program with two classes Catalog and Products that reads a file that contains the product name, quantity, and price, adds them to a list array, and calculate the total Price of the items. Everything works with my program except that it has a toString method that when I ran the program it prints something like this #445ea7e I think this happens because the addProducts() and getProducts(String name) on the Catalog class has to do something with the toString() and I don't know how to connect them to work.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Catalog{
private static int MAX_ITEMS = 10;
/**
* List of Products objects.
*/
private Products[] list;
private int nextItem;
/**
* Default constructor
*/
public Catalog(){
list = new Products[MAX_ITEMS];
nextItem = 0;
}
/**
* Adds an item to the list
*/
public void addProducts (String name, int quantity, double price){
**//I tried this: list[nextItem] = new Products(name, quantity, price);
//but I'm not sure if that's ok.**
}
/**
* Reads items from an input file.
*/
public void loadList(String fileName)
throws FileNotFoundException {
if ( (fileName != null) && (!fileName.equals("")) ) {
Scanner input = new Scanner(new File(fileName));
String newLine = null;
String name = null;
int quantity = 0;
double price = 0.0;
while (input.hasNextLine() && nextItem < MAX_ITEMS) {
if (input.hasNext()) {
name = input.next();
} else {
System.err.println("ERROR Not a String");
System.exit(2);
}
if (input.hasNextInt()) {
quantity = input.nextInt();
} else {
System.err.println("ERROR Not an integer");
System.exit(2);
}
if (input.hasNextDouble()) {
price = input.nextDouble();
} else {
System.err.println("ERROR Not a double");
System.exit(2);
}
list[nextItem] = new Products(name, quantity, price);
newLine = input.nextLine();
nextItem += 1;
}
}
return;
}
/**
* Calculate the total cost of products.
*/
public double getTotalPrice(){
double total = 0.0;
for(int i=0; i < nextItem; i++){
Products products = list[i];
total+=products.getTotalPrice();
}
return total;
}
/**
* Search Catalog items with a product name
*/
public Products getProducts(String name){
**//search a list for string equality using the name of the product and returns it to the caller**
}
public static void main(String[] args)
throws FileNotFoundException {
Catalog catalog= new Catalog();
catalog.loadList(args[0]);
System.out.println();
//System.out.println(toString()); **I don't know how to call toString**
System.out.println();
System.out.format("Total Price = %9.2f\n", catalog.getTotalPrice());
}
}
This is the Products class with the toString() method.
public class Products {
private String name;
private int quantity;
private double price;
/**
* Constructor.
*/
public Products(String name, int quantity, double price){
this.name = name;
this.quantity = quantity;
this.price = price;
}
/**
* Gets name of the product.
*/
public String getName(){
return this.name;
}
/**
* Gets the quantity of products.
*/
public int getQuantity(){
return this.quantity;
}
/**
* Gets the cost per product.
*/
public double getPrice(){
return price;
}
/**
* set quantity of the products.
*/
public void setQuantity(int quantity){
this.quantity=quantity;
}
/**
* Calculate the total price.
*/
public double getTotalPrice(){
return quantity * price;
}
/**
* Returns a spaced-separated list of the attributes.
*/
public String toString(){
String s=null;
s+=getName();
s+=s + " ";
s+=getQuantity();
s+=s + " ";
s+=getPrice();
return s;
}
}
This is the file with the Products information
Football 2 15.50
ChapStick 1 3.87
Book 4 10.00
You add toString() to your Catalog class as Product class :
public class Catalog {
private static int MAX_ITEMS = 10;
/**
* List of Products objects.
*/
private Products[] list;
private int nextItem;
// your old code here
// new code
#Override
public String toString() {
return "this is a catalog";
}
}
You call catalog.toString():
public static void main(String[] args)
throws FileNotFoundException {
Catalog catalog= new Catalog();
catalog.loadList(args[0]);
System.out.println();
//System.out.println(toString()); **I don't know how to call toString**
// use this line
System.out.println(catalog.toString());
System.out.println();
System.out.format("Total Price = %9.2f\n", catalog.getTotalPrice());
}
In your toString() method of Product class. you should change initialize variable from s=null; to s="";. Here is sample :
public String toString(){
String s="";
s+=getName();
s+=s + " ";
s+=getQuantity();
s+=s + " ";
s+=getPrice();
return s;
}
Hope this help :)
In your toString() method (in products class), change
String s = null;
to
String s = "";
Also, you have to make a toString method for the Catalog class in order to call it.
An example toString method for catalog class can be:
public String toString(){
String toReturn = "";
for(Products current: list){
toReturn+=current.toString()+"\n";
}
return toReturn;
}
Then if main just call, System.out.println(catalog.toString());
Try adding override to your toString method this might be the solution base on your current output.
#Override
public String toString(){
String s=null;
s+=getName();
s+=s + " ";
s+=getQuantity();
s+=s + " ";
s+=getPrice();
return s;
}
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
It's a simple program to add/remove different types of customers.
I know it's probably something simple, but has had me for a while now.
Keep getting the error,
constructor Customer in class Customer cannot be applied to the given types; required; java.lang. String, Address, char found:no arguments reason: actual and formal argument lists differ in length
I'm guessing it's something to do with the customer constructor but don't know.
public class Address
{
private String street,town;
/**
* Constructor for Address
*
* #param street The street
* #param town The town
*/
public Address (String street, String town)
{
this.street = street;
this.town = town;
}
/**
* #return The street
*/
public String getStreet()
{
return street;
}
/**
* #return The town
*/
public String getTown()
{
return town;
}
/**
* Change the street part of the address
*
* #param street The new street
*/
public void setStreet(String street)
{
this.street = street;
}
/**
* Change the town part of the address
*
* #param street The new town
*/
public void setTown(String town)
{
this.town = town;
}
public String toString()
{
return street + "\n" + town;
}
}
public class Name
{
private String fName, lName;
/**
* Constructor for Name
*
* #param fName The first name
* #param lName The last name
*/
public Name(String fName, String lName)
{
this.fName = fName;
this.lName = lName;
}
/**
* #return The first name
*/
public String getFName()
{
return fName;
}
/**
* #return The last name
*/
public String getLName()
{
return lName;
}
/**
* Amend the first name
*
* #param fName The new first name
*/
public void setFName(String fName)
{
this.fName = fName;
}
/**
* Amend the last name
*
* #param lName The new last name
*/
public void setLName(String lName)
{
this.lName = lName;
}
public String toString()
{
return fName + " " + lName;
}
}
public class Customer
{
// instance variables - replace the example below with your own
private String accountNumber;
private Address address;
private int balance;
private char customerType;
/**
* Constructor for objects of class Customer
*/
public Customer(String accountNumber, Address address, char customerType)
{
// initialise instance variables
this.accountNumber= accountNumber;
this.address= address;
balance = 0;
this.customerType=customerType;
}
/**
* Adds money to the ammount in the account
*/
public void credit(int amt)
{
balance= balance + amt;
}
/**
* removes money from the ammount in the account
*/
public void debit(int amt)
{
balance= balance - amt;
}
/**
* Returns the account number of the customer
*/
public String getAccountNumber()
{
return accountNumber;
}
/**
* returns the address of the customer
*/
public Address getAddress()
{
return address;
}
/**
* returns the balance of the customer
*/
public int getBalance()
{
return balance;
}
/**
* Returns the type of customer Bussiness or Personal
*/
public char getCustomerType()
{
return customerType;
}
public void setAddress(Address address)
{
this.address=address;
}
public String toString()
{
String output ="Account Number: " + accountNumber + "Customer Type: " + customerType + "balance: " + getBalance() + "Address: " + super.toString();
return output;
}
}
public class PersonalCustomer extends Customer
{
// instance variables
private Name name;
public PersonalCustomer(String accountNumber, Address address, Name name)
{
// initialise instance variables
this.accountNumber= accountNumber;
this.address=address;
this.name= Name;
}
public Name getName()
{
return + "Address: " + super.toString();
}
public void print()
{
System.out.println(toString());
}
public String toString()
{
String output = getFName() + getLName() + "\n" + "Account Number: " + accountNumber + "\n"
+ "Customer Type: " + customerType + "\n" + "Address: " + super.toString() + "\n"
+ "balance: " + getBalance();
return output;
}
}
The error message is saying you are calling:
new Customer();
but the customer requires a String, Address and char eg:
new Customer("Bob", new Address("Cool Street","Awesome Town"), 'a');
This seems a bit odd but the reason is that your child class implicitly calls the parent constructor if you don't.
public PersonalCustomer(String accountNumber, Address address, Name name)
{
// super(); //calls the parent constructor with no arguments without you seeing
this.accountNumber= accountNumber;
this.address=address;
this.name= Name;
}
All you need to do is change the PersonalCustomer constructor to
public PersonalCustomer(String accountNumber, Address address, Name name)
{
super(accountNumber, address, 'p'); //or whatever customer type they are supposed to get
this.name= Name;
}
If you don't define a constructor, there's an implicit no-args constructor.
But, when you define a constructor with arguments, the implicit no-rags constructor disappears.
You must have had some code prior to defining the new constructor that used the default constructor, ie new Customer(). You must define a no-args constructor to fox your problem
This little gem catches out many a new java programmer.