Question

In: Computer Science

I need to draw a cylinder in java with user input, and I can't seem to...

I need to draw a cylinder in java with user input, and I can't seem to get my lines to line up with my ovals correctly from the users input...

I know I will have to either add or subtract part of the radius or height but I'm just not getting it right, here is how I'm looking to do it.

           g.drawOval(80, 110, radius, height);
           g.drawLine(?, ?, ?, ?);
g.drawLine(?, ?, ?, ?);
           g.drawOval(80, 200, radius, height);

Solutions

Expert Solution

Solution:

As per your problem statement I had designed the code for drawing cylinder in java. Iam adding my source code and screenshot for your reference

Note: I have not taken inputs as user based, I had provided you the co-ordinates to work on. So if you want, just store value in variable and pass the values in  g.methods(ur_variablename,...) , keep playing with co-ordinates to get better idea.

Hope so it will surely help you.

Source Code:

import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JFrame;

public class GUI extends JPanel {

  
   public static void main(String[] args) {
      
       JFrame f = new JFrame(); //maked object for using frame
   f.setSize(800, 800); // set the size for frame
   f.setBackground(Color.white); // setted background color
   f.setForeground(Color.black); // setted foreground color
   f.add(new GUI()); // called this class to repaint window
  
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // to close window
   f.setVisible(true); // maked the frame visible
  
   }
   public void paint(Graphics g) { //initiated paint class to draw on window
         
   g.drawOval(51,51,231,71); //method to draw oval shape
   g.drawLine(51,81,51,331); //method to draw line
   g.drawLine(281,81,280,331); //method to draw line
   g.drawOval(51,301,231,71); //method to draw oval shape
  
   }
   }

ScreenShots:

Code:

Output:


Related Solutions

Java Programming I need an application that collects the user input numbers into an array and...
Java Programming I need an application that collects the user input numbers into an array and after that calls a method that sums all the elements of this array. and display the array elements and the total to the user. The user decides when to stop inputting the numbers. Thanks for your help!
I need to write a program and can't seem to make it run properly. Someone can...
I need to write a program and can't seem to make it run properly. Someone can help with the coding? It's with python Thanks! Here is the program: The rules of Shut the Box are as follows (abbreviated version): + You have two 5-sided die + You have 5 wooden blocks (labeled 1 through 5) + Each turn, you roll the dice and knock down the blocks corresponding to the number on each die + You have to knock down...
JAVA - I am asking for the user to input their firstName and lastName but I...
JAVA - I am asking for the user to input their firstName and lastName but I want the method myMethod() to be able to print it when it is called. Is that possible? I'm new to Java and i'm not too sure what I should do to fix this. Also if I were to create a IF statement would I have to declare int amountDeposited; , int accountBalance; , int newBalance; in the new if statement. import java.util.Scanner; import java.util.Arrays;...
JAVA JAVA JAVA . I need to convert a string input to int array, for example...
JAVA JAVA JAVA . I need to convert a string input to int array, for example if user enters 12 / 27 / 2020 , I want to store each value in a separate array and add them afterwards.
My Java program keeps "running." I know I need to close a "loop" but I can't...
My Java program keeps "running." I know I need to close a "loop" but I can't find it. I'm learning how to code. This is confusing for me. import java.util.Scanner; import java.util.ArrayList; public class SteppingStone4_Loops {    public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String recipeName = ""; ArrayList<String> ingredientList = new ArrayList(); String newIngredient = ""; boolean addMoreIngredients = true; System.out.println("Please enter the recipe name: "); recipeName = scnr.nextLine();    do {    System.out.println("Would you...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input system for a university student, where they put the season and year of when they started their uni course. For example the system will ask "What year did you start your degree?", the user will input "Autumn/2022" as a string. Now from a string format as shown, it should take that user input and calculate for example +2 or +3 years to the date....
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
This isn't a homework but since I can't seem to find any answers for it, I...
This isn't a homework but since I can't seem to find any answers for it, I would like to receive some insights from you experts! So, I heard that UK has official left the European Union on Jan 31st (aka Brexit). Are there any trade deals that have been signed? or any negotiations that has been reached? please provide me with some updates I can't seem to find any info on which trade deals were signed and etc. thanks! p.s...
Hi there, I am having a bit of an issue that I just can't seem to...
Hi there, I am having a bit of an issue that I just can't seem to figure it out. My code is supposed to read from another file and then have an output of a number for each categorie ////////Required Output/////// Movies in Silent Era: 0\n Movies in Pre-Golden Era: 7\n Movies in Golden Era: 581\n Movies in Change Era: 3445\n Movies in Modern Era: 10165\n Movies in New Millennium Era: 15457\n My program is: import java.util.ArrayList; public class MovieReducerEraCount...
I need to make this into a Java Code: Write a program that prompts the user...
I need to make this into a Java Code: Write a program that prompts the user for a double value representing a radius. You will use the radius to calculate: circleCircumference = 2πr circleArea = πr2 sphereArea = 4πr2 sphereVolume = 43πr3 You must use π as defined in the java.lang.Math class. Your prompt to the user to enter the number of days must be: Enter radius: Your output must be of the format: Circle Circumference = circleCircumference Circle Area...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT