Jack Green

All generations.

generate functionThu, 25 Apr 2024

Program 1: RoadProfiler RoadProfiler: Pass level You must complete this part even if you want to do the Challenge level. You are to complete 3 methods that all participate in analysing and displaying the profile of a section of a road, based on a GPS measurements every 10 meters along the section of road. printAverageHeight method so that it computes and prints out the average height of the road. maximumHeight method so that it finds and returns the maximum height in the list. displayProfile method so that it plots the profile by drawing lines from each measurement point to the next. Output with input from heights.txt: road-profiler-screenshot.png Instructions and Tips: The average of a set of numbers is the sum of the numbers, divided how many numbers there are. To find the maximum, your loop will need to keep track of the largest height seen so far. You may want to use the value Double.NEGATIVE_INFINITY which is the smallest number that Java recognises. You must use the LEFT, SEA_LEVEL, and STEP constants. The analyseProfile() method (completed for you) reads a sequence of heights from the user, using the UI.askNumbers() method, then calls the 3 methods you need to complete. For testing, you can avoid having to type all the numbers each time by selecting "Set Input" on the UI frame's MENU then choose the file heights.txt. The UI will then automatically input the input from that file instead of waiting for you to type the numbers.

mport java.util.*; import java.io.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; import javax.swing.text.*; import javax.swing.border.*; import javax.swing.pl

Java
View
generate functionSat, 16 Mar 2024

You are to complete 3 methods that all participate in drawing fancy rectangles: A fancy rectangle consists of three horizontal stripes that each contains a circle. The circles can be either filled or just outlined. Each stripe has its own height and colour. The diameter of each circle is 20% of the height of the stripe. For the top stripe, the circle is centered in the left-most third of the stripe. For the second stripe, the circle is centered in the middle third of the stripe. For the bottom stripe, the circle is centered in the right-most third of the stripe. The rectangle is 2/3 as high as it is wide (ratio 2:3) OR The width of the flag is 1.5 times the height of the flag.

ublic class Rectangle { public void draw(Graphics g) { g.setColor(Color.RED); g.fillRect(x, y, width, height); } } public class Circle { public void draw(Graphics g) { g.setColor(Color.RED); g.fillOval(x, y, width,

Java
View
generate functionSat, 16 Mar 2024

You are to complete 3 methods that all participate in drawing fancy rectangles: A fancy rectangle consists of three horizontal stripes that each contains a circle. The circles can be either filled or just outlined. Each stripe has its own height and colour. The diameter of each circle is 20% of the height of the stripe. For the top stripe, the circle is centered in the left-most third of the stripe. For the second stripe, the circle is centered in the middle third of the stripe. For the bottom stripe, the circle is centered in the right-most third of the stripe. The rectangle is 2/3 as high as it is wide (ratio 2:3) OR The width of the flag is 1.5 times the height of the flag. Below is an example of such rectangle where the circles are filled. right The vertical lines are not part of the rectangle. They just illustrate how all columns are the same width (one third of the total width of the rectangle). doFancyRect method so that: it asks for the height of each stripes, and whether the circles are filled or outlined, it then calls drawFancyRect with the necessary arguments. tip Note that we have written part of the code for you but it is not complete. drawFancyRect: it needs parameters, it must call drawStripe three times, it draws a black rectangle to outline the complete rectangle. drawStripe also needs parameters. It draws a stripe of the given width, height and colour with a circle at a given position.

ublic class Rectangle { public static void main(String[] args) { Rectangle r = new Rectangle(10, 10); System.out.println(r.getArea()); } private int width; private int height; public Rectangle(int width, int height) { this.width = width; this.height = height; } public int

Java
View
generate functionSat, 16 Mar 2024

The diameter of each circle is 20% of the height of the stripe. For the top stripe, the circle is centered in the left-most third of the stripe. For the second stripe, the circle is centered in the middle third of the stripe. For the bottom stripe, the circle is centered in the right-most third of the stripe. The rectangle is 2/3 as high as it is wide (ratio 2:3) OR The width of the flag is 1.5 times the height of the flag. oFancyRect method so that: it asks for the height of each stripes, and whether the circles are filled or outlined, it then calls drawFancyRect with the necessary arguments. tip Note that we have written part of the code for you but it is not complete. drawFancyRect: it needs parameters, it must call drawStripe three times, it draws a black rectangle to outline the complete rectangle. drawStripe also needs parameters. It draws a stripe of the given width, height and colour with a circle at a given position.

ublic class FancyRect { public static void main(String[] args) { int height = 100; int width = 100; int x = 0; int y = 0; int color = 0; int color2 = 0; int color3 = 0; int color4 = 0; int color5 = 0; int color6 = 0; int color7 = 0; int

Java
View
generate functionSat, 16 Mar 2024

You are to complete 3 methods that all participate in drawing fancy rectangles: A fancy rectangle consists of three horizontal stripes that each contains a circle. The circles can be either filled or just outlined. Each stripe has its own height and colour. The diameter of each circle is 20% of the height of the stripe. For the top stripe, the circle is centered in the left-most third of the stripe. For the second stripe, the circle is centered in the middle third of the stripe. For the bottom stripe, the circle is centered in the right-most third of the stripe. The rectangle is 2/3 as high as it is wide (ratio 2:3) OR The width of the flag is 1.5 times the height of the flag. oFancyRect method so that: it asks for the height of each stripes, and whether the circles are filled or outlined, it then calls drawFancyRect with the necessary arguments. tip Note that we have written part of the code for you but it is not complete. drawFancyRect: it needs parameters, it must call drawStripe three times, it draws a black rectangle to outline the complete rectangle. drawStripe also needs parameters. It draws a stripe of the given width, height and colour with a circle at a given position.

ublic class Rectangle { public static void main(String[] args) { Rectangle r = new Rectangle(10, 10); System.out.println(r.getArea()); } private int width; private int height; public Rectangle(int width, int height) { this.width = width; this.height = height; } public int

Java
View
generate functionSat, 16 Mar 2024

You are to complete 3 methods that all participate in drawing fancy rectangles: A fancy rectangle consists of three horizontal stripes that each contains a circle. The circles can be either filled or just outlined. Each stripe has its own height and colour. The diameter of each circle is 20% of the height of the stripe. For the top stripe, the circle is centered in the left-most third of the stripe. For the second stripe, the circle is centered in the middle third of the stripe. For the bottom stripe, the circle is centered in the right-most third of the stripe. The rectangle is 2/3 as high as it is wide (ratio 2:3) OR The width of the flag is 1.5 times the height of the flag.

ublic class Rectangle { public void draw(Graphics g) { g.setColor(Color.RED); g.fillRect(x, y, width, height); } } public class Circle { public void draw(Graphics g) { g.setColor(Color.RED); g.fillOval(x, y, width,

Java
View
class from descriptionMon, 18 Mar 2024

To summarize, you need to implement three methods for drawing fancy rectangles according to specific requirements: doFancyRect method: Prompts the user for the height of each stripe and whether the circles should be filled or outlined. Calls the drawFancyRect method with the necessary arguments based on the user input. drawFancyRect method: Takes parameters. Calls the drawStripe method three times, each time with specific arguments. Draws a black rectangle to outline the complete rectangle. drawStripe method: Takes parameters for width, height, color, and circle position. Draws a stripe with the given width, height, and color. Draws a circle at the specified position within the stripe. Additionally, the circles in each stripe have specific positions and sizes relative to the stripe's height and width, and the rectangle's dimensions are defined with a specific aspect ratio (2:3) or width-to-height ratio (1.5).

mport java.util.Scanner; public class FancyRect { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter the length of the first side: "); int length1 = input.nextInt(); System.out.println("Enter the length of the second side:

Java
View
generate functionSat, 16 Mar 2024

You are to complete 3 methods that all participate in drawing fancy rectangles: A fancy rectangle consists of three horizontal stripes that each contains a circle. The circles can be either filled or just outlined. Each stripe has its own height and colour. The diameter of each circle is 20% of the height of the stripe. For the top stripe, the circle is centered in the left-most third of the stripe. For the second stripe, the circle is centered in the middle third of the stripe. For the bottom stripe, the circle is centered in the right-most third of the stripe. The rectangle is 2/3 as high as it is wide (ratio 2:3) OR The width of the flag is 1.5 times the height of the flag. Below is an example of such rectangle where the circles are filled. right The vertical lines are not part of the rectangle. They just illustrate how all columns are the same width (one third of the total width of the rectangle). doFancyRect method so that: it asks for the height of each stripes, and whether the circles are filled or outlined, it then calls drawFancyRect with the necessary arguments. tip Note that we have written part of the code for you but it is not complete. drawFancyRect: it needs parameters, it must call drawStripe three times, it draws a black rectangle to outline the complete rectangle. drawStripe also needs parameters. It draws a stripe of the given width, height and colour with a circle at a given position.

ublic class Rectangle { public static void main(String[] args) { Rectangle r = new Rectangle(10, 10); System.out.println(r.getArea()); } private int width; private int height; public Rectangle(int width, int height) { this.width = width; this.height = height; } public int

Java
View
generate functionMon, 18 Mar 2024

To summarize, you need to implement three methods for drawing fancy rectangles according to specific requirements: doFancyRect method: Prompts the user for the height of each stripe and whether the circles should be filled or outlined. Calls the drawFancyRect method with the necessary arguments based on the user input. drawFancyRect method: Takes parameters. Calls the drawStripe method three times, each time with specific arguments. Draws a black rectangle to outline the complete rectangle. drawStripe method: Takes parameters for width, height, color, and circle position. Draws a stripe with the given width, height, and color. Draws a circle at the specified position within the stripe. Additionally, the circles in each stripe have specific positions and sizes relative to the stripe's height and width, and the rectangle's dimensions are defined with a specific aspect ratio (2:3) or width-to-height ratio (1.5).

ublic class Rectangle { public static void main(String[] args) { Rectangle rect = new Rectangle(10, 10, 10, 10); System.out.println(rect.getArea()); } private int width; private int height; private int length; private int breadth; public Rectangle(int width, int height, int length, int breadth)

Java
View

Questions about programming?Chat with your personal AI assistant