Consider the getArea method from the textbook shown belov public int getArea() if (width <= 0) { return 0; } // line #1 if (width Triangle smallerTriangle = new Triangle (width - 1); // line #3 int smallerArea = return smallerArea + width; // line #5 1) { return 1; } // line #2 %=D%3D %3D smallerTriangle.getArea (); // line #4 Assume that line #3 is changed to this: Triangle smallerTriangle - new Triangle (width); %3D This would cause infinite recursion for 51- O triangles with width equal to 1 O triangles with width equal to 0 triangles of any width O triangles with width greater than or equal to 2
Q: Update Bresenham’s line (JAVA) method such that you can scale the line before drawing it. Normally,…
A: The algorithm is employed for scan converting a line. it had been developed by Bresenham. it's an…
Q: Define a method calcPyramidVolume with double data type parameters baseLength, baseWidth, and…
A: public class Main { public static void main(String[] args) { //call calcPyramidVolume double…
Q: Write a method drawPentagon that draws a pentagon.
A: As there is no programming language mentioned i draw Pentagon using Python. We use turtle module…
Q: Implement any one of the following methods. That will be a good exercise for you if you choose to…
A: Given The answer is given below.
Q: that ranges from 1 to 100, however this is not exactly the case. Sometimes, there will be gaps…
A: Given: The input to this method is supposedly an ArrayList of integers that ranges from 1 to 100,…
Q: Given the GVCoin class, complete the method flipForHeads() in the TossingCoins class that counts and…
A: Here I have defined the function flipForHeads(). In this function, I have created a variable to…
Q: Using the methods pickDir() and exractInt() as shown below, to write a simple automated game: how…
A: The program is written in java. MAXLOOPS is set to 20
Q: Create a class that represents the grade distribution for a given course. In this class you should…
A: code is given below:
Q: Suppose that you are asked to analyze the Big-Oh of the following method pop(). What pieces of…
A: Big-Oh notation: It is a simplified analysis of an algorithms efficiency. It gives algorithms…
Q: Please Draw a Classifier with Name "Bank Transection" having a method with following statement "A…
A: Given : Method Name - Bank Transection Input parameter - Amount: Float Output parameter -…
Q: Given a string, write a method to find the first non-repeating vowel (a, e, i, o, u) in it and…
A: The answer is given below.
Q: Task: Implement the following classes and test their methods. Shape |- color : String - filled :…
A: Given: write this java code
Q: Given the following code, for a vacation expense tracking simulation: public class Vacation Budget {…
A: Here in VacationBudget class we have a method payExpenses() public void payExpenses (double…
Q: Create a class that represents the grade distribution for a given course. In this class you should…
A: your code is given below:
Q: A pet shop wants to give a discount to its clients if they buy one or more pets and at least four…
A: The program has two main parts – the part which receives the input and the part which validates the…
Q: Without adding any method or function to the classes shown below. Find out the coverage of the…
A: #include <iostream>#include <cstdlib>#include <iomanip>#include…
Q: Create new method in the Rectangle class called getArea to calculate the area of the rectangle.…
A: Here I have created a class Rectangle, with 2 variables length and breadth. Then I have created a…
Q: This method plays 24 rounds of rps and returns the total points earned. For each of the 24 rounds,…
A: Note: Below is the required program in Java language. Program Approach: Importing the necessary…
Q: Need help writing the following method: getWaitlistedStudents() – returns an array of Students in…
A: From the sample code given, it can be seen that waitlist is a linked list of type students. To…
Q: Without adding any method or function to the classes shown below. Find out the coverage of the…
A: #include <iostream>#include <cstdlib>#include <iomanip>#include…
Q: What is wrong with the following code? // voluminous.java: interface voluminous public double volume…
A: Here, we have to provide answers to the above questions.
Q: public static JigsawPuzzle (1 method1() return new JigsawPuzzle [) { new JigsawPuzzle(new…
A: It is defined as a picture of the state of the computer's memory at a specific point in time. There…
Q: mefine a method pyramidVolume with double data type parameters baselength, baseWidth, and…
A: import java.util.Scanner; public class Main{ public static double pyramidVolume(double…
Q: Write static methods: public static double sphereVolume(double r) :-ar public static double…
A: Only the first question will be answered since two questions are asked. please upload second part…
Q: also need help Write a second constructor that takes a String array of pages as input and sets the…
A: 1- Rules of the array: Array must be initialized at the time of declaration otherwise it will throw…
Q: Answer the prompt with given main method: Code: import java.awt.*; public class TestRandomWalker…
A: Actually, program is a executable software that runs on a computer.
Q: *: Implement the following class methods batterydiseount (int Byear) method takes the current year…
A: Step 1 : Start Step 2 : Define a method batterydiscount() which receives the current year and apply…
Q: Write a class CircularArrayQueue such that all the following methods are implemented: 1. enqueue 2.…
A: Queue follows the principle in which elements that are inserted first is the one which is removed…
Q: Q2: Write the Java code corresponding to the following UML diagram. Then, create two objects from…
A: Here I have created the class named Polygon. Next, I have created the variable and then I have…
Q: Bresenham’s line (JAVA) method such that you can scale the line before drawing it. Normally, you…
A: Java is an object-oriented programming language. It is platform-independent. Bresenham's Line…
Q: This method plays 24 rounds of rps and returns the total points earned. For each of the 24 rounds,…
A: import java.util.*; public class RPS { public static int playRps(){ Random ran = new…
Q: 99 100], with missing ranges in between. Find all the missing numbers from the range, add them…
A: Correct Code: import java.util.*;public class Main { public static void…
Q: What is wrong with the following code? // voluminous.java: interface voluminous { public double…
A: The answer with output screenshot as the proof is given below
Q: Write static methods: public static double cubeVolume(double h) : h3 public static double…
A: Two questions are asked so we will give you the answer to the first question only. Please upload…
Q: palindrome is a string that reads the same both forward and backward. Examples of palindromes are…
A: Please find the answer below :
Q: Update Bresenham's line (JAVA) method such that you can scale the line before drawing it. Normally,…
A: Actually, java is a object oriented programming language. It is a platform independent.
Q: Write a method drawPolygon(int n) that draws a regular polygon with n sides (thus, n=3 draws a…
A: We have to create one function "drawPolygon" which will draw a regular polygon share with n sides.…
Q: Given the GVCoin class, complete the method flipForHeads() in the TossingCoins class that counts and…
A: Answer; The project consists of flipping a coin and using various methods to detect how many heads…
Q: Write a method that checks whether the diagonal joining the upper-left and the lower-right corners…
A: The method checkUpperLeftToLowerRight(String[][]) board will return true if and only if the elements…
Q: Java Write a class called YourFirstNameLine that represents a line segment between two Points. Your…
A: class Point { public int x; public int y; } //MyLine is the class used to draw the line class…
Q: Write a class called YourFirstNameLine that represents a line segment between two Points. Your Line…
A: class Point { public int x; public int y; } //MyLine is the class used to draw the line…
Q: Given the Solid class, extend it with: Pyramid Cylinder RectangularPrism Sphere Make sure to…
A: Actually, java is a object oriented programming language. It is a platform independent.
Q: Suppose that there is a method named drawline(x1, y1, x2, y2) that draws a line from (x1, y1) to…
A: Program Plan: How to run this file? Just save the file as DrawLine.java in a folder Open…
Q: Consider the BookArrayBag from slide #6 in the lecture-03-jan-28.pptx. Write an instance method…
A: Here is the answer:-
Q: Consider the following method. /** Postcondition: m is displayed in a rectangular matrix for…
A: yes,all numbers will correctly display rectangular manner. ex: import java.util.*; class arr13{…
Q: Given the following method: int puzzle (int base, int limit) { if (base > limit) return -1; else if…
A: The problem is based on the basics of time complexities and determining constraints in a given…
Q: Consider the Processing code below: int x = 1, y = 1; void draw (){ if (x >= 10 || y >= 10) noLoop (…
A: class HelloWorld { int x=1,y=1; void draw(){ if(x>=10 || y>=10)…
Q: A constructor that creates a regular polygon with the specified number of sides, length of side, and…
A: A constructor has the same name as the class. It is used to initialize objects as they are created.…
Q: 4.2.3: Method definition: Volume of a pyramid. Define a method pyramidVolume with double…
A: The answer is given in the below step
Q: Define a method pyramidVolume with doublé data type parameters baselength, baseWidth, and…
A: The method will take three double values and returns one double value volume
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- Implement a class that simulates a traffic light. The next method advances the color in the usual way, from green to yellow to red, then again to green. Provide two constructors, as described in the documentation of the public interface. Also supply a method that yields the number of times that this traffic light has been red. /** A simulated traffic light.*/public class TrafficLight{ private String color; private int reds; /** Constructs a green traffic light. */ public TrafficLight() { /* Your code goes here */ } /** Constructs a traffic light. @param initialColor the initial color "green", "yellow", or "red" */ public TrafficLight(String initialColor) { /* Your code goes here */ } /** Moves this traffic light to the next color. */ public void next() { /* Your code goes here */ } /** Returns the current color of this traffic light. @return the current color */ public String getColor() {…*Create a rectangle class using all methods given below.* *Use Java* Class Rectangle will have the following instance variables: •x –a double that represents the x coordinate of the lower left vertex of the rectangle •y –a double that represents the y coordinate of the lower left vertex of the rectangle •width –a double that represents the width of the rectangle •height–a double that represents the height of the rectangle •color –a String that represents the color of the rectangle •filled –a boolean variable that is true if the rectangle is filled, and false if it is not Rectangle constructor: The constructor should be: Rectangle (double x, double y, double height, double width, String color, boolean filled) Parameters are, in order,the x and y coordinates of the lower left corner, the height, the width, and the color of the rectangle. The constructor should check that these values represent a valid rectangle. If they do, then it should initialize the rectangle to these values.…Given the Solid class, extend it with: Pyramid Cylinder RectangularPrism Sphere Make sure to create the constructor and override the volume and surfaceArea methods. Also extend RectangularPrism with Cube. HINT: You can look up formulas for how to compute the volume and surface area of a certain type of shape online. ========================================== public class SolidTester{public static void main(String[] args){String name;double volume;double surfaceArea; // Pyramid constructor should take name, length, width, height// in that orderPyramid pyramid = new Pyramid("My pyramid", 1, 3, 5);name = pyramid.getName();volume = round(pyramid.volume(), 2);surfaceArea = round(pyramid.surfaceArea(), 2);System.out.println("Pyramid '" + name + "' has volume: " + volume +" and surface area: " + surfaceArea + "."); // Sphere constructor should take name then radiusSphere sphere = new Sphere("My sphere", 4);name = sphere.getName();volume = round(sphere.volume(), 2);surfaceArea =…
- Write a class CircularArrayQueue such that all the following methods are implemented: 1. enqueue 2. dequeue 3. first 4. isEmpty 5. size 6. toStringAdd the following constructor to your Rectangle class: public Rectangle(Point p, int width, int height) Construct a new Rectangle whose top-left corner is specified by the given Point and with the given width and height.Create new method in the Rectangle class called getArea to calculate the area of the rectangle. Call getArea method from the LengthWidthDemo class to print the area. In JAVA Programming please
- JAva Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is locatedat a point with integer coordinates and faces north, south, east, or west. Supply methods:public void turnLeft()public void turnRight()public void move()public Point getLocation()public String getDirection()The turnLeft and turnRight methods change the direction but not the location. The move method movesthe robot by one unit in the direction it is facing. The getDirection method returns a string “N”, “S”,“E”, “W”. For the new object, the initial location and facing should be specified. For the initial facing, 0means north, 1 means east, 2 means south, and 3 means west.A tester class, RobotTester, has been provided as follows to help you how to implement the Robot class.Therefore, implement the Robot class such that the following RobotTester class can be executed withoutany changes.import java.awt.Point;/**A class to test the Robot class.*/public class RobotTester{/**Tests the…Write the equals method for Circle2 which returns true when the radius and the color are the same as the parameter’s radius and color. The TestCircle2, Circle2 and GeometricObject2 classes are given as follows. public class TestCircle2 { public static void main(String[] args) { Circle2 c1 = new Circle2(2.3, "red"); Circle2 c2 = new Circle2(5.6, "white"); Circle2 c3 = new Circle2(2.3, "red"); System.out.println("c1 equals c2: " + c1.equals(c2)); System.out.println("c1 equals c3: " + c1.equals(c3)); System.out.println("c2 equals c3: " + c2.equals(c3)); } } class Circle2 extends GeometricObject2 { private double radius; public Circle2() { } public Circle2(double radius) { this.radius = radius; } public Circle2(double radius, String color) { this.radius = radius; setColor(color); } /** * Return radius */ public double getRadius() {…Write a static method that draws an arrow line from astartingpoint to an ending point in a pane using the following method header:public static void drawArrowLine(double startX, double startY,double endX, double endY, Pane pane) Write a test program that randomly draws an arrow line, as shown in Figure.
- in java processing , Given the number of edges “numEdge", implement a method which draws a green star on a black background with numEdge edges: void drawStar(int numEdge){ .....} note : ( write the code over here )Look at the API of the Point class and find out how to construct a Point object. Write a Java program “PointTester”, that constructs two points with coordinates (3, 4) and (–3, –4). Find the distance between them, using the distance method. Print the distance, as well as the expected value. (You may draw a sketch on graph paper to find the value you will expect.) - Update your program so it randomly select coordinate points (x,y), where −50 ≤ ? ≤ 50 ??? ? ∈ [−90, 90].Write a method drawPentagon that draws a pentagon.