
Building Java Programs: A Back To Basics Approach (5th Edition)
5th Edition
ISBN: 9780135471944
Author: Stuart Reges, Marty Stepp
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 3, Problem 1PP
Program Plan Intro
Print Christmas tree
- Import the required package.
- Create a class “ChristmasTree”,
- Define the method “main()”,
- Declare the necessary variables.
- Create “Scanner” object.
- Prompt the user to enter the number of segments and height of the Christmas tree.
- Get the number of segments and height from the user.
- Print new line.
- Assign the number of segments and height to the variable “m” and “n” respectively.
- Set the starting row value to “1”.
- Create “for” loop to iterate till number of segments using “i”,
- Create “for” loop to iterate till the height of the tree using “j”,
- Execute “while” loop,
-
- Print space.
- Increment counter variable.
- Create loop whenever the number of rows greater than the “i” value,
-
- Print space.
- Create loop whenever the “j” value is less than or equal to “i” value,
-
- Print “*”.
- Create loop using the variable “k” whenever the value is less than “i”,
-
- Print “*”.
- Print new line.
- Increment the starting row.
- Increment the number of rows.
- Create “for” loop to iterate till the height of the tree using “j”,
- Print stem of the tree as follows,
- Create loop till the value get from dividing the (number of rows*number of segments-1) by “2”,
- Print space.
- Print “*”.
- Create loop till the value get from dividing the (number of rows*number of segments-1) by “2”,
- Print space.
- Print “*”.
- Create loop till the value get from subtracting “3” from the value which is obtained from dividing the (number of rows*number of segments-1) by “2”,
- Print the space.
- Create loop till the value “7”.
- Print “*”.
- Define the method “main()”,
Expert Solution & Answer

Want to see the full answer?
Check out a sample textbook solution
Students have asked these similar questions
What are quantitative and qualitative data? Describe an example of a use case and visual representation for qualitative data and one for quantitative data from your organization.
1. Checksum. Assuming the following IP header lacking checksum:
01000101.00000000.11000011.00101010.
00000000.00000000.00000000.00000000.
10000000.00000000.00000000.00000000. <- checksum
01100011.11011001.00000000.00000001.
10000000.00000000.00000000.00000010
Compute its checksum
I would like to know the features of BranchCache, Metadata, and LPR Port Monitor
Chapter 3 Solutions
Building Java Programs: A Back To Basics Approach (5th Edition)
Ch. 3.1 - Which of the following is the correct syntax for a...Ch. 3.1 - Prob. 2SCPCh. 3.1 - Prob. 3SCPCh. 3.1 - Prob. 4SCPCh. 3.1 - Prob. 5SCPCh. 3.1 - What is the output of the following...Ch. 3.1 - Prob. 7SCPCh. 3.1 - Prob. 8SCPCh. 3.1 - Prob. 9SCPCh. 3.1 -
Write a method called printStrings that accepts a...
Ch. 3.1 - Prob. 11SCPCh. 3.2 -
What is wrong with the following program?
public...Ch. 3.2 -
Evaluate the following expressions:
a Math.abs...Ch. 3.2 -
What output is produced by the following...Ch. 3.2 - Prob. 15SCPCh. 3.2 - Prob. 16SCPCh. 3.2 -
Write a method called countQuarters that takes an...Ch. 3.3 - Prob. 18SCPCh. 3.3 - Prob. 19SCPCh. 3.3 - Prob. 20SCPCh. 3.3 - Prob. 21SCPCh. 3.3 -
Consider the following code fragment:
Scanner...Ch. 3.3 - Prob. 23SCPCh. 3.3 - Prob. 24SCPCh. 3.3 - Prob. 25SCPCh. 3 - Prob. 1ECh. 3 -
Write a method called printPowersOf2 that accepts...Ch. 3 -
Write a method called printPowersOfN that accepts...Ch. 3 - Prob. 4ECh. 3 - Prob. 5ECh. 3 - Prob. 6ECh. 3 -
Write a variation of the largestAbsVal method...Ch. 3 -
Write a method called quadratic that solves...Ch. 3 -
Write a method called lastDigit that returns the...Ch. 3 - Prob. 10ECh. 3 - Prob. 11ECh. 3 - Prob. 12ECh. 3 - Prob. 13ECh. 3 - Prob. 14ECh. 3 - Prob. 15ECh. 3 - Prob. 16ECh. 3 - Prob. 17ECh. 3 -
Write a method called vertical that accepts a...Ch. 3 - Prob. 19ECh. 3 - Prob. 20ECh. 3 - Prob. 21ECh. 3 - Prob. 22ECh. 3 - Write a method called printIndexed that accepts a...Ch. 3 - Write a program that produces images of Christmas...Ch. 3 - Prob. 2PPCh. 3 - Prob. 3PPCh. 3 - Prob. 4PPCh. 3 - Prob. 5PPCh. 3 - Write a program that produces calendars as output....
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
- Please answer the JAVA OOP questions below: How do arrays of objects differ from arrays of primitive types? Why and when would you use an array of objects? What are the different ways to initialize an array of objects? What is a static variable in Java? How does its scope differ from instance variables? When should you use static variables? Provide examples where static variables are beneficial over instance variables. What is the difference between static and non-static methods in the Data Definition Class? What are the benefits of using static methods?arrow_forwardAssume you are a loyal member of Costco. You have been expecting your membership reward from the company, and you just received a text message on your mobile phone. The message appears to be from Costco: Costco - Your 3% return is ready: costco.wholesaledividend.com Before clicking the link in the message, you consider whether this is genuinely from Costco or a phishing attack on you. How can you tell? If it is a phishing attack, what mechanism was most likely used to send the message to you? What actions can you take if you are not sure whether it is a genuine message from Costco? What actions can you take if you are sure this is a phishing attack?arrow_forwardRSA and Diffie-Hellman are important algorithms in public-key cryptography. What are the differences between the two? Assume you intercept the ciphertext C = 105 sent to a user whose public key is e = 7, n = 403. Explain in detail how you will find the private key of the user and crack the ciphertext. What is the plaintext M?arrow_forward
- CBC-Pad is a block cipher mode of operation commonly used in block ciphers. CBC-Pad handles plain text of any length. Padding is used to ensure that the plaintext input is a multiple of the block length. Hence, the ciphertext is longer than the plaintext by at most the size of a single block.Assume that the original plaintext is 556 bytes and the size of a cipher block is 28 bytes. What will be the padding? If the original plaintext is an integer multiple of the block size, will padding still be needed? Why or why not?arrow_forwardAbstract classes & Interfaces (Ch13) 5. See the code below and solve the following. class Circle { protected double radius; // Default constructor public Circle() ( } this(1.0); // Construct circle with specified radius public Circle(double radius) { } this.radius radius; // Getter method for radius public double getRadius() { } return radius; // Setter method for radius public void setRadius(double radius) { } this.radius = radius; // Implement the findArea method defined in GeometricObject public double findArea() { } return radius* radius * Math. PI; // Implement the find Perimeter method defined in GeometricObject public double findPerimeter() { } return 2*radius*Math.PI; // Override the equals() method defined in the Object class public boolean equals(Circlel circle) { } return this.radius == circle.getRadius(); // Override the toString() method defined in the Object class public String toString() { } } return "[Circle] radius = " + radius; 5-1. Define a class name…arrow_forward6. What is Race condition? How to prevent it? [2 marks] 7. How many synchronization methods do you know and compare the differences. [2 marks] 8. Explain what are the “mutual exclusion”, “deadlock”, “livelock”, and “eventual entry”, with the traffic intersection as an example like dinning philosophy. [2 marks] 9. For memory allocation, what are the difference between internal fragmentation and external fragmentation. Explain with an example. [2 marks] 10. How can the virtual memory map to the physical memory. Explain with an example. [2 marks]arrow_forward
- Your answers normally have 50 words. Less than 50 words will not get marks. 1. What is context switch between multiple processes? [2 marks] 2. Draw the memory layout for a C program. [2 marks] 3. How many states does a process has? [2 marks] 4. Compare the non-preemptitve scheduling and preemptive scheduling. [2 marks] 5. Given 4 process and their arrival times and next CPU burst times, what are the average times and average Turnaround time, for different scheduling algorithms including: a. First Come, First-Served (FCFS) Scheduling [2 marks] b. Shortest-Job-First (SJF) Scheduling [2 marks] c. Shortest-remaining-time-first [2 marks] d. Priority Scheduling [2 marks] e. Round Robin (RR) [2 marks] Process Arrival Time Burst Time P1 0 8 P2 1 9 P3 3 2 P4 5 4arrow_forwarda database with multiple tables from attributes as shown above that are in 3NF, showing PK, non-key attributes, and FK for each table? Assume the tables are already in 1NF. [Hint: 3 tables will result after deducing 1NF -> 2NF -> 3NF]arrow_forwarda database with multiple tables from attributes as shown above that are in 3NF, showing PK, non-key attributes, and FK for each table? Assume the tables are already in 1NF. [Hint: 3 tables will result after deducing 1NF -> 2NF -> 3NF]arrow_forward
- If a new entity Order_Details is introduced, will it be a strong entity or weak entity? If it is a weak entity, then mention its type (ID or Non-ID, also Justify why)?arrow_forwardWhich one of the 4 Entities mention in the diagram can have a recursive relationship? Order, Product, store, customer.arrow_forwardInheritance & Polymorphism (Ch11) There are 6 classes including Person, Student, Employee, Faculty, and Staff. 4. Problem Description: • • Design a class named Person and its two subclasses named student and Employee. • Make Faculty and Staff subclasses of Employee. • A person has a name, address, phone number, and e-mail address. • • • A person has a class status (freshman, sophomore, junior and senior). Define the status as a constant. An employee has an office, salary, and date hired. A faculty member has office hours and a rank. A staff member has a title. Override the toString() method in each class to display the class name and the person's name. 4-1. Explain on how you would code this program. (1 point) 4-2. Implement the program. (2 point) 4-3. Explain your code. (2 point)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 Math Library; Author: Alex Lee;https://www.youtube.com/watch?v=ufegX5o8uc4;License: Standard YouTube License, CC-BY