Given the class Species as defined in Listing 5.19, why does the following
public class SpeciesEqualsDemo
{
public static void main(String [] args)
{
Species s1, s2; s1;
setSpecies(“Klingon ox”, 10, 15);
s2.setSpecies(“Klingon ox”, 10, 15);
if (s1 == s2)
System.out.println(“Match with ==,”);
else
sysyem.out.println(“Do Not match with ==.”)
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects (9th Edition)
Differential Equations: Computing and Modeling (5th Edition), Edwards, Penney & Calvis
Computer Systems: A Programmer's Perspective (3rd Edition)
Artificial Intelligence: A Modern Approach
Starting Out with C++ from Control Structures to Objects (9th Edition)
- What is the output of the following code? 1: class Arthropod2: public void printName(double input) { System.out.print("Arthropod"); }3: }4: public class Spider extends Arthropod {5: public void printName(int input) { System.out.print("Spider"); }6: public static void main(String[] args) {7: Spider spider = new Spider();8: spider.printName(4);9: spider.printName(9.0);10: }11: } A. SpiderArthropodB. ArthropodSpiderC. SpiderSpiderD. ArthropodArthropodE. The code will not compile because of line 5.F. The code will not compile because of line 9. Please explain how this code works each line.arrow_forwardThe following is in Java: public class MyClass { private int x; private double y; public static void setValues(int a, double b) { x = a; y = b; } } 1) What is the problem? 2) In a few sentences how can the issue be fixed?arrow_forwardConsider the following class:1 public class Student {2 private int studentNumber;3 private Student labPartner;4 private static Student classPres = null;5 private static int nextStudentNumber = 100;67 public Student () {8 this.studentNumber = Student.nextStudentNumber;9 Student.nextStudentNumber ++;10 this.labPartner = null;11 }1213 public void setLabPartner (Student labPartner) {14 this.labPartner = labPartner;15 }1617 public static void setClassPres (Student pres) {18 Student.classPres = pres;19 }20 }(a) Write code that is able to construct an array of 1000 student objects and loads them in increasingstudent number order into that array. The lab partners of these students should all be null. TheclassPres should also be null.arrow_forward
- Consider the following code in Java 8:public interface Runnable{void run() ;}public final class Caller {public static void call (String before, String after, Runnable r) (System.out.println(before);r. run() ;System.out.println(after);} }public class MyClass{public static void main(String args[]) (Caller.call("BEFORE", "AFTER",); } }Complete the blark line with some code so that the program prints the folowing to the output: BEFOREHi there!AFTERarrow_forwardTrace and document every step of execution of the following program: public class Trace { public static void main(String[] args) { int[] num = {1, 3, 6, 9, 12 }; for (int i = 4; i >= 0; i--) { num[i] +=1; } num[0] *=num[4]; } }arrow_forwardI have the following code in java, replit: //First class public class Main { public static void main(String[] args) { Scanner console = new Scanner(System.in); Random random = new Random(); Game game = new Game(console, random); game.startGame(); console.close(); }} //Second class import java.util.Scanner; public class Player { private String name; private int totalGames; private int totalGuesses; private int bestGame; public Player() { this.name = null; this.totalGames = 0; this.totalGuesses = 0; this.bestGame = Integer.MAX_VALUE; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getTotalGames() { return totalGames; } public void setTotalGames(int totalGames) { this.totalGames = totalGames; } public int getTotalGuesses() { return totalGuesses; } public void setTotalGuesses(int totalGuesses) {…arrow_forward
- Consider the following class. 1 public class Example 2 { 3 private int a; 4 private String x; 5 6 public Example() 7 { 8 a = 0; 9 x = "1"; 10 } 11 12 public Example(int a, String x) 13 { 14 a = a + 10; 15 this.a = a; 16 this.x = x; 17 } 18 19 public void b() 20 { 21 a = a + 1; 22 x = x + "0"; 23 } 24 25 public void c() 26 { 27 b(); 28 a = a / 2; 29 x = x + "1"; 30 b(); 31 } 32 33 public int d() 34 { 35 return a; 36 } 37 38 public String e() 39 { 40 return x; 41 } 42 43 public int f(int a) 44 { 45 return a; 46 } 47 48 public void g() 49 { 50 System.out.println(x + " | " + a); 51 } 52 } State which lines (begin and end of line) declare 1) constructors, 2) accessors, and 3) mutators.arrow_forwardConsider the following class. 1 public class Example 2 { 3 private int a; 4 private String x; 5 6 public Example() 7 { 8 a = 0; 9 x = "1"; 10 } 11 12 public Example(int a, String x) 13 { 14 a = a + 10; 15 this.a = a; 16 this.x = x; 17 } 18 19 public void b() 20 { 21 a = a + 1; 22 x = x + "0"; 23 } 24 25 public void c() 26 { 27 b(); 28 a = a / 2; 29 x = x + "1"; 30 b(); 31 } 32 33 public int d() 34 { 35 return a; 36 } 37 38 public String e() 39 { 40 return x; 41 } 42 43 public int f(int a) 44 { 45 return a; 46 } 47 48 public void g() 49 { 50 System.out.println(x + " | " + a); 51 } 52 } State which lines (begin and end of line) declare 1) constructors, 2) Consider class Example from the previous exercise. For each object first and second, write down the value of the fields a and x or indicate that the object does not exist (e.g. using a forward slash “/”), after the execution of each of the following lines of code. 1 Example first = new Example(); 2 Example second = new Example(2, "0");…arrow_forward(Java) Q 4,5 COMPLETE BOTH STEPS Explain the answer step-by-step and include verbal explanation. Thank you! Given the below class: public class Dog { private String name; private double weight; private static int numDogs = 0; public Dog(String name, double weight) { this.name = name; this.weight = weight; numDogs++; } public String getName() { return name; } public double getWeight() { return weight; } public static int getNumDogs() { return numDogs; }public static void increaseNumDogs() {numDogs++;}public void printGreeting() { System.out.println("Woof!"); } @Override public String toString() { return "Name: " + name + "\nWeight: " + weight; }} Add a method call to getNumDogs to the below starter code: public class DogTest {public static void main(String[] args) { Dog fluffy = new Dog("Fluffy", 10); int num = //call getNumDogs method here }} Then, add a method call…arrow_forward
- 4.2.3: Method definition: Volume of a pyramid. Define a method pyramidVolume with double parameters baseLength, baseWidth, and pyramidHeight, that returns as a double the volume of a pyramid with a rectangular base. Relevant geometry equations: Volume = base area x height x 1/3Base area = base length x base width.(Watch out for integer division). import java.util.Scanner; public class CalcPyramidVolume { //answer goes here// public static void main (String [] args) { Scanner scnr = new Scanner(System.in); double userLength; double userWidth; double userHeight; userLength = scnr.nextDouble(); userWidth = scnr.nextDouble(); userHeight = scnr.nextDouble(); System.out.println("Volume: " + pyramidVolume(userLength, userWidth, userHeight)); }}arrow_forwardGiven the following class. (JAVA) public class FamilyMember { public String drink( ) {return “cup”;} public String eat( ) {return “fork”;} } Write a Baby class that is derived from the FamilyMember class. The Baby class has an instance variable for the age, a default constructor, and a constructor that accepts an integer. Include any other necessary methods. If a baby is older than 3 years, print that “it eats with its fork”; otherwise, “it eats with its hands”.arrow_forwardWrite a java (Java 7 ) program for this :-- A new deadly virus has infected large population of a planet. A brilliant scientist has discovered a new strain of virus which can cure this disease. Vaccine produced from this virus has various strength depending on midichlorians count. A person is cured only if midichlorians count in vaccine batch is more than midichlorians count of person. A doctor receives a new set of report which contains midichlorians count of each infected patient, Practo stores all vaccine doctor has and their midichlorians count. You need to determine if doctor can save all patients with the vaccines he has. The number of vaccines and patients are equal. Input Format First line contains the number of vaccines - N. Second line contains N integers, which are strength of vaccines. Third line contains N integers, which are midichlorians count of patients. Output Format Print a single line containing ′Yes′ or ′No′. Input Constraint 1<N<10 Strength of vaccines…arrow_forward
- 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