Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //the Testet class
- //the main
- import java.util.Scanner;
- public class Tester {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Scanner s= new Scanner(System.in);
- String name,color,favFood;
- int whiskers,battelsNum;
- Cat c1=new Cat("Tom","Grey",50);
- StreetCat c2=new StreetCat("Mini","Yellow",40,3);
- SiamiCat c3=new SiamiCat("Boosy","White",30,"fish");
- //receiving data for a streetCat
- System.out.println("Enter a cat's name");
- name=s.next();
- System.out.println("Enter a cat's color");
- color=s.next();
- System.out.println("Enter the cat's whiskers length (cm)");
- whiskers=s.nextInt();
- System.out.println("Enter how many times the cat got envolved in a battel");
- battelsNum=s.nextInt();
- StreetCat c4=new StreetCat(name,color,whiskers,battelsNum);
- //recieving data for a siamiCat
- System.out.println("Enter a cat's name");
- name=s.next();
- System.out.println("Enter a cat's color");
- color=s.next();
- System.out.println("Enter the cat's whiskers length (cm)");
- whiskers=s.nextInt();
- System.out.println("enter the cat's favourite food");
- favFood=s.next();
- SiamiCat c5=new SiamiCat(name,color,whiskers,favFood);
- System.out.println(c1);
- System.out.println(c2);
- System.out.println(c3);
- System.out.println(c4);
- System.out.println(c5);
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ///the Cat class
- //////////////////////////////
- public class Cat {
- protected String _name,_color;
- protected int _whiskers;//in centimeters
- //constructor for all fields
- public Cat(String _name, String _color, int _whiskers) {
- super();
- this._name = _name;
- this._color = _color;
- this._whiskers = _whiskers;
- }
- //toString for all fields
- @Override
- public String toString() {
- return "Cat [_name=" + _name + ", _color=" + _color + ", _whiskers=" + _whiskers + "]";
- }
- }
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //the StreetCat class
- //////////////////////////////////////
- public class StreetCat extends Cat {
- protected int _battelsNum;
- //constructor for all fields
- public StreetCat(String _name, String _color, int _whiskers,int _battelsNum) {
- super(_name, _color, _whiskers);
- this._battelsNum=_battelsNum;
- // TODO Auto-generated constructor stub
- }
- //toString for all fields
- @Override
- public String toString() {
- return super.toString()+ "StreetCat [_battelsNum=" + _battelsNum + "]";
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- ///the SiamiCat class
- ///////////////////////////////////////////////
- public class SiamiCat extends Cat {
- protected String _favFood;
- //constructor for all fields
- public SiamiCat(String _name, String _color, int _whiskers,String _favFood) {
- super(_name, _color, _whiskers);
- this._favFood=_favFood;
- // TODO Auto-generated constructor stub
- }
- //toStrin for all fields
- @Override
- public String toString() {
- return super.toString()+"SiamiCat [_favFood=" + _favFood + "]";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement