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.9, Problem 13.9.1CP
Show the output of the following code:
Rational r1 = new Rational(–2, 6);
System.out.println(r1.getNumerator());
System.out.println(r1.getDenominator())
System.out.println(r1.intValue());
System.out.println(r1.doubleValue());
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Trace through (show all the steps as we did in class) for the following java code for the factorial function. Show all the steps (illustrate, do not code) that lead to the final answer when myFactorial(6) is called:
int myFactorial( int integer)
{
if( integer == 1)
return 1;
else
{
return(integer*(myFactorial(integer-1);
}
}
PROBLEM STATEMENT:
Return the factorial of the provided integer parameter.
public class FactorialComputation{public static int solution(int n){// ↓↓↓↓ your code goes here ↓↓↓↓return 0;}
Can you please help me with the question above
the Language is Java and can yiu use the java code that i gave above to answer the question
In C++
QUESTION 14
class rectangleType
{
public:
void setLengthWidth(double x, double y); //Sets the length = x; width = y;
void print() const; //Output length and width
double area(); //Calculate and return the area of the rectangle (length*width)
double perimeter(); //Calculate and return the perimeter (length of outside boundary of the rectangle)
private:
double length;
double width;
};
Write the function definition for the function perimeter
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
What is a decision structure?
Starting Out with Python (3rd Edition)
In Exercises 53 through 56, determine the output produced by the lines of code where Courier New is the font se...
Introduction To Programming Using Visual Basic (11th Edition)
Why are field values sometimes coded?
Modern Database Management
Distinguish among data definition commands, data manipulation commands, and data control commands.
Modern Database Management (12th Edition)
Determine by row and column number which fusible links must be blown in the programmable AND array of Figure 3-...
Digital Fundamentals (11th Edition)
What will the following program display? public class Checkpoint { public static void main(String[] args) { int...
Starting Out with Java: From Control Structures through Data Structures (3rd 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
- int f(int &k){k++;return k * 2;}int main(){int i = 1, j = -1;int a, b, c;a = f(i) + i/2;b = j + f(j) + f(j);c = 2 * f(j);return 0;} What are the values of a, b and c id the operands in the expressions are evaluated from left to right and then what are the values when its evaluated right to left?arrow_forwardDraw a flowchart for the Frazzle function.arrow_forwardFix the typo in the following program. Your solution should be a single line of code with the typo fixed: public class Rational private int numerator; private int denominator; public Rational(int numerator, int denominator) this.numerator = numerator: this.denominator = denominator; public int getNumerator() { return this.numerator; } public int getDenominator (){ return this.denominator; } public double getFraction() { return (double)numerator / (double)denominator; public String toString () | return numerator+"/"+denominator; public static void main (Stringl) args) Rational r = new Rational (2, 3); System.out.println (r); double real = getFraction (): System.out.println (real);arrow_forward
- A spell checker in a word processing program makes suggestions when it finds a word not in the dictionary. To determine what words to suggest, it tries to find similar words. One measure of word similarity is the Levenshtein distance, which measures the number of substitutions, additions, or deletions that are required to change one word into another. For example, the words spit and spot are a distance of 1 apart; changing spit to spot requires one substitution (i for o). Likewise, spit is distance 1 from pit since the change requires one deletion (the s). The word spite is also distance 1 from spit since it requires one addition (the e). The word soot is distance 2 from spit since two substitutions would be required. a. Create a graph using words as vertices, and edges connecting words with a Levenshtein distance of 1. Use the misspelled word “moke” as the center, and try to find at least 10 connected dictionary words. How might a spell checker use this graph? b. Improve the method…arrow_forwardRe-write the following Factorial function using the Lambda expression static int Factorial(int number) { if (number < 1) { return 0; } else if (number == 1) { return 1; } else { unchecked { return number * Factorial(number - 1); } } }arrow_forward3: The code on the right is supposed to be the ARM code for procA; however, there are problems with the ARM code. C code: int procA(int x, int y) { int perimeter = (x + y) * 2; I return perimeter; } ARM code: I procA: add rø, r1, r2 mov r1, rø lsl #1 bx lr push {lr} Give the corrected version of the ARM code for procA:arrow_forward
- inhinclude Rsing namespace std; int maxResult( ) int maxVal for (int i { for (int j = 0; j <= n 0; i <= n; i += a) i; j += b) %3D %3D float z = (float)(n (i + j)) / (float)(c); if (floor(z) { int x = int y ceil(z)) i / a; j/ b; maxVal = max(maxVal, x + y (int)z); return maxVal; } int main() { max cout << maxResult( ); return 0; 1 } Input Compilation failed due to fellowing ons main.cpp:7:23: error: 'n' was not declared in this scope 7| for (int i = 0; i <= n; i a) main.cpp:7:31: error: 'a was not declared in this scope for (int i = 0; i <= n; i t= a) %3D main.cpp:9:36: error: b' was not declared in this scope | 6 for (int j = 0; j <= n - i; j - b) %3D main.cpp:11:45: error: 'c was not declared in this scopearrow_forwardWrite a function that overloads the compound addition operator (+=) for the following class. class Sample{private: int value;public:Sample (int value); ~Sample();...}arrow_forwardWrite code for tic tac toe in C using 2d arrays and functions. The game is for 2 players User and Computer. Write comments for proper understanding of code. Use simple and proper logics. Please dont copy the code from google (plagiarised)arrow_forward
- Note: The code is written you can just tell the explanation what is happening in the code Explain in English.Just explain the whole code. #include <iostream>using namespace std;class PrimeNumberGenerator{private:int counter;public://ConstructorPrimeNumberGenerator() : counter(0){}//Function to reset countervoid reset(){counter = 0;}int getCounter(){return counter;}//Function to return next prime number after currentPrimeint getNextPrime(){if(counter == 0){counter = 2;}else{for(int i = counter + 1; ; i++){if(isPrime(i)){counter = i;break;}}}return counter;} //Function to check if a number is prime or notbool isPrime(int num){for(int i = 2; i <= num/2; i++){if(num % i == 0)return false;}return true;}}; int main() {int option;PrimeNumberGenerator gen;cout << "Enter 1 if you want to reset\n";cout << "Enter 2 if you want to get next prime number\n";cout << "Enter -1 to quit: ";cin >> option;while(option != -1){if(option == 1){gen.reset();cout <<…arrow_forwardvoid traceMe(double x, double y) { double z; z = (pow(x, y)); cout « fixed « showpoint <« setprecision(2)<« x « ", " « y « ", " « z « endl; int main() double one=2, two=6; traceMe(two, one); 2.00 , 6,00 , 36.00 6.00 , 2.00 , 36.00 6.00 , 2,00 , 64.00 O 6.00, 2.00, 4,00arrow_forwardExplain the function of the given code: int timer = 100; int ledPins[] = { 2, 7, 4, 6, 5, 3 }; int pinCount = 6; void setup() { for (int thisPin = 0; thisPin = thisPin--) { digitalWrite(ledPins[thisPin], HIGH); delay(timer); digitalWrite(ledPins[thisPin], LOW); } 0;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
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY