java - Implementation of Setter and Getter without using switch -


a pet can either cat or dog. each pet needs have name, owner’s name, color, doctor’s name , breed. of pets can cry, eat , sleep. without using switch method, tried use setter , getter function scanner. dont know how identify if user inputs dog user input dog else cat.

is possible?

package petexercise;  import java.util.scanner;  public class petcatdog {   public static void main(string[] args) {     scanner scan = new scanner(system.in);     petcat cat = new petcat();     petdog dog = new petdog();     system.out.print("enter dog or cat word:");     string pet = cat.nextline();   } } 

the other subclasses made setter , getters

so have -

user - class represent user. has name, pet info, etc. user can have many or no pets

pet - pet represents type of animals. have common attributes name, age..some common actions eat.

dog - extends pet has attributes name, age, color, breed, actions specifially dog barks, fetches balls

cat - extends pet has attributes name, age, color, breed, actions being useless sleeping twenty times day

ask user for-

  1. the user info (build user)
  2. ask if user has pet. if no pet, update user profile state no pets.
  3. if has pet, ask if have dog. if have, ask how many. read info on each dog. build user's dog profile. if no dog, update user profile indicate no dogs.
  4. if has pet, ask if have cat. if have, ask how many. read info on each cat. build user's cat profile did dog in step 3 on..

update:

for know if user entered either dog or cat, can have like-

scanner scan = new scanner(system.in);  string response;  do{         system.out.print("do have pet ? (y/n): ");     response = scan.nextline();     } while(!response.equalsignorecase("y") && !response.equalsignorecase("n"));  if(response.equalsignorecase("n")){     system.exit(0); }  do{         system.out.print("cat or dog ? (c/d): ");     response = scan.nextline();     } while(!response.equalsignorecase("c") && !response.equalsignorecase("d"));  

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -