Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The last photo is what i have so far so if you could add to that please!!!! thank you im stuck on the segment part
The last photo is what i have so far so if you could add to that please!!!! thank you im stuck on the segment part
*** Overview: In this assignment, you will write a Java program in a file named DrawTrees.java that can generate 1/0 (input/output) sessions such as Sample Session 1 shown below. Note that user input is shown underlined only for easy identification, and is not part of the I/O. You will use the following new Java language elements in your program: parameters for controlling the behavior of a method methods that return a value (non-void methods) a Java Scanner object for getting console input from the user Sample I/O Session 1 Implementation Requirements: Your program will contain the following elements: Enter height: 4 Enter number of segments: 3 In the same way you made the public static class Enter till character: - constant in Lab 2, make a public static Scanner class object connected to the System.in console input device (the keyboard). As a class object 1. it will be in the scope of all the methods in the class, 2. it won't have to be passed as a parameter to all the methods that input data from the keyboard. Define a method named getAttribute with the following header public static int getAttribute(String prompt) This getAttribute method performs exactly and only the 3 tasks described below. 1. Display the prompt parameter that was passed to it. 2. Input an int value from the user. Functionality: You will be 3. Return (not display) the value input by the user in task drawing evergreen trees that are 2. characterized by main() will call getAttribute twice: once to get the the number of segments height of the tree, and again to get the number of the height of the segments segments in the tree. See 3.2 and its Common the fill character used to Programming Error Ignoring the Returned Value section draw the tree for the correct way to call a method that returns a value. Your program should be able to Your program will define another parameterized method reproduce exactly any of the of your own design that is called by main(). sample 1/0 sessions shown in this document, using only the Java Your program will define another parameterized method language elements presented in of your own design that is called by another method that is chapters 1-3 of the textbook not main. main will contain calls to only your methods. That is, no NOTE: Don't miss the WARNING section on the last page. calls to println, next Int, etc. If those calls are within assignment statements that is OK. Write the subset of your DrawTrees.java program that does the following: Declare the class Scanner object connected to the System. in keyboard input stream Implement the getAttributo method as per the requirements described above. Have main call the getAttribute method twice to input A) the value for the height of the tree and B) the number of segments in the tree. For the checkpoint, have main() display those values to confirm everything is working correctly. Your checkpoint should be able to generate the following I/O session, where user input is underlined only for easy identification: Enter height: 3 Enter number of segments: 4 Height = 3 and segments - 4 The last line of output is displayed by main(). That last line will not remain in the final version of the program. It is only here for the checkpoint to confirm that the main () method and the getAttribute() method are communicating with each other properly. End Lab 3 Checkpoint Specs Style Requirements Consult the Good Style Specifications page in the Quick Links module on the Canvas website. All requirements in the As of Lab 1. As of Lab 2 and As of Lab 3 sections are now in effect. More Sample I/O Sessions Sample I/O Session 2 Sample I/O Session 3 Enter height: 3 Enter height: 5 Enter number of segments: 5 Enter number of segments: 2 Enter till character: x Enter till character: ! ! XXX !!!!!!! !!! !!!!!!! xxxxx XXX xxxxx xxxxxxx XXXXX XXXXXXX xxxxxxxxx XXXXXXX XXXXXXXXX XXXXXXXXXXX XXXXXXXXX XXXXXXXXXXX XXXXXXXXXXXXX X X XXXXXXX Sample 1/0 Session 4 Enter height: 10 Enter number of segments: 3 Enter till character: I Sample 1/0 Session 5 Enter height: 4 Enter number of segments: 3 Enter fill character: 9 ### ##### ####### 000 GO000 0000000 000 OOOOO 000000000 00000 0000000 00000000000 O ### +++++ ###### D OOOOOOO ### ## ####### WARNING: Chapter 3 was all about writing and calling methods that accept parameters and/or have non-void return values. Students who solve this lab project without employing these new language elements, as instructed in these specs, will receive no more than 5 total points for this lab. That is, the student will lose all 3 implementation points, and all 2 style points, even if the program runs perfectly Students avoid writing and calling their own methods that accept parameters and/or return non-void values by declaring class-level variables, even though Good Style Specifications say to declare variables at the most restrictive scope possible and/or writing all of the code in main().even though specs say main() should call only other methods that you wrote. # # # # # # # 1 //This program prompts the user for tree size and shapes and then 2 //draws a tree figure out of that information 3 4 import java.util.*; 5 6 public class DrawTrees { 7 public static void main(String[] args) { 8 Scanner console = new Scanner(System.in); 9 System.out.print("Enter height: "); 10 int triangleSize = console.nextInt(); 11 System.out.print("Enter number of segments: "); 12 String segments = console.next(); 13 System.out.print("Enter fill character: "); 14 String fill = console.next(); 15 drawTriangle(triangleSize, fill, segments); 16 } 17 public static void drawTriangle(int size, String fill, String segments) { 19 for (int line = 1; line Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started