Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13.6, Problem 13.6.5CP
What is wrong in the following code?
public class Test {
public static void main(String[] args) {
Person[] persons = {new Person(3), new Person(4), new Person(1)};
java.util.Arrays.sort(persons);
}
}
class Person {
private int id;
Person(int id) {
this.id = id;
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
the code:
class HighArray { private long[] a; private int nElems;
public HighArray(int max) { a = new long[max]; nElems = 0; }
public void insert(long value) { a[nElems] = value; nElems++; }
public boolean find(long searchKey) { int j; for (j = 0; j < nElems; j++) if (a[j] == searchKey) break; if (j == nElems) return false; else return true; }
public long getMax() { if (nElems == 0) return 01; else { long max = a[0]; for (int i = 1; i < nElems; i++) { if (a[i] > max) max = a[i]; } return max; } }
public boolean delete(long value) { int j; for (j = 0; j < nElems; j++) if (value == a[j]) break; if (j == nElems) return false; else { for (int k = j; k < nElems; k++) a[k] = a[k + 1]; nElems--; return true; } }
public void display() { for (int j = 0; j < nElems; j++) System.out.print(a[j] + " "); System.out.println(""); }}
public class HighArrayApp {
public static void main(String[] args) { int maxSize =…
public 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 " +…
public class Number { private int num; public Number(int n) { num = n; }
/* Type your code here */ public int getNum() { return num; } public void setNum(int n) { num = n; }
public static void main(String [] args) { Number yourNum = new Number(723); System.out.print(yourNum); }}
Chapter 13 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global 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
What will the following code display? for number in range(10, 5, 1): print(number)
Starting Out with Python (4th Edition)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
Empl Id Name Address SSN Job Id Job Title Skill Cod Dept Start Date Term Date 25X15 Joe E. Baker 33 Nowhere St ...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Show a snippet of PHP code for creating a recordset. Explain the meaning of the code.
Database Concepts (8th Edition)
Is the following comment a single-line style comment or a multi-line style comment? / This program was written ...
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Rainfall Program Modification Recall that Programming Exercise 3 in Chapter 8 asked you to design a program tha...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
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
- 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?arrow_forwardusing System; class Program { publicstaticvoid Main(string[] args) { int number = 1,i; while (number <= 88) { Console.WriteLine(number); number = number + 2; { Random r = new Random(); int[] randNo=newint[3]; for(i=0;i<3;i++) { randNo[i]= r.Next(1,88) Console.WriteLine("Random Number between 1 and 88 is "+randNo); } } } } } how can this program be fixed to choose three random numbers in C# between 1-88 instead of just one random number?arrow_forwardpublic class MyGenClass { private T1 name; private T2 stulD; private T3 CGPA; public void setStuData( ){ l parameters name = n; stulD = d: CGPA = g; public void printAsString() { System.out.printin( '): # print all Information as string public static void main(String args||) { Il Create an object stu by parameters String, Integer, Double II Call setStuData() with any values you like Il Call printAsString()arrow_forward
- 26. Assume the declaration of Exercise 24. A. Write the statements that derive the class dummyClass from class base as a private inheritance. (2 lines are { and }.) "A1 is { "A2 is "A3 is )) B. Determine which members of class base are private, protected, and public in class dummyClass. "B1 is dummyClass is a dearrow_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_forwardclass Solution(object): def longestCommonPrefix(self, strs): result ="" for i in strs[0]: for j in strs[1]: for k in strs[2]: if i == j and i == k: result+=i if len(result) >0: return result else: return result IndexError: list index out of range for j in strs[1]: Line 5 in longestCommonPrefix (Solution.py) ret = Solution().longestCommonPrefix(param_1) Line 31 in _driver (Solution.py) _driver() Line 41 in <module> (Solution.py) can someone explain why this is wrong?arrow_forward
- Override the Person class’s speak function inside the Student class. Make the function print “I’m a student”. public class Person { public void speak() { System.out.println("I'm a person"); } public static void main(String[] args) { Person p1 = new Student(); p1.speak(); } } class Student extends Person { // ADD CODE HERE }arrow_forwardCreate a fee invoice application for students attending Valence College, a college in the State of Florida. There are two types of students: graduate and undergraduate. Out-of-state undergraduate students pay twice the tuition of Florida-resident undergraduate students (all students pay the same health and id fees). A graduate student is either a PhD or a MS student. PhD students don't take any courses, but each has an advisor and a research subject. Each Ms and Phd student must be a teaching assistant for one undergraduate course. MS students can only take graduate courses. A course with a Course Number (crn) less than 5000 is considered an undergraduate course, and courses with a 5000 crn or higher are graduate courses. CRN Course Credit Hours. 4587 MAT 236 4 4599 COP 220 3 8997 GOL 124 1 9696 COP 100 3 4580 MAT 136 1 2599 COP 260 3 1997 CAP 424 1 5696 KOL 110 2 7587 MAT 936 5 2599 COP 111 3 6997 GOL 109 1 2696 COP 101 3 5580 MAT 636 2 2099 COP 268 3 4997 CAP 427 1 3696 KOL 910 2…arrow_forwardCreate a fee invoice application for students attending Valence College, a college in the State of Florida. There are two types of students: graduate and undergraduate. Out-of-state undergraduate students pay twice the tuition of Florida-resident undergraduate students (all students pay the same health and id fees). A graduate student is either a PhD or a MS student. PhD students don't take any courses, but each has an advisor and a research subject. Each Ms and Phd student must be a teaching assistant for one undergraduate course. MS students can only take graduate courses. A course with a Course Number (crn) less than 5000 is considered an undergraduate course, and courses with a 5000 crn or higher are graduate courses. CRN Course Credit Hours. 4587 MAT 236 4 4599 COP 220 3 8997 GOL 124 1 9696 COP 100 3 4580 MAT 136 1 2599 COP 260 3 1997 CAP 424 1 5696 KOL 110 2 7587 MAT 936 5 2599 COP 111 3 6997 GOL 109 1 2696 COP 101 3 5580 MAT 636 2 2099 COP 268 3 4997 CAP 427 1 3696 KOL 910 2…arrow_forward
- Main.java 1 class DictionaryEntry 2 - { 3 4 5 6 7 8 9- 10 11 12 13 14 15 String word; String definition; Dictionary Entry(String w, String def) {this word=new String (w); // Clone the strings this definition = new String(def); } class TestMyDictionary public static void main(String[] args) { } DictionaryEntry [] Dico = new DictionaryEntry [10]; Dico [0]=new Dictionary Entry("Java" "A modern object-oriented Type here to search programming language"); Dico [1]=new DictionaryEntry ("C++" "An effective object oriented programming language"); Dico [2] = new DictionaryEntry("FORTRAN, "FORTRAN stands for FORmula TRANSIation. Often used for simulation."); O JL I S Et Run O $ Outputarrow_forwardWarmup Write a method called countSuit) that takes an array of Cards and a String suit as parameters and counts how many of the cards have the given suit. Complete the definition of the class Warmup and method definition countSuit shown below. public class Warmup { public static int countSuit(Card [] cards, String suit) { // fill in code here } } For example, if we ran the following code in the main method: Card[] cards = new Card[4]; cards [0] = new Card (4, "clubs"); cards [1] = new Card (12, "diamonds"); cards [2] = new Card (1, "hearts"); cards [3] new Card(10, "diamonds"); System.out.println(countSuit(cards, "diamonds")); the output printed would be 2.arrow_forwardIN JAVAarrow_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