logo

Java Program to Draw Shapes - Desklib

10 Pages1283 Words284 Views
   

Added on  2019-10-18

About This Document

This Java program allows users to draw different shapes like circle, X, box, and box with X. The program takes user input and draws the shapes accordingly. Users can choose to fill the shapes or leave them empty. The program also writes the output to a file. This program is useful for beginners who want to learn how to draw shapes in Java.

Java Program to Draw Shapes - Desklib

   Added on 2019-10-18

ShareRelated Documents
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */package main;import java.util.Scanner; import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;/** * * @author pkum80 */public class Main { public static void main(String[] args) { int choice =0; Scanner sc=new Scanner(System.in); boolean fill = false; do { System.out.println("1. Draw Circle"); System.out.println("2. Draw X"); System.out.println("3. Draw Box"); System.out.println("4. Draw Box with X"); System.out.println("5. Exit"); System.out.print("Please enter your choice ?");
Java Program to Draw Shapes - Desklib_1
choice = sc.nextInt(); switch(choice) { case 1: double r =0.0; while(true) { System.out.print("Please enter radius of circle ?"); r = sc.nextDouble(); if(r>0) { break; } else { System.out.println("Radius cannot be less than 0"); } } sc.nextLine(); System.out.print("Do you want to fill the object ?"); if(sc.nextLine().equalsIgnoreCase("Y")) fill = true; else fill = false; drawCircle(r,fill); break; case 2: int x_size =0;
Java Program to Draw Shapes - Desklib_2
while(true) { System.out.print("Please enter Size of X ?"); x_size = sc.nextInt(); if(x_size>2) { break; } else { System.out.println("Size cannot be less than 3"); } } printX(x_size); break; case 3: int box_size =0; while(true) { System.out.print("Please enter Size of Box ?"); box_size = sc.nextInt(); if(box_size>1) { break; } else { System.out.println("Size cannot be less than 2");
Java Program to Draw Shapes - Desklib_3

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
NIM Game Playing Interface in Java
|8
|2250
|180

Object Oriented Programming with Java
|9
|1142
|153

CarYardMIT162011 Class Implementation in Java
|6
|1107
|393

Efficient and Debugged Java Program for IDSearch
|4
|1456
|442

Memory Sequence Game - Java Program for Console Based Game
|8
|998
|259

JAVA Program Using Array of Objects
|28
|2144
|15