Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Course Concept(s) Covered . Using Objects Basic Class Structure Instance Variables Instance Methods Class Variables Class Methods Instructions Create a folder called CSC1130 Writing Classes_2_yourlastname,

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Course Concept(s) Covered . Using Objects Basic Class Structure Instance Variables Instance Methods Class Variables Class Methods Instructions Create a folder called CSC1130 Writing Classes_2_yourlastname, Store all of the files for this lob in that folder. Once you have completed the lab, upload the zipped folder in Canvas Create two new source files one should be called Turtle.java and the other should be called Driver java. Do the following: Within the Turtle.java file, create a Turtle class (package level access) as follows: Class Name Turtle Data Instance variables weight (type double with private access) age (type long with private access) gender (type character with package access will eventually hold the value "M or "F) Class variable CLASSIFICATION (constant of type String with public access - value should be "Reptiles Constructor 3-argument constructor (accepts 3 arguments of appropriate type to initialize the 3 instance variables - package access Instance methods .getWeight (returns weight-private access) .getAge (returns the turtle's age private access) grow faccepts 1 parameter of type double - used to increase the weight - package access) printVitals (uses calls to the getWeight and getAge methods to neatly print these 2 values - public access) Class method printClassification (prints "Turtles are Reptiles" using the CLASSIFICATION class variable - public access) Methods . After Turtle.java compiles cleanly, write the Driver class to be used as a driver to test your Turtle class. The driver should do the following Ask the user for the information to create a Turtle Instantiate the Turtle class, using the information provided by the user as parameters to the constructor Write the appropriate code to test the printVitals, grow and printClassification methods Print the turtle's gender by directly accessing the gender instance variable from the driver Compile and execute the code Fox any errors that occur at either stage. After successful execution change the code so that the driver tries to directly call getWeight and getAge, rather than going through the printVitals method. . Try to compile the code. What happens and why? Change the code so that the driver tries to directly access the weight and age variables rather than going through the printVitals methods . Try to compile the code. What happens and why? Why can the driver directly access the gender instance variable, when it cannot directly access the age or weight variables? Change the classification from "Reptiles" to "Mammals" in the driver, . Try to compile the code. What happens and why? How does the compiler know that classification is a constant? Change the Driver class so that it has public access. Does this compile? Change the Turtle class so that it has public access. Does this compile? Create a Frog class with public access within the Driver java file below the Driver class. The Frog class should not have any code in it. In other words, your class should look like this: public class Frog 1 Does Driver java compile now? . Explain what happened as you worked through the last 3 bullet points. Under what conditions will the compiler allow you to declare a class public? Two methods in a class can have the same name as long as their parameter lists are different this phenomenon is called method overloading). Try to overload the grow method in the Turtle dass twice. One method should allow the age to be increased, and the other should allow both the weight and age to be increased when you are done, the Turtle class will have three prow methods Add method calls in the Driver to demonstrate that both of these new grow methods work correctly Comment out all of the code in the Driver class. Write a line of code that instantiates the Turtle class using the default constructor supplied by Java. . Try to compile the code. Does it compile cleanly? Comment out the 3 argument constructor in the Turtle class and try to recompile. Does it compile cleanly now? Explain what happened as you worked through the last 3 bullet points. Under what conditions will Java supply a default constructor

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago

Question

=+How will this affect the recruiting process?

Answered: 1 week ago