
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
Don't use ai to answer I will report your answer.
Class with public instance variable: step by step and solve with java
![Required Skills Inventory
• Declare an instance variable in a Java class
Initialize an instance variable in a Java class
• Implement an attribute as an instance variable in a Java class
Problem Description and Given Info
You must complete the Bunny class (in the bunny.java file) you are given below. To complete this simple class, you must declare the
following public instance variables (fields):
1. a public field named name of type String
2. a public field named age of type int
NOTE
In general, fields (instance variables) should be declared to be private. However, for this Challenge you are being asked to declare the the
fields as public.
1234567000122
8
9
Current file: Main.java
1 public class Main {
Main.java
public static void main(String[] args)
Bunny myBunny = new Bunny();
Bunny.java
Bunny yourBunny = new Bunny();
14 }
myBunny.setName("Flopsy");
myBunny.setAge(3);
yourBunny.setName("Mopsy");
yourBunny.setAge(5);
myBunny.print();
yourBunny.print();
15}
Load default template...](https://content.bartleby.com/qna-images/question/7845ab2c-c17f-457d-8bee-84c50f4b5ca5/7db7df67-925e-4282-9813-1c6a268a8136/h3hh3da_thumbnail.jpeg)
Transcribed Image Text:Required Skills Inventory
• Declare an instance variable in a Java class
Initialize an instance variable in a Java class
• Implement an attribute as an instance variable in a Java class
Problem Description and Given Info
You must complete the Bunny class (in the bunny.java file) you are given below. To complete this simple class, you must declare the
following public instance variables (fields):
1. a public field named name of type String
2. a public field named age of type int
NOTE
In general, fields (instance variables) should be declared to be private. However, for this Challenge you are being asked to declare the the
fields as public.
1234567000122
8
9
Current file: Main.java
1 public class Main {
Main.java
public static void main(String[] args)
Bunny myBunny = new Bunny();
Bunny.java
Bunny yourBunny = new Bunny();
14 }
myBunny.setName("Flopsy");
myBunny.setAge(3);
yourBunny.setName("Mopsy");
yourBunny.setAge(5);
myBunny.print();
yourBunny.print();
15}
Load default template...

Transcribed Image Text:Current file: Bunny.java❤
Load default template...
Main.java
Bunny.java
1 class Bunny {
2
// declare required fileds below
3
456782
//make no other changes to this code
public void print() {
System.out.println(" (\\\\\\\ ");
System.out.println(" (--)
");
System.out.println(" 0_(\")(\") ");
System.out.printf("%s is %d years old. \n", this.name, this.age);
9
10
11
}
12}
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps with 1 images

Knowledge Booster
Similar questions
- Please follow the directions correctly public class TestWord { public static void main(String[] args) { /* Word w1 = new Word("Go Cubs Go", "Cub"); System.out.println("New Word object"); System.out.println("Superclass word: " + w1.getSentence()); System.out.println("Subclass word: " + w1.getNoVowelsWord()); System.out.println("Is word a substring of sentence? " + w1.isSubstring()); System.out.println(); Word w2 = new Word("Applepie", "Apple"); System.out.println("New Word object"); System.out.println("Superclass word: " + w2.getSentence()); System.out.println("Subclass word: " + w2.getNoVowelsWord()); System.out.println("Is word a substring of sentence? " + w2.isSubstring()); System.out.println(); System.out.println("w1 and w2 are the same? " + w1.equals(w2)); */ } }arrow_forwardZOOM + Press Esc to exit full screen Create a new java project named CH46EX 1. Create a class named Student 1. 2 private instance data fields – student name, student id 2. 1 final and static constant for a COLLEGE, set to "Fullerton" Create one programmer written constructor that accepts parameters for two instance data fields during instantiation Create a static method named demoStaticMethod ()-see output 3. | - print message, print college 4. Create a non-static method named demoObjectMethod ()– see output - print message, college, student name, student id 2. Create an application named StudentDemo 1. Create/instantiate 1 student object 2. Call each method correctly This demo is a static method Fullerton 3. Expected Output > This demo is a non-static method Fullerton Name: Wyle Coyote ID: 456arrow_forwardsolution in python languagearrow_forward
- Answer the following: What is the correct answer?arrow_forwardAnswer the given question with a proper explanation and step-by-step solution. qns: In Java please! There is no solution on the Internet that works, please don't copy from other answers because I have checked thosearrow_forwardJava Program This assignment requires one project with two classes. Class Employee Class Employee- I will attach the code for this: //Import the required packages. import java.text.DecimalFormat; import java.text.NumberFormat; //Define the employee class. class Employee { //Define the data members. private String id, lastName, firstName; private int salary; //Create the constructor. public Employee(String id, String lastName, String firstName, int salary) { this.id = id; this.lastName = lastName; this.firstName = firstName; this.salary = salary; } //Define the getter methods. public String getId() { return id; } public String getLastName() { return lastName; } public String getFirstName() { return firstName; } public int getSalary() { return salary; } //Define the method to return the employee details. @Override public String toString() { //Use number format and decimal format //to…arrow_forward
- Find the error(s) in the following class definition: public class Circle private double radius; public double setRadius(double a) { radius = a; public void getRadius() { return radius;arrow_forwardJava true or false: The method public boolean simpleMethod() { return true; } is a valid mutator?arrow_forwardclass Bug { private final int orgPosition = 0; private int currentPosition; private boolean direction; public Bug() { direction = true; currentPosition = orgPosition; } public void move() { if (direction) { ++currentPosition; } else { --currentPosition; } } public void turn() { direction = !direction; } public int getPosition() { return currentPosition; } public boolean getDirection() { return direction; } public String toString() { StringBuffer sb = new StringBuffer(); sb.append("Position = " + currentPosition + ", Direction = "); sb.append(direction ? "RIGHT" : "LEFT"); return sb.toString(); } } -------------------------------------TestDriver.java------------------------------------- import java.util.Scanner; class TestDriver { public static void main(String args[]) { Scanner input = new Scanner(System.in); Bug b…arrow_forward
- Chapter 4 methods can be used to do math calculations and models of engineering and science problems. We describe the maths problem and use the computer to solve it and test it. Can a software on a computer solve math questions and make formulas?arrow_forwardJava Program This assignment requires one project with two classes. Class Employee Class Employee- I will attach the code for this: //Import the required packages. import java.text.DecimalFormat; import java.text.NumberFormat; //Define the employee class. class Employee { //Define the data members. private String id, lastName, firstName; private int salary; //Create the constructor. public Employee(String id, String lastName, String firstName, int salary) { this.id = id; this.lastName = lastName; this.firstName = firstName; this.salary = salary; } //Define the getter methods. public String getId() { return id; } public String getLastName() { return lastName; } public String getFirstName() { return firstName; } public int getSalary() { return salary; } //Define the method to return the employee details. @Override public String toString() { //Use number format and decimal format //to…arrow_forwardPlease help debug this: Debugging Exercise 4-3, Farrell, Joyce, Java Programming, 9th edition, Cengage Learning public class DebugBox { private int width; private int length; private int height; private FixDebugBox() { length = 1; width = 1; height = 1; } public DebugBox(int width, int length, int height) { width = width; length = length; height = height; } public void showData() { System.out.println("Width: " + width + " Length: " + length + " Height: " + height); } public double getVolume() { double vol = length - width - height; return vol; } }arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education