Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13.7, Problem 13.7.6CP
Show the output of the following code:
public class Test {
public static void main(String[] args) {
House house1 = new House(1, 1750, 50);
House house2 = (House)house1.clone();
System.out.println(house1.equals(house2);
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
class Param3 {
public int x;
private void increase(int p)
{
x = x*p; }
public void calculateX(int y) {
increase(y);
}
public int getX() { return x; }
}
// in another class
Param3 q3 = new Param3();
q3.x = 5; q3.calculateX(7);
System.out.println(q3.getX());
what would be the answer for the last two lines ? also above were x = x*p do both x in here are the fields? wouldn't that be cnofusing?
For the following four classes, choose the correct relationship between each pair.
public class Room (
private String m type;
private double m area;
// "Bedroom", "Dining room", etc.
// in square feet
public Room (String type, double area)
m type
type;
m area
= area;
public class Person {
private String m name;
private int m age;
public Person (String name, int age)
m name
= name;
m age = age;
public class LivingSSpace (
private String m address;
private Room[] m rooms;
private Person[] m occupants;
private int m countRooms;
private int m countoccupants;
public LivingSpace (String address, int numRooms, int
numoccupants)
m address =
address;
new int [numRooms];
= new int [numOceupants];
m rooms
%3D
D occupants
m countRooms = m countOccupants = 0;
public void addRoom (String type, double area)
class class
{
public static void main(String args[])
{
int a =5;
int b =10;
first:
{
second:
{
third:
{
if(a == b >>1)
break second;
}
System.out.println(a);
}
System.out.println(b);
}
}
}
Give result for the code
Java
Try to do ASAP
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 13.2 - Prob. 13.2.1CPCh. 13.2 - The getArea() and getPerimeter() methods may be...Ch. 13.2 - True or false? a.An abstract class can be used...Ch. 13.3 - Prob. 13.3.1CPCh. 13.3 - Prob. 13.3.2CPCh. 13.3 - Prob. 13.3.3CPCh. 13.3 - What is wrong in the following code? (Note the...Ch. 13.3 - What is wrong in the following code? public class...Ch. 13.4 - Can you create a Calendar object using the...Ch. 13.4 - Prob. 13.4.2CP
Ch. 13.4 - How do you create a Calendar object for the...Ch. 13.4 - For a Calendar object c, how do you get its year,...Ch. 13.5 - Prob. 13.5.1CPCh. 13.5 - Prob. 13.5.2CPCh. 13.5 - Prob. 13.5.3CPCh. 13.5 - Prob. 13.5.4CPCh. 13.6 - Prob. 13.6.1CPCh. 13.6 - Prob. 13.6.2CPCh. 13.6 - Can the following code be compiled? Why? Integer...Ch. 13.6 - Prob. 13.6.4CPCh. 13.6 - What is wrong in the following code? public class...Ch. 13.6 - Prob. 13.6.6CPCh. 13.6 - Listing 13.5 has an error. If you add list.add...Ch. 13.7 - Can a class invoke the super.clone() when...Ch. 13.7 - Prob. 13.7.2CPCh. 13.7 - Show the output of the following code:...Ch. 13.7 - Prob. 13.7.4CPCh. 13.7 - What is wrong in the following code? public class...Ch. 13.7 - Show the output of the following code: public...Ch. 13.8 - Prob. 13.8.1CPCh. 13.8 - Prob. 13.8.2CPCh. 13.8 - Prob. 13.8.3CPCh. 13.9 - Show the output of the following code: Rational r1...Ch. 13.9 - Prob. 13.9.2CPCh. 13.9 - Prob. 13.9.3CPCh. 13.9 - Simplify the code in lines 8285 in Listing 13.13...Ch. 13.9 - Prob. 13.9.5CPCh. 13.9 - The preceding question shows a bug in the toString...Ch. 13.10 - Describe class-design guidelines.Ch. 13 - (Triangle class) Design a new Triangle class that...Ch. 13 - (Shuffle ArrayList) Write the following method...Ch. 13 - (Sort ArrayList) Write the following method that...Ch. 13 - (Display calendars) Rewrite the PrintCalendar...Ch. 13 - (Enable GeometricObject comparable) Modify the...Ch. 13 - Prob. 13.6PECh. 13 - (The Colorable interface) Design an interface...Ch. 13 - (Revise the MyStack class) Rewrite the MyStack...Ch. 13 - Prob. 13.9PECh. 13 - Prob. 13.10PECh. 13 - (The Octagon class) Write a class named Octagon...Ch. 13 - Prob. 13.12PECh. 13 - Prob. 13.13PECh. 13 - (Demonstrate the benefits of encapsulation)...Ch. 13 - Prob. 13.15PECh. 13 - (Math: The Complex class) A complex number is a...Ch. 13 - (Use the Rational class) Write a program that...Ch. 13 - (Convert decimals to fractious) Write a program...Ch. 13 - (Algebra: solve quadratic equations) Rewrite...Ch. 13 - (Algebra: vertex form equations) The equation of a...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Describe the purpose of the access key attribute and how it supports accessibility.
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
What data structure does Python use in place of arrays?
Concepts of Programming Languages (11th Edition)
Assuming there are no accidents or delays, the distance that a car travels down the interstate can be calculate...
Starting Out With Visual Basic (7th Edition)
_____________ is an objects ability to contain and manipulate its own data.
Starting Out with C++ from Control Structures to Objects (8th Edition)
The keywordindicates that a method does not return a value.
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Suppose a machine language is designed with an op-code field of 4 bits. How many different instruction types ca...
Computer Science: An Overview (12th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- what is the output of this code?arrow_forwardAnalyse the following code. public class Test { int x; public Test(String t) { System.out.println("Test"); } public static void main(String[] args) { Test test = new Test(); System.out.println(test.x); } } A. The program has a compile error because you cannot create an object from the class that defines the object. B. The program has a compile error because System.out.println method cannot be invoked from the constructor. C. The program has a compile error because x has not been initialized. D. The program has a compile error because Test does not have a default constructor.arrow_forward2. Using Encapsulation concept for Test1 class. package Exam; public class Test1 { private static int index = 0; public int x; Test1(){ index ++; } public static int getlndex () { return index; } public void prints(){ System.out.println("Hi Students!"); } } public class Test2 extends Test1 { @Override public void prints(){ System.out.println("OOP!"); } } public class Main { public static void main(String[] args) { } }arrow_forward
- Statement that increases numPeople by 5. Ex: If numPeople is initially 10, the output is: There are 15 people.arrow_forwardpublic class Test { } public static void main(String[] args) { String str = "Salom"; System.out.println(str.indexOf('t)); }arrow_forwardpublic class test{ private static final int MAX = 100; private int[] sco; public test(int[] sco){ this.sco = sco; } private int comAvg() throws IllegalArgumentException{ int sum = 0; for (int i = 0; i < sco.length; i++){ int sc = sco[i]; if (sc < 0 || sc > MAX){ throw new IllegalArgumentException("Score (" + sc + ") is not in the range 0-" + MAX); } sum += sco[i]; } int av = sum / sco.length; return av; } public static void main(String[] args){ test test = new test(new int[] { 50, 70, 81 }); try{ int avgSc = test.comAvg(); char letG; if (avgSc < 60) letG = 'F'; else if (avgSc < 70) letG = 'D'; else if (avgSc < 80) letG = 'C'; else if (avgSc < 90) letG = 'B'; else letG = 'A'; System.out.println("\nAVG Score is " +…arrow_forward
- import java.util.Scanner; public class Shady RestRoom 2 { // Modify the code below public static void main (String args[]) { int selection; int price; String result; final int QUEEN = 1, KING = 2, SUITE = 3; final int QPRICE = 125, KPRICE = 139, SPRICE = 165; final String QSTRING = "Queen bed", KSTRING = "King bed"; SSTRING = "Suite with a king bed and pull-out couch"; INVALIDSTRING = "an invalid option"; Scanner in = new Scanner(System.in); System.out.println("\t\n\nMenu\n"); System.out.println("(" + QUEEN + ") " + QSTRING); System.out.println("(" + KING + ") " + KSTRING); System.out.println("(" + SUITE + ") " + SSTRING); System.out.print("Enter Selection (1, 2, or 3) >> "); selection = in.nextInt(); if(selection == QUEEN) { result = QSTRING; price = QPRICE; } else if(selection == KING) { result = KSTRING; price = KPRICE; } else if (selection == SUITE) { result = SSTRING; price = SPRICE; } else { result = INVALIDSTRING; price = 0; } System.out.println("You selected " + result +…arrow_forward2-7 Given the code below, which lines are valid and invalid.arrow_forwardExplain C# code line by linearrow_forward
- Java: ShowStudent.java: class ShowStudent { public static void main (String args[]) { Student pupil = new Student(); pupil.setIdNumber(234); pupil.setPoints(47); pupil.setHours(15); pupil.showIdNumber(); pupil.showPoints(); pupil.showHours(); System.out.println("The grade point average is " + pupil.getGradePoint()); } } ShowStudent2.java: class ShowStudent2 { public static void main (String args[]) { Student pupil = new Student(); pupil.showIdNumber(); pupil.showPoints(); pupil.showHours(); System.out.println("The grade point average is " + pupil.getGradePoint()); } } Student.java: class Student { // the private data members private int idNumber; private int hours; private int points; // Constructor added in part c Student() { } // end of constructor added in part c // the public get and set methods public void…arrow_forwardpublic class MyGenClass { private T1 name; private T2 stulD; private T3 CGPA; public void setStuData( ){ I/ parameters name = n; stulD = d: CGPA = g; } public void printAsString() { System.out.println( } ); I/ print all information as string public static void main(String args||) { Il Create an object stu by parameters String, Integer, Double Il Call setStuData() with any values you like /l Call printAsString() } }arrow_forwardWhat is the output of the following code with explanation:- class Teacher { public Teacher() { System.out.println("Teacher class constructor called"); } } public class Student extends Teacher { public Student() { System.out.println("Student class constructor called"); } public static void main (String args[]) { Student s = new Student(); } }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
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License