java - OOP School work (beginner) -


as is, compile.

bug = printing breed , declawed statements on same line. cannot rid of bug reason

bug = unable result logic compile , print console (newb)

there examples little mine posted haven't done because not think i'm supposed going for. 1 worked perfect uses , array , aren't part yet in course. here teachers instructions , tips gave me , code far. of commented out since i'm trying rid of bugs before printing result. did change of names convenience until assignment complete. sorry formatting issues. advice?

in order:

  1. assignment instruction class file
  2. tip teacher
  3. class file code far
  4. assignment driver file
  5. driver file code far

    1. assignment instructions class file:

create new class called cat includes functionality below

the new class has attributes of: name – type string age – type integer weight – type double breed - type string declawed - type boolean - true has no claws, false has claws

be sure classes have reasonable complement of constructor, accessor , mutator methods. every member variable must have @ least 1 independent accessor , 1 independent mutator.

example: public void setname(string name) mutator used set name public void setbreed(string breed) mutator used set breed public void set(boolean declawed) used set claws or not ****(you must overload set method set declawed value)** this?** public string getname() accessor used name public string getbreed() accessor used breed public boolean getboolean() access used value of declawed

ensure use “this” reference within class when referring every instance variable or instance method of current object.

  1. tip teacher: if statement use age , claw methods @ end when print out need rest of methods. can create display method display print statements each category such name, age, etc...then becomes easier display in main method - here code in main method:

    system.out.println("the cat data entered is: \n"); mycat1.display(); mycat2.display(); mycat3.display();

  2. code class file far

/************************************************************************************************* *cat.java *jonathan nees * *cha. 6 oop *************************************************************************************************/

import java.util.scanner; public class cat {     private string name;     private int age;     private double weight;     private string breed;     private boolean declawed;      public void setname(string name)     {         this.name = name;     }      public string getname()     {     return this.name;     }      public void setage(int age)     {     this.age = age;     }      public int getage()     {     return this.age;     }      public void setweight(double weight)     {     this.weight = weight;     }      public double getweight()     {     return this.weight;     }      public void setbreed(string breed)     {         this.breed = breed;     }      public string getbreed()     {     return this.breed;     }      public void setdeclawed(boolean declawed)     {     this.declawed = declawed;     }      public boolean isdeclawed()     {     if (!this.declawed == false)     {         return true;     }     else     {         return false;     }     }      scanner input = new scanner(system.in);      public void display()     {     system.out.print("enter name of cat: ");     this.name = input.nextline();     system.out.print("enter age of cat: ");     this.age = input.nextint();     system.out.print("enter weight of cat: ");     this.weight = input.nextdouble();     system.out.print("enter breed of cat: ");     this.breed = input.nextline();         system.out.print("does cat have claws? true or false?: ");     this.declawed = input.nextboolean();     } } 
  1. assignment instructions driver file

write driver program reads in 3 pets of type cat , prints out name , age of cats claws , on 3 years old.

the following information should read in: name (as string) age (as int) weight (as double) breed (as string) declawed (as boolean)

ensure use accessor methods check age , claws.

  1. code driver file far

/************************************************************************************************* *catdriver.java *jonathan nees * *cha. 6 oop driver *************************************************************************************************/

import java.util.scanner;  public class catdriver {     public static void main(string[] args)     {     scanner input = new scanner(system.in);     cat cat1 = new cat();     cat cat2 = new cat();     cat cat3 = new cat();      cat1.display();     system.out.println();     cat2.display();     system.out.println();     cat3.display();     system.out.println();      //*for (int i=0; i<3; i++)     //{     //  system.out.println("the cats on 3 claws are:");     //  if ((!this.age() <= 3) && (this.declawed() == true))     //  {     //      system.out.println("name: " + this.name);     //      system.out.println("age: " + this.age + "years old");         //  }     //}     } } 

like said i've commented out work out bugs before doing result.

it works! sorta...

i able work. rewrote display method using setter methods , did trick. also, declawed setter method written little confusingly may want tinker it. try this:

public void display() {     system.out.print("enter name of cat: ");     this.setname(input.nextline());     system.out.print("enter age of cat: ");     this.setage(integer.valueof(input.nextline()));     system.out.print("enter weight of cat: ");     this.setweight(double.valueof(input.nextline()));     system.out.print("enter breed of cat: ");     this.setbreed(input.nextline());     system.out.print("does cat have claws? true or false?: ");     this.setdeclawed(!boolean.valueof(input.nextline())); } 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -