Writing Classes Test Part 2- 40%
star
star
star
star
star
Last updated over 1 year ago
2 questions
20
Directions :: Write a Cheetah class. Cheetah will have name, speed, and size properties. Name is a String, speed is a double, and size is an integer. You must provide instance variables, constructors, and methods for class Cheetah. Use the runner code below.
Cheetah cat = new Cheetah( "kitty", 87.0, 8 ); //sets name, speed, and size
cat.speedUp( 3 ); //increases speed by 3
System.out.println( cat.isFast() ); //cat’s speed is greater than 50//returns true
cat.getsBigger( 1 ); //adds one to size
System.out.println( cat.isBig() ); //cat’s size if less than 10//returns false
Directions :: Write a Cheetah class. Cheetah will have name, speed, and size properties. Name is a String, speed is a double, and size is an integer. You must provide instance variables, constructors, and methods for class Cheetah. Use the runner code below.
Cheetah cat = new Cheetah( "kitty", 87.0, 8 ); //sets name, speed, and size
cat.speedUp( 3 ); //increases speed by 3
System.out.println( cat.isFast() ); //cat’s speed is greater than 50
//returns true
cat.getsBigger( 1 ); //adds one to size
System.out.println( cat.isBig() ); //cat’s size if less than 10
//returns false
20
Directions :: Write a class named Ostrich. Ostrich should have one instance variable / field named speed that is of type double. Ostrich should have two constructors. One constructor will be a default with no parameters. One constructor will be an initializer that takes in a parameter of type double. Ostrich will have a print method.
Directions :: Write a class named Ostrich. Ostrich should have one instance variable / field named speed that is of type double. Ostrich should have two constructors. One constructor will be a default with no parameters. One constructor will be an initializer that takes in a parameter of type double. Ostrich will have a print method.