Stripes / Checkerboard And Double Diagonal (Asterisk Patterns)

Oct 2, 2014

I need to make a program that does stripes, checkerboard, and double diagonal. I can not get the stripes to work?

import java.util.Scanner;
public class AsciiArt {
public static void main(String[] args){
int pattern;
Scanner input=new Scanner(System.in);
System.out.println("Choose one of the following patterns by pressing the corresponding number");
System.out.println("1) Stripes");

[Code] ....

View Replies


ADVERTISEMENT

Creating A Diagonal Cross?

Oct 3, 2014

I need to create a diagonal cross however I can not figure out how to do the upper left side of it.

Currently I am getting

0*
1--*
2---*
3 *--*
4*-----*

I want to get it to look like

0*------*
1 *--*
2----*
3 *---*
4*------ *

( I replaced spaces with -) So far I have

System.out.println("Input a size(must be larger than 1: )");
size=input.nextInt();
if (size>1) {
for (x=0;x<size;x++){
System.out.println("");

[Code] ....

View Replies View Related

Moving Rectangle In Diagonal Line

Jul 24, 2009

I am just trying to move a rectangle in a diagonal line. When the applet pops up, the rectangle is there but doesn't move. If I drag the sides of the applet to make it bigger or smaller the rectangle will redraw itself and move, but I want it to move without touching the window.

Java Code:

package javaapplication3;
import java.applet.Applet;
import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Random;

[Code] .....

Why does it only repaint when I resize the window?

View Replies View Related

How To Use Asterisk Symbol For Answer

Oct 13, 2014

I am new to programing and I am making a dice game where I have to roll two dice and add the total together for each dice (2, 3, 4 ect.) I have all the program finished except one thing.

How would I use the * character that shows the total percentage each number was rolled. Each * will represent 1% of the total rolls. Instead of saying there were ( 4 ) 2's rolled i have to put ( **** ) 2's rolled.

2: ***
3: ******
4: *********

View Replies View Related

Print Array Asterisk Bar Chart

Jul 6, 2014

I am trying to get this program to take 5 integers from a user and print a bar chart made of asterisks. The only way I've been able to access the values stored in the array is when my loops are nested, but this keeps my output from printing the way I would like it to.

It prints:
Enter a number:
2
**
Enter a number...and so on

I want it to take the values say(2,3,5,8,4) and do this:
**
***
*****
********
****

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int[] barArray = new int[5];
for(int i =0; i < barArray.length; i++){
System.out.println("Enter a number: ");
barArray[i] = in.nextInt();
for(int j = 0; j < barArray[i]; j++){
System.out.print("* ");
}System.out.println("");
in.close();
}
}

View Replies View Related

How To Make Password Converted Into Asterisk

Oct 11, 2014

package exercises;
import java.util.*;
public class Log_in_form {
static Scanner scan=new Scanner(System.in);
public static void main(String[] args) {
String username="rosas";
String password="sandy";

[Code] .....

View Replies View Related

Java Math - Write Expression Whose Value Is Length Of Diagonal Of Square

Jul 24, 2014

The area of a square is stored in a double variable named area . Write an expression whose value is length of the diagonal of the square. Do I use math.sqrt?

View Replies View Related

Comparing Characters Of A Word To Puzzle Board - Diagonal Search Algorithm

Feb 7, 2015

Coding (must follow pseudocode algorithm provided) for comparing characters of a word to a puzzle board char[][].

I've gotten the horizontal and vertical searches to work, but I'm having a difficult time figuring out how to search diagonally.

Here's the search algorithm format I have to use:

for each guess word
for each letter of the puzzle
for each letter of the guess word
check for diagonal match
if found, add word to list, break to next guess

I'm assuming there should be a +1 horizontal offset after I find the first letter, but every index I've bumped has caused me to screw up my array bounds. I'm missing something.

Here's the algorithm I'm using for diagonal search. This same algorithm worked for vertical search (minus the offset of course)

//diagonal search
for(String word : guessWords) {//for each guess word
 int letterCount = 0;
int index = 0;
for(int j=0; j<grid[index].length; j++) {//for each puzzle letter
 
[Code] ....

View Replies View Related

Finishing / Creating Checkerboard Program

Sep 9, 2014

I have my CheckerboardViewer done, my component is what I need finishing. My final product needs to be a checkerboard with alternating red and grey squares but the background is already grey. My code for the Viewer is:

import javax.swing.JFrame;
public class CheckerBoardViewer
{
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.setSize(300, 400);
frame.setTitle("CheckerBoardViewer");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
CheckerBoardComponent component = new CheckerBoardComponent();
frame.add(component);
frame.setVisible(true);
}
}

And this is what I have of the Component:

import javax.swing.JComponent;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

[code]....

I've created one square so far, but I'm having trouble creating the code for at least the second square.

View Replies View Related

Display Checkerboard Pattern On Applet

Apr 27, 2014

Here is a program that is suppose to display a checkerboard on an applet as shown below but it is not.

/*
23.7 (Draw a Checkerboard Pattern) Write an applet that draws a checkerboard pattern as follows:

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

*/

import java.awt.Graphics;
import javax.swing.JApplet;
public class Exercise23_7 extends JApplet
{
// method paint to paint a checker board pattern
public void paint( Graphics g )

[Code] .....

View Replies View Related

CheckerBoard Won't Appear - Creating A Game In Java

Mar 8, 2015

Anyway I am creating a game for my A2 coursework, most commonly known as Checkers. I have completed my code and everything works as I had planned except that the CheckerBoard itself as well as the checkerpieces do not appear to be showing.

The section of were my board should be present is just a black space. Although my board does not appear to be displaying, all of the actions I perform on it such as clicking certain section produces the planned response, and although I've checked through my code I cannot work out what I've done wrong.

CheckerBoard content = new CheckerBoard(); // Sets the CheckerBoard values into the content to be used in the next line
application.setContentPane(content); // Container holds the values together, Content pane of the CheckerBoard
application.pack(); // Use preferred size of content to set size of application.
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
application.setLocation( (screensize.width - application.getWidth())/2,
(screensize.height - application.getHeight())/2 );

[Code] ....

I have noticed is that within the BoardComplete(), if you change the setBackground(Color.BLACK) to WHITE, it will change the colour of the section to white, but the checkboard is still unshown.

View Replies View Related

Create A Checkerboard Pattern With 2 Nested For Loops?

Feb 12, 2015

Im trying to create a checkerboard pattern with 2 nested for loops . I need to output asterisk characters. Im supposed o use an n int so I dont know if im limited to that 1 int. Im only getting 1 line of asterisk.

* * * * *
* * * * *
* * * * *
* * * * *
package checkerboard;
public class Checkerboard {
public static void main(String[] args) {
for (int row = 1; row < 6; row++){
System.out.print("* ");
for (int col = 6; col < col; col++) {

[code]...

View Replies View Related

Making Custom Checkerboard With Nested Loop

Feb 7, 2014

I'm trying to make a custom checkboard with given user input, in the form of (# of rows, # of columns, size of each square, filler character).

So the input 2 3 5 * would look like

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

I've made my loop, but I am unable to get more then a 1 1 1 checkerboard properly. I am stuck on how to divide the filler characters to make the proper square size. As of now they are all one lined.

import java.util.*;
 public class Checker{
 public static void main(String[] args) {
int col, row, size; char filler;
System.out.println("Please enter 3 numbers and a character."); //output

[Code] ..........

View Replies View Related

Checkerboard Using 2D Arrays And Object Oriented Programming In BlueJ

Apr 23, 2014

Driver:

*initiating theGrid[][]*
public Zhang()
{
con.setLayout(new FlowLayout());
for (int xDimension = 0; xDimension<theGrid.length; xDimension++)

[Code] ....

All I'm getting as a blank screen and I've searched for what to put into object oriented code to make the image show up how to program using 2d arrays. I don't get any error messages (which is good I suppose) but how to make the image show up because I have stuff under the graphics and draw methods, did I do something wrong where initializing the array?

View Replies View Related

Simple Code In Java That Replace All Tabs User Input With Asterisk

Feb 13, 2015

I am creating a simple code in Java that replaces all tabs the user inputs with '*'. However, I am doing something wrong and I am not sure what. Here is what I have so far in Eclipse..

import java.util.Scanner; 
public class ReplacingTabs {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = "";
String s2 = "";
 
[Code] .....

There is an error with the s2 in the line String s2 = s.replace(' ','*');

I think I need to add String s2 to the loop but I am not sure how..

View Replies View Related

Java Design Patterns

May 9, 2015

we have been given a scenario to design a system in which we have to make the class diasgrams. however we have to use appropriate patterns that match the scenario.

View Replies View Related

Nested Patterns Using For Loops

Feb 9, 2015

i want to use nested loops to print patterns but i cant seem to make a pattern that will look like V and K this should be the outcome.

* *
* *
* *
* *
*

@ @
@ @
@@
@ @
@ @

View Replies View Related

Compare Inheritance And Design Patterns?

Apr 30, 2014

Design Patterns are one form of reuse. so is inheritance. what are the similarities and difference between them?

View Replies View Related

Design Patterns And Java Algorithms

Nov 22, 2014

I've looked over the concepts of Java programming, tested them in code and i understand most of them. I have a problem when i need to make harder programs , this might be because i dont know design patterns and algorithms.I'm curious what a entry level programmer needs to know to get a job in the field. Right now i was thinking i need to know:

1. The way all big concepts work and most of the keywords.

2. Design patterns.

3. Algorithms.

what i actually need to know for an entry level job and can you tell me which design patterns and algorithms are a must know for that first job. Considering i might have financial problems in the near future this is not a theoretical question, i really need to know what i need to learn in the next 2-3 months to get an entry level job down.

View Replies View Related

EJB / EE :: Design Patterns - Usage Of Transactions And Exceptions

Feb 3, 2015

When it comes to Java EE I see many developers having trouble with the usage of transactions and exceptions and when to use what.

I see a full chapter of RESTful Web Services, but do you also relate these Web Services to their counterparts (SOAP Web Services)?

View Replies View Related

EJB / EE :: Difference Between Inversion Of Control And Dependency Injection Patterns

Feb 4, 2015

My question is regarding the the Inversion of Control (IoC) and Dependency Injection (DI) patterns, when learning about Spring i saw that people keep talking about Ioc and Dependecy Injection like if its the same thing!

View Replies View Related

Using Nested Loops In A Class Called Print Patterns

Mar 7, 2014

Write a method to print each of the following patterns using nested loops in a class called PrintPatterns. The signature of the methods are:

public static void printPatternX(int size) //'X' from 'A' to....., size is a positive integer.

#
##
###
####
#####
######
#######
########

View Replies View Related

Making Patterns (Diamond Shape) Using Nested Loops

Mar 23, 2015

I have to make a pattern that is of a diamond shape such as this:

Java Code:
1
1 2 3
1 2 3 4 5
1 2 3
1
mh_sh_highlight_all('java');

I wrote this (for the variable name, this is just a small part of my program and I'm trying to get the pattern right so I didn't mind my variables at the moment):

Java Code:

public class NewFile{
public static void main(String []args){
int k = 0;
for (int i=1 ; i<=5 ; i++) {
{ for (int h=2 ; h >= i ; h--)

[Code] ....

My output is the following:

Java Code:
1
123
12345
1234567
123456789
mh_sh_highlight_all('java');

I realize I should divide the code into a lower and upper triangle using two loops. However, I don't know how to break the first part. I did find the "trend" but I don't see how to implement it.

View Replies View Related

JSP / JSTL :: What Is The Difference Between Design Patterns And Frame Word

Feb 20, 2006

what are design patterns ? what is the difference between design patterns and frameword ?

View Replies View Related

Using Factory And Singleton Design Patterns To Create A Simple Form

Nov 16, 2014

My assignment was to create a simple form that demonstrates the use of the factory and singleton design patterns. "Use the Factory pattern to ensure that each form input consists of a text label and a textfield. Use the Singleton pattern for the submit button. When the submit button is clicked, a pop-up should show all the information that was typed into all of the form fields."

I used JFrame to create the form without the design patterns and I although I get the desired result, I'm not quite sure how I can integrate the design patterns into the code I wrote. The example I have to go off uses shapes, not text fields so I think that's why I'm not quite clear on how to approach this.

Here's my code so far:

import javax.swing.event.*;
import javax.swing.*;
import java.awt.*;

[Code]....

View Replies View Related

Factory And Singleton Design Patterns - Building A Simple Form

Nov 20, 2014

My assignment was to create a simple form that demonstrates the use of the factory and singleton design patterns. "Use the Factory pattern to ensure that each form input consists of a text label and a textfield. Use the Singleton pattern for the submit button."

Here's what I have:

Form.java file

interface Form {
public void getFormField ();
}
Name.java file (I have a similar files just like this for Address.java, City.java, State.java, Zip.java and Phone.java)
import java.util.Scanner;
class Name implements Form

[Code] ....

It compiles at the moment but I get a null pointer exception in the main method of the FormFactoryDemo file.

View Replies View Related







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