Displacing A Shape Made Of Asterisks

May 5, 2014

I'm making a program that prints arrows of varying tail length, head width, and displacement.The shape algorithms are working properly, but the displacement isn't working. The first arrow has zero displacement, and the second one is supposed to be bigger and start the print at 10 spaces right and 5 spaces down from the default, but it's not working. I tried changing the displacement settings of the first arrow, and no changes happened, so I know that the positions aren't registering properly in general. How to pass the xAdj and yAdj (displacement) values? I think I have the empty space formula set up, but it's still not running.

Driver:
public class Driver
{
//default values
public static final int Arrow_Default_xAdj = 0;
public static final int Arrow_Default_yAdj = 0;
public static final int Arrow_Default_tail = 5;
public static final int Arrow_Default_width = 5;

[code]...

View Replies


ADVERTISEMENT

Printing Asterisks Shape In Java

Mar 17, 2014

I am supposed to Write a program that prints a shape similar to the following shape. Maximize use of loops and minimize use of print statements.

.....*
....**
...***
..****
...***
....**
.....*

(without the "...")(i couldn't get it to stay in shape)

This is what i got so far:

Java Code: package assignment7;

public class Exercise3
{
public static void main (String[] args)
{
for (int count =0; count < 4; count++)
{
for (int j=0; j < count+1; j++)
[Code] ....

Tthis compiles to:

*
**
***
****
**
*

How do i center it to create the shape?

View Replies View Related

Creating Shape - How To Deal With Blanks And Asterisks

Mar 16, 2014

I need to create this shape:

*" "*" "*
" "*" "*" "
" "" "*" "" "

using loops. How to deal with the blank and asterisks? Its just don't work correctly for me...

View Replies View Related

Getting Rid Of Asterisks

Mar 19, 2014

This is my code so far which is correct my only problem is that I have to make it so there doesn't become more than 50 asterisks on a line and I don't know how to do that I know the code is something divided by 50 but I dont understand where I would put it.

so instead of this

************************************************** ******************(pretend it was 100 asterisks)
it would be
****************************************(x<50 asterisks or 42)

import java.util.*;
public class Graph {
private int [] counter;
public Graph(int x) {
counter=new int[5];

[Code] ....

View Replies View Related

Bar Chart With Asterisks

Oct 12, 2014

I need to make a loop that prints out a certain number of asterisks, depending on the random number generated (includes 0-24, not including 25). I'm just in basic java programming and am stuck on this task.

These are the directions given to me:

Write a loop to do the following tasks 10 times:
-Generate a random number in the range of 0 to 24 and store in an int variable named: score
-Write loop to print a bar of asterisks proportional to the value in score :

For example: , if value stored in score is 8, the bar chart should like as follows: (value of score spaced by a tab ( ) and a series of 8 asterisks in one line)
8 ********
//end of the loop

I've tried looking for other questions like this, but this one is a random number, with no input. Yes, I know there are easier ways, but my professor is extremely picky with everything.

This is what I have so far:

public class PA5LoopsA {
public static void main(String [] args) {
//Declare variables
int score;
//Generate random number between 0 and 24
score = (int) (Math.random() * 25);

[Code] ....

Clearly, none of my formatting went through...yes, I know how to space everything out!

View Replies View Related

Bar Chart With Asterisks?

Oct 19, 2014

Here is the assignment instructions:

Overview: Use the Eclipse Java environment to create and test a program using methods that will display a bar graph.

Specifics: This assignment is an extension of the Module 5 activity, the first bar chart (asterisk) display program. You should also make use of the Bar Chart printing program of Chapter 6 (Fig. 6 in the textbook, p. 217).

Your program should use methods to accept input from the keyboard, store it in an array, and use that data to display a bar graph.

Pseudocode for the program might look like the following.

Main
declare an array of integers
get the number of asterisks in each bar
print the bar graph
get the number of asterisks in each bar
declare a Scanner input object
declare an array to fill and return

[code]....

Problem is I cannot get it to display the number of asterisks I enter as input.

View Replies View Related

How To Convert Integer To That Many Asterisks

Jan 22, 2015

int a = 5;

//how do I convert a to 5 asterisks '*'?

When I do System.out.println(a); I want there to be 5 asterisks '*****'

View Replies View Related

Draw Square With Asterisks (for Loops)

Apr 21, 2015

So currently I'm trying to learn how to draw a square with asterisks based on the input I give for it's sideLength.

So if I have a Square(5) it should draw a 5x5 looking like this:

*****
*****
*****
*****
*****

but then in the main method, it should draw multiple squares of given sizes, so say 5, 6, and 7. Making a square for each of the given numbers. This is what I currently have so far ....

class Square {
int sideLength; Square( int size ) {
sideLength= size;
} int getArea() {
return sideLength * sideLength;

[Code] ....

View Replies View Related

How Recursion Calls Are Made

Jun 5, 2014

How the recursion works. I tried to figure out writing down low, mid, high at each recursive call. But I seem to be making a mistake somehow. I don't understand where the values are returned to in

if(leftmax>rightmax){
return leftmax;}
else
return rightmax;

Here's the code:

public class Maximum{
public static int max(int[] a,int low,int high){
int mid,leftmax,rightmax;
if(low==high)
return a[low];

[Code] ....

firstly leftmax=max(a,0,4)

Then what is the next line executed?Is it rightmax=max(a,5,8).

After this is it leftmax=max(a,5,6)

rightmax=max(a,7,8)

I tried to understand what these recursion calls by writing them down.But I somehow make a mistake.

View Replies View Related

Referring To Object That Has Not Yet Been Made?

Apr 16, 2015

I am trying to make a for loop using an iterator that refers to an object of a class that hasnt been made yet. The class is called MyArrayList but it does not have a Main. A MyArrayList object is made externally so I am unsure how to refer it to the object from within the class. Is there a place holder I could use such as Object.Iterator() or something similar. I have created an inner class that implements the Iterator interface. Here is the code that I need to adjust to do this:

public class ListIterator<E> implements Iterator<E> {
public myIterator() {
Iterator it = MyArrayList.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
}

View Replies View Related

Two Windows Are Being Made Of Game

Jan 19, 2014

I have a game which is very simple: it is two images, and one needs to reach the other. Once it does, it resets. I have a class which holds the two images, and another which holds the game. My images class extends my game class. The problem I am having is that when I run the program, not one, but two frames appear. One is the perfect game, working perfectly, and the other is the game without images. I want the one that is the game without images to simply stop appearing. I believe it is appearing because my class that displays the image is extending the game class, but I can't not extend it because if I do I get a whole lot of bugs and errors.

Image class:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;

[code]....

View Replies View Related

Increase Counter When A Post Is Made?

May 15, 2015

I was wondering what the easiest way would be to keep track of everytime someone makes a new post on reddit (social media site, for those who don't know). I want the program to keep track of the number of posts made with a counter, but that's the easy part. How do I set up a program to actually communicate with and monitor reddit's servers in this manner?

View Replies View Related

JComboBox - Different Choices Depending On Selection Made

Oct 5, 2010

I am stuck trying to build a relatively "simple" GUI. The GUI should have one JComboBox that allows the user to pick from one of three locations. Then based on their choice, another JComboBox should be generated with another set of choices. The key is that the second ComboBox should have different choices depending on the selection made in the first one. So, in theory, the logic should be something like:

//create new JComboBox array of strings "locations"
//create new JComboBox array of strings "costToTravelThere"
//if user picks location 1 from the first ComboBox
then add the second ComboBox with options specific to that first location
else if user picks location 2 from first ComboBox
then add the second ComboBox with options specific to that second locatoin

I understand how to do the basic stuff, like create the JFrame and the actual panels and ComboBoxes, etc. What I don't understand is how to implement the second ComboBox dependent on the first one. I'm not very experience with Listeners and such, and I'm sure that's a big part of this.

View Replies View Related

Sort 2 Different Objects In Self Made Generic Class Using Comparator

May 31, 2014

Ok here are my 2 Classes

Both have Identical Fields

package com.Lists;
public class EmployeeOffice implements EmpInterface {
private double salary;
private String name;
private String postion;
private double hoursWorked;

[Code] .....

So if i wanna sort this Generic class using comaparator what do i do... I cant find an answer to this... I wanna sort them on the basis of salary what to do ...

View Replies View Related

Add Color To Ball In Pong - Speed Up When Contact Made With Paddle

Apr 23, 2014

I wrote a code from our text book for Pong. Im trying to figure out how to fill the ball with color. Im also wondering how to speed the ball up once there is contact with the paddle. The initial speed is ok but once contact is made with the paddle, it slows down. Makes it too easy to play. Here is my code so far. As far as the game goes, it works and is good. Just wanted to add a couple customizations.

Java Code:

package pong;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.event.ActionEvent;

[Code] .....

View Replies View Related

Change Type / Custom Color Of Rectangle Made Through DragMode

Jun 9, 2014

What I'm trying to do is basically draw a Rectangle outline through left-click and then dragging the mouse to the size one wants.

After one has created this rectangle, the user can change the color of the rectangle through clicking the 3 sliders found on the top in the program. Upon the change in color, the rectangle should change from "g.drawRect" to "g.fillRect" and use the desired color.

I have the basic outline of the program done, but working with the last part (the color and changing of the Rectangle type after changing the color)

Is there like a "then" command in Java? Like: after you've done x, do y. That would make this heaps easier.

import java.awt.event.*;
import java.awt.*;
import java.applet.*;
 
//Diese Applikation offnet ein Fenster,
//in welchem durch einen gehaltenen linken Mouse Klick
//ein Reckteck gezeichnet wird
 
public class WhatIsTheProblem006 extends Applet
implements AdjustmentListener {

[Code] ....

View Replies View Related

Not Getting A Proper Shape Of Leftarrow

Apr 22, 2014

why am I not getting a proper shape of "Leftarrow"? The result should look like the following (the system draws the arrow abnormally, so the beginning should a real ARROW:

*

* *

* *

* * * * * * * * *

* *

* *

*

here is the class:

Java Code: public class LeftArrow extends ShapeBase {
private int lengthOfTail;
private int widthOfArrowHead;

[Code]....

View Replies View Related

ASCII Star Shape

Feb 2, 2014

I am having an awful time submitting the right program for this star pattern. 2.4: Star Pattern Write a program that displays the following pattern:

*
***
*****
*******
*****

I input the following:

// Program Challenge 2.4
2
3 public class PC24
4 {
5 public static void main(String[ ] args)
6
7 /**
Newline Advances the cursor to the next line for subsequent printing p.42*/
8
9 {
10
11 System.out.println(" *
"+ " ***
"+" *****
"+"*******
"+ " *****
");
12
13
14 }
15 }

View Replies View Related

Print Triangle Shape Using Numbers?

Jun 1, 2014

i want to print triangle shape using number like

this

1

12

123

1234

12345

123456

this is my code

class shape{
public static void main(String [] args){
for(int x =0 ; x<=6;x++){
for(int y =0 ; x > y ; y++){
System.out.print(x);
}
System.out.print("
");
}
}
}

but my output is

1

22

333

4444

55555

666666

View Replies View Related

Combobox To Change Color And Shape

Nov 19, 2014

i java a project with java draw golf course and currently working on 2 combo boxes to change shape of the flag on the post and fill color as well on combo box item change. I have below code. as am new to java what to do next.

import java.awt.*;
import java.awt.event.ItemEvent;
import javax.swing.*;
public class GulfCourse extends JPanel{
public void paintComponent( Graphics g){
super.paintComponents(g);
//draw green oval

[Code]...

View Replies View Related

Graphics 2D Shape Cutter For BufferedImages

Jul 15, 2014

I'm going to make tiles for my RPG game, instead of drawing each shape of the tile, I will just draw the full tile in a spritesheet. I will create a sprite sheet of shapes that I want to clip somehow or use to cut the original full image into the shape I want. How can I, take a Buffered Image, cut it's shape and perhaps add something, giving me a Buffered Image of a cut tile with possibly added features that I can then draw with Graphics?

View Replies View Related

Cutting Out Specific SHAPE From IMAGE

Apr 9, 2014

I'm making my 2D Java game, in my own style, in my own way. I'm trying to make it as code efficient as possible and compact, it usually is easier to change that way. I'm going to use BufferedImage subdivision on tilesets to take out tiles that I need, rather than creating multiple images with a tile each. Now, I've made multiple water tiles, for how they would be arranged differently.

So let's say you have a single water spot, it will be circular, you have two water spots, you have a tile-thick line with circular ends like two little water spots connected, this makes the game look more advanced, better, more realistic and good in many other ways. But, I found that an avarage amount of shapes needed is 25. I thought, how could I make this more efficient?

Could it be possible to use like shape cutting tools or something that would take out a specific shape of a single water tile to leave out all the different shapes, this is a good idea because I could use these tools for all kinds of different tiles in order to make specific features. By tools I mean simple black shapes which will remove the unwanted parts of the tile to form the wanted shape.

View Replies View Related

Drawing Certain Shape - Printing Onto JPanel

Jun 12, 2014

I am trying to draw at my mouse a certain shape that I have set. I defined some shapes where they extend shape and draw circles and stuff. But when I click on panel it seems the paint doesnt put anything there. Debugger tells me shapes are saved though.

public void mouseClicked(MouseEvent e) {
currentX = e.getX(); 
currentY = e.getY();
Shape newShape = owner.currentBrush.clone();
picture.add(newShape);
repaint();

[Code] ....

View Replies View Related

Tetris Game - Painting A Custom Shape

Dec 10, 2014

I am currently trying to make a Tetris game, so far I've got a class drawing that extends a JPanel as my canvas, a class Square that is 1 square(20 by 20) and a class LineShape that should draw 4 squares above each other. The class Frame way below is merely to set things up.

Currently i'm able to draw objects of my class Square, so I made a class LineShape that combines both and makes a 4Square long line.

My problem is when I try to draw an object of the class LineShape, it shows nothing, removes what is already painted(the square) and gives an error message:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at LineShape.<init>(Screen.java:96)
at Drawing.paint(Screen.java:79)

I put my classes together so you can copy paste and run, make a new screen to start, to see the problem occur, go to the drawing class's paint method and uncomment these lines:

// LineShape shape = new LineShape(this);
// shape.paint(g);

Below are my classes:

import javax.swing.*;
import java.awt.*;
public class Screen {
private Frame frame;
private Frame inputFrame;
private JPanel panel;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Draw String Inside A Shape

Mar 19, 2015

I have this piece of code, i want to insert a text inside my shape.

import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import java.awt.Color;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Deleting Shape Drawn On JPanel

Apr 7, 2015

I want to delete the shape i have drawn on the panel. Here is my code

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.geom.Rectangle2D;

[Code] ....

Why it is not deleting my rectangle.

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved