Big Java Late Objects
2nd Edition
ISBN: 9781119330455
Author: Horstmann
Publisher: WILEY
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 5.9, Problem 36SC
Consider this slight modification of the printTriangle method:
public static void printTriangle(int sideLength)
{
if (sideLength < 1) { return; }
for (int i = 0; i < sideLength; i++)
{
System.out.print("[]");
}
System.out.println();
printTriangle(sideLength - 1);
}
What is the result of printTriangle(4)?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
public class TestShape
{
public static void main(String[] args)
{
/*
Circle c1 = new Circle(2.67);
System.out.println("c1: ");
System.out.println(c1.toString());
System.out.println();
Circle c2 = new Circle(3, false, "Red");
System.out.println("c2: ");
System.out.println(c2.toString());
System.out.println();
Rectangle r1 = new Rectangle(3, 2, true, "Blue");
System.out.println("r1: ");
System.out.println(r1.toString());
System.out.println();
Rectangle r2 = new Rectangle(3.2, 4, false, "Red");
System.out.println("r2: ");
System.out.println(r2.toString());
*/
}
}
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?
public class Geometry{public static void main(String[] args){//asks for user's choice Scanner in = new Scanner(System.in);displayMenu();selectOption(choice);System.out.println("Enter your choice (1-3): ");int choice1 = in.nextInt();System.out.println("Thanks for using the Geometry Calculator - Goodbye!");//Prints if input is a number that is not one of the choiceswhile(choice1 < 1 || choice1 > 3 ){System.out.println("Invalid choice. Please enter 1 - 3: ");choice1 = in.nextInt();}}/**Displays the menu*/public static void displayMenu(){System.out.println("Welcome to the Geometry Calculator Application");System.out.println("1. Calculate the Area of a Circle");System.out.println("2. Calculate the Area of a Rectangle");System.out.println("3. Calculate the Area of a Triangle");}/** This method calculates the area of the circle@return the area of the circle*/public static double circle()// calculates the area of the circle{Scanner in = new Scanner(System.in);System.out.println("What is…
Chapter 5 Solutions
Big Java Late Objects
Ch. 5.1 - Consider the method call Math.pow(3, 2). What are...Ch. 5.1 - What is the return value of the method call...Ch. 5.1 - The Math.ceil method in the Java standard library...Ch. 5.1 - It is possible to determine the answer to Self...Ch. 5.2 - What is the value of cubeVolume(3)?Ch. 5.2 - Prob. 6SCCh. 5.2 - Provide an alternate implementation of the body of...Ch. 5.2 - Declare a method squareArea that computes the area...Ch. 5.2 - Consider this method: public static int...Ch. 5.3 - What does this program print? Use a diagram like...
Ch. 5.3 - Prob. 11SCCh. 5.3 - What does this program print? Use a diagram like...Ch. 5.4 - Prob. 13SCCh. 5.4 - What does this method do? public static boolean...Ch. 5.4 - Implement the mystery method of Self Check 14 with...Ch. 5.5 - How do you generate the following printout, using...Ch. 5.5 - Prob. 17SCCh. 5.5 - Prob. 18SCCh. 5.5 - Prob. 19SCCh. 5.5 - The boxString method contains the code for...Ch. 5.6 - Consider the following statements: int...Ch. 5.6 - Consider this method that prints a page number on...Ch. 5.6 - Consider the following method that computes...Ch. 5.6 - The comment explains what the following loop does....Ch. 5.6 - In Self Check 24, you were asked to implement a...Ch. 5.7 - Explain how you can improve the intName method so...Ch. 5.7 - Prob. 27SCCh. 5.7 - What happens when you call intName(0)? How can you...Ch. 5.7 - Trace the method call intName(72), as described in...Ch. 5.7 - Prob. 30SCCh. 5.8 - Which lines are in the scope of the variable i...Ch. 5.8 - Which lines are in the scope of the parameter...Ch. 5.8 - The program declares two local variables with the...Ch. 5.8 - There is a scope error in the mystery method. How...Ch. 5.8 - Prob. 35SCCh. 5.9 - Consider this slight modification of the...Ch. 5.9 - Consider this recursive method: public static int...Ch. 5.9 - Consider this recursive method: public static int...Ch. 5.9 - Prob. 39SCCh. 5.9 - The intName method in Section 5.7 accepted...Ch. 5 - In which sequence are the lines of the Cubes.java...Ch. 5 - Write method headers for methods with the...Ch. 5 - Give examples of the following methods from the...Ch. 5 - Prob. 4RECh. 5 - Consider these methods: public static double...Ch. 5 - Prob. 6RECh. 5 - Design a method that prints a floating-point...Ch. 5 - Write pseudocode for a method that translates a...Ch. 5 - Describe the scope error in the following program...Ch. 5 - For each of the variables in the following...Ch. 5 - Prob. 11RECh. 5 - Perform a walkthrough of the intName method with...Ch. 5 - Consider the following method: public static int...Ch. 5 - Consider the following method that is intended to...Ch. 5 - Suppose an ancient civilization had constructed...Ch. 5 - Give pseudocode for a recursive method for...Ch. 5 - Give pseudocode for a recursive method that sorts...Ch. 5 - Write the following methods and provide a program...Ch. 5 - Write the following methods and provide a program...Ch. 5 - Prob. 4PECh. 5 - Prob. 5PECh. 5 - Prob. 6PECh. 5 - Prob. 7PECh. 5 - Prob. 8PECh. 5 - Write methods public static double...Ch. 5 - Write a recursive method public static String...Ch. 5 - Write a recursive method public static boolean...Ch. 5 - Use recursion to implement a method public static...Ch. 5 - Use recursion to determine the number of digits in...Ch. 5 - Write a method that computes the balance of a bank...Ch. 5 - Write a method that tests whether a file name...Ch. 5 - It is a well-known phenomenon that most people are...Ch. 5 - Prob. 3PPCh. 5 - Use recursion to compute an, where n is a positive...Ch. 5 - Leap years. Write a method public static boolean...Ch. 5 - In Exercise P3.13 you were asked to write a...Ch. 5 - Prob. 10PPCh. 5 - Write a program that reads two strings containing...Ch. 5 - Prob. 12PPCh. 5 - Write a program that reads words and arranges them...Ch. 5 - Prob. 14PPCh. 5 - Write a program that reads two fractions, adds...Ch. 5 - Write a program that prints the decimal expansion...Ch. 5 - Write a program that reads a decimal expansion...Ch. 5 - Write two methods public static void...Ch. 5 - Write a program that reads in the width and height...Ch. 5 - Repeat Exercise P5.19 with hexagonal circle...Ch. 5 - Postal bar codes. For faster sorting of letters,...Ch. 5 - Write a program that reads in a bar code (with :...Ch. 5 - Write a program that converts a Roman number such...Ch. 5 - A non-governmental organization needs a program to...Ch. 5 - Having a secure password is a very important...Ch. 5 - Prob. 30PPCh. 5 - Prob. 31PPCh. 5 - Electric wire, like that in the photo, is a...Ch. 5 - The drag force on a car is given by FD=12v2ACD...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Museum Tours Write a program that lets the user select items from different guided tours at a large museum. Use...
Starting Out With Visual Basic (8th Edition)
In Exercises 3 through 24, carry out the task.
Create a button containing the word “PUSH” with the letter H as...
Introduction To Programming Using Visual Basic (11th Edition)
Consider Figure 5.16, the decile-wise lift chart for the transaction data model, applied to new data. a. Interp...
Data Mining for Business Analytics: Concepts, Techniques, and Applications with XLMiner
What is the output of the following (when embedded in a complete program)? for (int n = 10; n 0; n = n 2) { c...
Problem Solving with C++ (9th Edition)
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
In Exercises 61 through 66, rewrite the statements using augmented assignment operators. Assume that each varia...
Introduction to Programming Using Visual Basic (10th 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
- class overload { int x; double y; void add(int a , int b) { x = a + b; } void add(double c , double d) { y = c + d; } overload() { this.x 0; %3D this.y = 0; } %3D } class Overload_methods { public static void main(String args[]) { overload obj int a = 2; double b - 3.2; obj.add(a, a); obj.add(b, b); System.out.println(obj.x + } = new overload(); + obj.y); } #3Run the codearrow_forwardpublic void foo4() { String s2 = "smith"; String s3 = s2; String s4 = null; String s5 = ""; String só = new String(s2); if(s2 == s3) { System.out.print("1"); } if(s2.equals(s3)) { System.out.print("2"); } if(s2 == s6) { System.out.print("3"); } if(s2.equals(s6)) { System.out.print("4"); } if(s5 == s4) { System.out.print("5"); } if(s4.equals(s5)) { System.out.print("6"); } 3//end of foo4() Examine and trace the method foo4() above, which statement IS true? O The method will print out "356" on screen. The method will print out "1234" on screen. The method will print out "123" on screen. The method will print out "124" on screen.arrow_forwardJava: 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_forward
- public class LabProgram { public static void main(String args[]) { Course cis162 = new Course(); int beforeCount; String toDrop; // Example students for testing cis162.addStudent(new Student("Henry", "Nguyen", 3.5)); cis162.addStudent(new Student("Brenda", "Stern", 2.0)); cis162.addStudent(new Student("Lynda", "Robison", 3.2)); cis162.addStudent(new Student("Sonya", "King", 3.9)); toDrop = "Stern"; beforeCount = cis162.countStudents(); cis162.dropStudent(toDrop); System.out.println("Course size: " + beforeCount + " students"); System.out.println("Course size after drop: " + cis162.countStudents() + " students"); } } import java.text.DecimalFormat; // Class representing a student public class Student { private String first; // first name private String last; // last name private double gpa; // grade point average // Student class constructor public Student(String f, String l, double g) {…arrow_forwardpublic class Polygon { private double sideLength; private int sides; private String shape; public double getArea () { int n sides; double a sideLength; return ((a * a * n) / (4 * Math.tan((180 / n) 3.14159 / 180))); public void setPolygon (double sl, int sd, String sh) { sides-sd; sideLength-sl; shape=sh; public Polygon (double sl, int sd, String sh) ( sides-sd; sideLengthsl; shape=sh; public String getShape () { return (shape); } public int getSides () { return (sides); } public double getLength () { return (sideLength); } Write a static method named find that takes as a parameter an array of type Polygon named list. The method should print the shapes of each polygon that has an area greater than 500 and return their count. The method prototype is public static int find (Polygon [] list); Note: assume the array is already declared, populated with data in the main method and ready to be used.arrow_forwardpublic class worksheet3_1 { public static void main(String[] arg) { ShadowingExample example = new ShadowingExample(); example.x = 99; example.sampleMethod(); }}class ShadowingExample { int x; public void sampleMethod() { int x = 0; System.out.println("the value of local variable x = " + ………………………………………………); System.out.println("the value of instance variable x = " + …………………………………………); }} what should be written in the second print statement so that the output is: the value of instance variable x = 99 what should be written in the first print statement so that the output is: the value of local variable x = 0 options are: samplemethod.x this.x shadowingexample.x x Answer 1 Question 1arrow_forward
- import java.util.Scanner; public class TicketCounter { public static void main (String [] args) { int awardPoints; int userTickets; Scanner scnr = new Scanner(System.in); userTickets = scnr.nextInt(); // Program will be tested with values: 5, 6, 7, 8. if (userTickets < 6) { awardPoints = 1; { else { awardPoints = userTickets; } System.out.println(awardPoints); }}arrow_forward1- public class Con{ public static void main(String[] args) int[] ar=(2,5,7,9}; int i=2; final int j=1; 6. for (int x:ar) 8- { 9 if(ar[i]arrow_forwardimport java.util.Scanner;public class LabProgram { public static void main(String args[]) { Scanner scnr = new Scanner(System.in); int credits; int seed; GVDie die1, die2; die1 = new GVDie(); die2 = new GVDie(); // Read random seed to support testing (do not alter) seed = scnr.nextInt(); die1.setSeed(seed); // Read starting credits credits = scnr.nextInt(); int rounds = 0; while (credits > 0) { // Step 1: Roll both dice die1.roll(); die2.roll(); int total = die1.getValue() + die2.getValue(); if (total == 7 || total == 11) { // Player wins one credit credits++; // UPDATE - print the dice total here System.out.println("Dice total: " + total); //UPDATE - break the loop and end the round break; } else if (total == 2 ||…arrow_forwardimport java.util.Scanner; public class LabProgram { public static void main(String args[]) { Scanner scnr = new Scanner(System.in); int credits; int seed; GVDie die1, die2; die1 = new GVDie(); die2 = new GVDie(); // Read random seed to support testing (do not alter) seed = scnr.nextInt(); die1.setSeed(seed); // Read starting credits credits = scnr.nextInt(); int rounds = 0; while (credits > 0) { // Step 1: Roll both dice die1.roll(); die2.roll(); int total = die1.getValue() + die2.getValue(); if (total == 7 || total == 11) { // Player wins one credit credits++; } else if (total == 2 || total == 3 || total == 12) { // Player loses one credit credits--; } else { // Set the goal for future rolls int goal = total;…arrow_forwardpublic class Test { } public static void main(String[] args){ int a = 10; System.out.println(a*a--); }arrow_forwardIdentify the error(s) in the program and describe why this error occurs. Rewrite the code after correcting all errors. package Overview interface MyInt{ int a; void seta(int alpha); } public class CheckTest implements MyInt { @Override public void seta(int alpha) {a = alpha;} public static void main(String[] args) { seta(5); } }arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_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