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
Concept explainers
Textbook Question
Chapter 13.6, Problem 13.6.3CP
Can the following code be compiled? Why?
Integer n1 = new Integer(3);
Object n2 = new Integer(4);
System.out.println(n1.compareTo(n2));
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
In this assignment, you will need to add a new method to the Date class, which you
can find on D2L in the "Sample Code" section.
The new method should make a Date object's day, month, and year value change to
the next day. In other words, add one day to the object's current date. Do not use any
part of the built-in DateTime class, but you may want to use the DaysInMonth()
method from the Date class.
Examples:
• If the Date object stores the date 12/31/2021, then after calling your method
it should store the date 1/1/2022
• If the Date object stores the date 2/28/2022, then after calling your method it
should store the date 3/1/2022
As noted in the common instructions, you only need to turn in your new method, not
the entire Date class.
using System;using System.Text.RegularExpressions;class chapter8 {static void Main() {string words = "08/14/57 46 02/25/59 45 06/05/85 18" +"03/12/88 16 09/09/90 13";string regExp1 = "(\\s\\d{2}\\s)";MatchCollection matchSet = Regex.Matches(words,regExp1);foreach (Match aMatch in matchSet)Console.WriteLine(aMatch.Groups[0].Captures[0]);}}
Now let’s modify this program to search for dates instead of ages, and usea grouping construct to organize the dates. And write the c# code:
Method: sumOdds(value: int): This method will sum all the odd values from 1 upto the value passed by parameter. This will display the sumas an integer value.Method: characterCount(phrase: str): This method will count the number of characters in the phrase that is passed by parameter. You cannot useany built in function ( ie len() ) and must use a looping activity. This should display the number of characters inthe phrase as an integerMethod: multiplicationPractice(): This method is to practice simple multiplication problems. The program should randomly generate twonumbers from 1-10 for the user to multiply. It should display the multiplication problem and allow the user toanswer the problem. It should display if the user got the answer correct or incorrect. The activity shouldcontinue until the user has gotten 3 different practice problems correct.Method: order(value1: int, value2: int, value3: int): This method is to order the 3 passed value from least to greatest. It should display…
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
Suppose the registers 0x4 and 0x5 in the Vole contain the bit patterns 0x3A and 0xC8, respectively. What bit pa...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Type in and run the 12 programs presented in this chapter. Compare the output produced by each program with the...
Programming in C
Restaurant Bill Write a program that computes the tax and tip on a restaurant bill. The program should ask the ...
Starting Out with Java: From Control Structures through Objects (6th Edition)
Write a statement that clears the contents of the List object created in Check point 7.22.
Starting out with Visual C# (4th Edition)
Widget Factory Design a class for a widget manufacturing plant. Assuming that 10 widgets may be produced each h...
Starting Out with C++: Early Objects (9th Edition)
What is the highest decimal number that can be represented by each of the following numbers of binary digits (b...
Digital Fundamentals (11th 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
- Assignment: Enhancing Dice Roll Stats Calculator Program Introduction: The project involves creating a program to roll pairs of dice, gathering statistics on the outcomes. Probability differs in the roll of two dice compared to a single die due to varied combinations. Dice Roll Series: User greeted with "Welcome to the Dice Roll Stats Calculator!" and prompted to specify rolls. Java classes: DiceRoller, Indicator, Validator. DiceRoller: Arrays: rollSeries (captures results), statIndicators (stores statistical indicators). Constructor rolls dice as per user request. Methods collect stats and print the report. Indicator class: Contains dicePairTotal and dicePairCount. Displaying Results: Sort statIndicators array before display. Indicator objects sortable by dicePairCount (implements Comparable). Example output:-----------------------dicepair rolltotal count percent---- ------ --------7 5 50%10 2 20%4 2 20%2 1 10% Tasks:…arrow_forwardx = 3 + numbers[3]++; System.out.println(x); QUESTION 2: Class Rectangle has two data members, length (type of float) and width (type of float). The class Rectangle also has the following: //mutator methods void setlength (float len) } //B. length = len; H accessor methods float getLength() I return length; The following statement creates an array of Rectangle with size 2: Rectangle[] arrayRectangle= new Rectangle[2]; Is it correct if executing the following statements? What is the output? If it is not correct, write the correct one arrayRectangle. setLength (12.59); System.out.printin[rectangle Set.getLength()); arrayRectangle[1].setLength(4.15); System.out.println(arrayRectangle[1].getLength()): QUESTION 3: Use the following int array int[] numbers = { 42, 28, 36, 72, 17, 25, 81, 65, 23, 58} -Open file data.txt to write. to write the values of the array numbers to the file with the y numbers to get the valuesarrow_forwarda) FindMinIterative public int FindMin(int[] arr) { int x = arr[0]; for(int i = 1; i < arr.Length; i++) { if(arr[i]< x) x = arr[i]; } return x; } b) FindMinRecursive public int FindMin(int[] arr, int length) { if(length == 1) return arr[0]; return Math.Min(arr[length - 1], Find(arr, length - 1)); } What is the Big-O for this functions. Could you explain the recurisive more in details ?arrow_forward
- Description: The program prompts the user to enter three numbers and invokes the method: public static void displayIncreasingNumbers(int num1, double num2, long num3) to display them in increasing order. Below is my code: package threeincreasingnumbers; import java.util.Scanner; public class Threeincreasingnumbers { public static void main(String[] args) {// Create Scanner Scanner scan = new Scanner(System.in); // Prompt the user to enter three numbersSystem.out.print("Enter three numbers: ");int num1 = scan.nextInt();double num2 = scan.nextDouble();long num3 = scan.nextLong(); // Display numbers in increasing orderdisplayIncreasingNumbers(num1, num2, num3);}public static void displayIncreasingNumbers(int num1, double num2, long num3) {double temp; if (num2 < num1 && num2 < num3){temp = num1;num1 = (int) (double) num2;num2 = temp;}else if (num3 < num1 && num3 < num2) {temp = num1; num1 = (int) num3;num3 = (long) temp;}if (num3 < num2) {temp = num2;num2 =…arrow_forwardBasic Java Help Each year, the Social Security Administration provides a list of baby names for boy and girls by state. You will write a program to read a file containing a list of baby names and display the top names. To start, implement the following class: baby names util = printTopNames(File, int): void printTopNames Will be a static method. It will accept two parameters, one is a File containing the list of names. The other is an integer that indicates how many names to display (ie, top 10 names, or top 50 names, etc). The integer argument could be any valid integer. You do not have to worry about an integer value large than 5 for the boy/girl names. This method should open the file and parse the file and print the names as shown below: Your program will use the Scanner class to read the data from the file (see your text for examples). You will also need to use a delimiter with the scanner so that the scanner will break the line apart based on the commas. For this file, set…arrow_forwardHow do I code: public static int maxValue(int[] arr) public static int maxValue(int[] arr, int firstIndex, int lastIndex) public static int indexOfFirstMaxValue(int[] arr) in java?arrow_forward
- What does the following code do? In [1]: def mystery (a, b) : if b == 1: return a else: return a + mystery (a, b - 1) In [2]: mystery (2, 10) Out [2]: ?????arrow_forwardHow do I change the code so if numMinutes is zero then the number cast members is also zero? Code: import java.util.*; import java.util.Arrays; public class Movie { private String movieName; private int numMinutes; private boolean isKidFriendly; private int numCastMembers; private String[] castMembers; // default constructor public Movie() { this.movieName = "Flick"; this.numMinutes = 0; this.isKidFriendly = false; this.numCastMembers = 0; this.castMembers = new String[10]; } // overloaded parameterized constructor public Movie(String movieName, int numMinutes, boolean isKidFriendly, String[] castMembers) { this.movieName = movieName; this.numMinutes = numMinutes; this.isKidFriendly = isKidFriendly; this.numCastMembers = castMembers.length; this.castMembers = new String[numCastMembers]; for (int i = 0; i < castMembers.length; i++) { this.castMembers[i] = castMembers[i]; } } // set the number of minutes public void setNumMinutes(int numMinutes) { this.numMinutes = numMinutes; } //…arrow_forwardInstructions: In the code editor, you are provided with a treasureChestMagic() function which has the following description: Return type - void Name - treasureChestMagic Parameters - an address of an integer Description - updates the value of a certain integer randomly You do not have to worry about how the treasureChestMagic() function works. All you have to do is ask the user for an integer and then call the treasureChestMagic() function, passing the address of that integer you just asked. Finally, print the updated value of the integer inputted by the user. Please create a main code for my function that works with this. This is my code: #include<stdio.h>#include<math.h> void treasureChestMagic(int*); int main(void) { // TODO: Write your code here return 0;} void treasureChestMagic(int *n) { int temp = *n; int temp2 = temp; *n = *n + 5 - 5 * 5 / 5; temp2 = (int) pow(2, 3); if(temp % 3 == 0) { *n = temp * 10; } else if(temp %…arrow_forward
- using System; class main { publicstaticvoid Main(string[] args) { int number = 1; while (number <= 88) { int i; 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[i]); } } } } This code is supposed to count from 1-88 and then select three random numbers from the list but instead it generates an infinite loop of random numers between 1-88. how can it be fixed?arrow_forwardusing System; class main { publicstaticvoid Main(string[] args) { int number = 1; while (number <= 88) { int i; 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[i]); } } } } how can this program be fixed to count from 1-88 and then choose 3 different random numbers?arrow_forwardfor the class ArrayAverage write a code that calculates the average of the listed numbers with a double result for the class ArrayAverageTester write a for each loop and print out the resultarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
9.1: What is an Array? - Processing Tutorial; Author: The Coding Train;https://www.youtube.com/watch?v=NptnmWvkbTw;License: Standard Youtube License