In: Computer Science
Hi, Please find the solution. Please use the ways of coding in this answer to achieve what you need, Thanks.
import java.time.LocalDate; public class RescueAnimal { int age; float weight; float height; public RescueAnimal() { placement = new Placement(); } LocalDate obtainedDate; String obtainedLocation;//keeping simple int lagtimeInHoursBeforeTraining; LocalDate graduationDate; LocalDate serviceStartDate; Placement placement; Status status; Breeds breeds; Phases phase; Gender gender; enum Gender{ MALE,FEMALE; } enum Status { INTAKE, TRAINING, INSERVICE, FARM; } enum Phases { PHASE1, PHASE2, PHASE3, PHASE4, PHASE5; } enum Breeds { Americanpitbullterrier, Beagle, BelgianMalinois, Bordercollie, Bloodhound, Coonhound, Englishspringerspaniel, Germanshepherd, Germanshorthairedpointer, Goldenretriever, Labradoretriever, NovaScotiaducktollingretriever, Roughcollie, Smoothcollie; } public float getHeight() { return height; } public void setHeight(float height) { this.height = height; } class Placement{ String agency,city,country,name,email,address,mailAddress,phoneNoAgency; @Override public String toString() { return "Placement{" + "agency='" + agency + '\'' + ", city='" + city + '\'' + ", country='" + country + '\'' + ", name='" + name + '\'' + ", email='" + email + '\'' + ", address='" + address + '\'' + ", mailAddress='" + mailAddress + '\'' + ", phoneNoAgency='" + phoneNoAgency + '\'' + '}'; } public String getAgency() { return agency; } public void setAgency(String agency) { this.agency = agency; } 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 String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getMailAddress() { return mailAddress; } public void setMailAddress(String mailAddress) { this.mailAddress = mailAddress; } public String getPhoneNoAgency() { return phoneNoAgency; } public void setPhoneNoAgency(String phoneNoAgency) { this.phoneNoAgency = phoneNoAgency; } } @Override public String toString() { return "RescueAnimal{" + "age=" + age + ", weight=" + weight + ", height=" + height + ", obtainedDate=" + obtainedDate + ", obtainedLocation='" + obtainedLocation + '\'' + ", lagtimeInHoursBeforeTraining=" + lagtimeInHoursBeforeTraining + ", graduationDate=" + graduationDate + ", serviceStartDate=" + serviceStartDate + ", placement=" + placement + ", status=" + status + ", breeds=" + breeds + ", phase=" + phase + ", gender=" + gender + '}'; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public float getWeight() { return weight; } public void setWeight(float weight) { this.weight = weight; } public LocalDate getObtainedDate() { return obtainedDate; } public void setObtainedDate(LocalDate obtainedDate) { this.obtainedDate = obtainedDate; } public String getObtainedLocation() { return obtainedLocation; } public void setObtainedLocation(String obtainedLocation) { this.obtainedLocation = obtainedLocation; } public int getLagtimeInHoursBeforeTraining() { return lagtimeInHoursBeforeTraining; } public void setLagtimeInHoursBeforeTraining(int lagtimeInHoursBeforeTraining) { this.lagtimeInHoursBeforeTraining = lagtimeInHoursBeforeTraining; } public LocalDate getGraduationDate() { return graduationDate; } public void setGraduationDate(LocalDate graduationDate) { this.graduationDate = graduationDate; } public LocalDate getServiceStartDate() { return serviceStartDate; } public void setServiceStartDate(LocalDate serviceStartDate) { this.serviceStartDate = serviceStartDate; } public Placement getPlacement() { return placement; } public void setPlacement(Placement placement) { this.placement = placement; } public Status getStatus() { return status; } public void setStatus(Status status) { this.status = status; } public Breeds getBreeds() { return breeds; } public void setBreeds(Breeds breeds) { this.breeds = breeds; } public Phases getPhase() { return phase; } public void setPhase(Phases phase) { this.phase = phase; } public Gender getGender() { return gender; } public void setGender(Gender gender) { this.gender = gender; } }
import java.time.LocalDate; import java.util.Scanner; public class Main { public static void main(String[] args) { RescueAnimal dog = new RescueAnimal(); Scanner sc = new Scanner(System.in); Main x = new Main(); x.rescueAnimal(dog,sc); System.out.println(dog); } public void rescueAnimal(RescueAnimal dog,Scanner sc){ System.out.println("Enter weight"); dog.setWeight(sc.nextFloat()); System.out.println("Enter height"); dog.setHeight(sc.nextFloat()); System.out.println("Enter (f)for female (m) for male"); dog.setGender(sc.next().charAt(0)=='f'? RescueAnimal.Gender.FEMALE:RescueAnimal.Gender.MALE); System.out.println("Is the dog in INTAKE(i), TRAINING(t), INSERVICE(s), FARM(f)?"); char c = sc.next().toLowerCase().charAt(0); if(c =='i'){ dog.setStatus(RescueAnimal.Status.INTAKE); } if(c =='s'){ dog.setStatus(RescueAnimal.Status.INSERVICE); } if(c =='f'){ dog.setStatus(RescueAnimal.Status.FARM); } if(c =='t'){ dog.setStatus(RescueAnimal.Status.TRAINING); } System.out.println("Which Phase 1,2,3,4,5"); int choice = sc.nextInt(); if(choice==1){ dog.setPhase(RescueAnimal.Phases.PHASE1); }if(choice==2){ dog.setPhase(RescueAnimal.Phases.PHASE2); }if(choice==3){ dog.setPhase(RescueAnimal.Phases.PHASE3); }if(choice==4){ dog.setPhase(RescueAnimal.Phases.PHASE4); }if(choice==5){ dog.setPhase(RescueAnimal.Phases.PHASE5); } System.out.println("Enter lagtimeInHoursBeforeTraining"); dog.setLagtimeInHoursBeforeTraining(sc.nextInt()); // System.out.println(""); int i=1; for (RescueAnimal.Breeds br: RescueAnimal.Breeds.values()){ System.out.println("Enter "+i++ + " for "+br.toString()); } choice = sc.nextInt(); dog.setBreeds(RescueAnimal.Breeds.values()[choice-1]); System.out.println("Enter Graduation date: dd"); int day = sc.nextInt(); System.out.println("Enter Graduation Date:mm"); int month = sc.nextInt(); System.out.println("Enter Graduation Date:yyyy"); int year = sc.nextInt(); LocalDate graDate = LocalDate.of(year, month, day); System.out.println("Service start date: dd"); day = sc.nextInt(); System.out.println("Service start date:mm"); month = sc.nextInt(); System.out.println("Service start date:yyyy"); year = sc.nextInt(); LocalDate serviceDate = LocalDate.of(year, month, day); dog.setServiceStartDate(serviceDate); dog.setGraduationDate(graDate); System.out.println("Agency name?"); // dog.placement = new RescueAnimal() RescueAnimal.Placement placement = dog.placement; placement.setAgency(sc.next()); System.out.println("Agency address?"); placement.setAddress(sc.next()); System.out.println("Agency city?"); placement.setCity(sc.next()); System.out.println("Agency Country?"); placement.setCountry(sc.next()); System.out.println("Agency Email?"); placement.setEmail(sc.next()); System.out.println("Agency Mail addrsss?"); placement.setMailAddress(sc.next()); System.out.println("Agency Phone number?"); placement.setPhoneNoAgency(sc.next()); dog.setPlacement(placement); return; } } Sample out: