I wrote a new class called Pet and I'm trying to get it connected to a pre-written class called Assignment4 for, well, an assignment. However, I can't link the two together. They're saved in the same folder on my computer, so I don't understand the problem. I get the error "cannot find symbol constructor Pet()". Here is the complete code. Thanks in advance for any help.
First Program
Second programCode:public class Pet
{
private static String petName;
private static String type;
private static BirthInfo birth;
public Pet(String petName, String type)
{
petName = "?";
type = "?";
}
public String getPetName()
{
return petName;
}
public String getType()
{
return type;
}
public BirthInfo getBirthInfo()
{
return birth;
}
public void setPetName (String pName)
{
petName = pName;
}
public void setType (String pType)
{
type = pType;
}
public void setBirthInfo(int date, int month, int year, String place)
{
birth.setDate(date);
birth.setMonth(month);
birth.setYear(year);
birth.setPlace(place);
}
public String toString()
{
return "\nPet Name:\t\t" + petName + "\nType:\t\t\t" + type +
"\nBirth Information:\t" + birth + "\n\n";
}
}
PS the BirthInfo references are for another class that I wrote, but there don't seem to be any problems linking it with the other programs.Code:import java.io.*; //to use InputStreamReader and BufferedReader
import java.util.*;
public class Assignment4
{
public static void main (String[] args)
{
// local variables, can be accessed anywhere from the main method
char input1 = 'Z';
String inputInfo;
String name, type, place;
int date, month, year;
String line = new String();
// instantiate a Pet object
Pet pet1 = new Pet();
printMenu();
//Create a Scanner object to read user input
Scanner scan = new Scanner(System.in);
do // will ask for user input
{
System.out.println("What action would you like to perform?");
line = scan.nextLine();
if (line.length() == 1)
{
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
// matches one of the case statement
switch (input1)
{
case 'A': //Add Pet
System.out.print("Please enter the pet information:\n");
System.out.print("Enter a pet name:\n");
name = scan.nextLine();
pet1.setPetName(name);
System.out.print("Enter its type:\n");
type = scan.nextLine();
pet1.setType(type);
System.out.print("Enter its birth date:\n");
date = Integer.parseInt(scan.nextLine());
System.out.print("Enter its birth month:\n");
month = Integer.parseInt(scan.nextLine());
System.out.print("Enter its birth year:\n");
year = Integer.parseInt(scan.nextLine());
System.out.print("Enter its birth place:\n");
place = scan.nextLine();
pet1.setBirthInfo(date, month, year, place);
break;
case 'D': //Display Pet
System.out.print(pet1);
break;
case 'Q': //Quit
break;
case '?': //Display Menu
printMenu();
break;
default:
System.out.print("Unknown action\n");
break;
}
}
else
{
System.out.print("Unknown action\n");
}
} while (input1 != 'Q' || line.length() != 1);
}
/** The method printMenu displays the menu to a user **/
public static void printMenu()
{
System.out.print("Choice\t\tAction\n" +
"------\t\t------\n" +
"A\t\tAdd Pet\n" +
"D\t\tDisplay Pet\n" +
"Q\t\tQuit\n" +
"?\t\tDisplay Help\n\n");
}
}
