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
ADVERTISEMENT
Oct 13, 2014
I have been tasked with creating a coin Star simulator. This accomplishes which accomplishes the following tasks:
Prompts the user to enter coins:
(example inputs): (Note, these can't be like a numerical input followed by a word input, it needs to be one line)
4 quarters
3 dimes
0 pennies
All of which would be allowed inputs.
If an incorrect format is used it should tell the user to use the correct format of number space cointype
After every new input it should give a running total of the current money the system has stored.
this loop should continue until the user enters the phrase "finish"
Then, this system should output the money (minus 9.1% fee) in the largest denominations possible (up to $20)
So if the total came to $ 131.33 (after fee)
It should output:
6 twenties 1 tens 0 fives 1 singles 1 quarter 0 dimes 1 nickle 3 pennies.
and then maybe some cheeky text about how the machine stole your money.
The actual coding for me however is very difficult as I really don't know how to convert the string input from the user into usable numerical and substrings for the calculations.
I have some basic skeleton code worked out, but its only designed to run once.
import java.util.Scanner;
public class CoinStar {
Scanner input = new Scanner(System.in);
public static void main(String[] args) {
/** this first section is supposed to take the string from the user and separate it into two substrings,
* one integer, one word string
*
[Code] ....
View Replies
View Related
Sep 17, 2014
I am doing an assignment in my Java class and I need to connect the nodes to make a 12 pointed star. I have already drawn out the star and figured out which nodes to connect together. The only thing I cannot get is to show all of the nodes in the order they connect. I can only get the first 3 nodes to show up. I need it to wrap around and basically keep adding 5 to the last node until all numbers 0-11 are used.
public class StarWinding {
public static void main(String[] args) {
for (int i = 0 ; i < 12; i+=5) {
System.out.print(i + " ");
}
}
}
And the out put so far is: 0 5 10
I need it to be: 0 5 10 3 8 1 6 11 4 9 2 7
View Replies
View Related
May 30, 2014
I am trying to program the A star algorithm using JButtons. Now I have some tweaking to do but I have to get past the errors first.
I am getting the following errors:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at AStar.findEndButton(AStar.java:40)
at Screen$1.actionPerformed(Screen.java:59)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
[Code] ....
In my AStar class you will see these buttons which is an instance of matrixButtons
MatrixButtons[][] current;
MatrixButtons[][] endButton;
MatrixButtons[][] startButton;
MatrixButtons[][] nextCurrent;
MatrixButtons[][] temp;
MatrixButtons bestNextMove;
I really need them to handle several different methods. A full example of the full program is below.
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Screen
[Code] ....
View Replies
View Related
May 16, 2014
I try to use below codes to convert Hex String "1111737999630745" to ASCII.
When I read the result in Notepad++ with HEX-Editor plugin, I find attached image which is different from above String, there is one additional c2 and I am quite confused.
Java Code:
public static void main(String[] args) throws IOException {
Test strToHex = new Test();
File file = new File("D:/filename");
// if file doesnt exists, then create it
if (!file.exists()) {
file.createNewFile();
[Code] .....
View Replies
View Related
Apr 19, 2015
I need to write a program that combines everything I learned in my Java course from chapter 1-6 and 8 by Tony Gaddis at least with all the other chapters being bonus points, so I decided to write a program that tells you the binary to hex conversion or hex to ascii conversion. However I keep getting the following errors in my class, enums, and main program that I'm not sure about why. Please do not point out that the numbers in the case select are not what the hex values translate to because I know that, but I was trying to use more meaningful place holders temporarily:
These are the errors for main:
----jGRASP exec: javac BinToHex.java
BinToHex.java:9: error: cannot find symbol
Scanner keyboard = new Scanner(System.in);
^
symbol: class Scanner
location: class BinToHex
[Code] .....
3 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Because of the error in the picture attached I am unable to show the remaining errors for the class and enumsjGrasp Save error for Ascii character import enum datatype.jpg
Here is the code for main:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.*;
/**
This program shows that you can binary to hex and hex to ascii.
*/
public class BinToHexToAscii
[Code] .....
/**
Hex value output enumerated data type
*/
enum BintoHexfinalDatatype { "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F",
"10","11","12","13","14","15","16","17","18","19","1A","1B","1C","1D","1E","1F",
"20","21","22","23","24","25","26","27","28","29","2A","2B","2C","2D","2E","2F",
"30","31","32","33","34","35","36","37","38","39","3A","3B","3C","3D","3E","3F",
"40","41","42","43","44","45","46","47","48","49","4A","4B","4C","4D","4E","4F",
"50","51","52","53","54","55","56","57","58","59",&quo
View Replies
View Related
Jan 21, 2015
I have two programs that talk to each other over a TCP connection. When I write the data "STX+1234" where STX is the Ascii character STX or Ctrl B and I expect the written String length to be 6 which it is. On the other side of the socket I create the ServerSocket and use the client socket's InputStream to create a BufferedReader. When I receive the string it now has 12 characters where each original character has been replaced by NUL and the character. How do I read the string as it is originally specified without the conversion? And is the problem on the reader side or the writer side?
View Replies
View Related
Feb 12, 2014
I've written some code to do this, but it's not working as I expect. This is what the ASCII map looks like:
###################
#.................#
#......G........E.#
#.................#
#..E..............#
#..........G......#
#.................#
#.................#
###################
Here's how I've tried to store the information in a 2D array:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
public class Map {
public void importMap() throws IOException{
BufferedReader br = new BufferedReader(new FileReader("map.txt"));
String line;
[Code] ....
But it's not printing out what I'm expecting. It's printing out:
[[#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [#, #, #, #, #, #, #, #, #], [
What is printed is much larger than what I've copy and pasted but I can't post it all here.
The error I get is:
Exception in thread "main" java.io.IOException: Stream closed
at java.io.BufferedReader.ensureOpen(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at Map.importMap(Map.java:26)
at Map.main(Map.java:44)
View Replies
View Related
Dec 14, 2014
For part of my program, I am trying to ask the user for input on generating a number of random characters. I have already done this with integers and doubles, how would I do this for characters using ASCII values? Would I use the same format as I did for generating integers (Shown in code)?
import java.util.Random;
import java.util.Scanner;
public class NewNumberCharacter {
public static void main(String[] args) {
// Create a Scanner
Scanner input = new Scanner(System.in);
[code]....
View Replies
View Related
Aug 25, 2014
I am trying to figure out how to convert a string of ASCII code into char.I know that you can use (char) to convert it, but the issue is you cannot really just it for Strings.
View Replies
View Related
Feb 23, 2014
I am trying to make a class definition file for an ASCII File.
Ultimately, I want to be able to add methods to allow the image produced by the file to be printed normally, then printed with various manipulations.
However, for some reason, whenever I try to run the program to test my normalPrint method, it terminates without printing anything.
I think this is because the array's values width and height are not within the scope of the method. I tried passing the array as a parameter for the method like so:
Java Code:
public void normalPrint(char [][] poop){
//method here
} mh_sh_highlight_all('java');
But it gave me an error that stated
"The method normalPrint(char[][]) in the type asciiFile is not applicable for the arguments ()"
Class Definition:
Java Code:
import java.io.*;
import java.util.Scanner;
public class asciiFile {
int height;
int width;
[Code] .....
View Replies
View Related
May 23, 2014
I want to make a parser from binary to ASCII with JavaCC or another Compiler Construction with Java. I don't know how to start.
View Replies
View Related
Mar 22, 2014
This is my program.
public class C4
{
// instance variables - replace the example below with your own
public static void main(String[] args)
{
System.out.println((char)41);
}
}
I wanted to check that the integer 41 is 'A' in UTF-8, although it's ')' in UTF-16 , so I ran the program with javac -encoding UTF-8 C4.java but the result was still ')'.
How do i fix this? Also, do constants for the max values of ASCII and UTF-8 exist in Java? I need to show how many number of bits are used to represent characters in both encodings.
View Replies
View Related
Sep 12, 2014
I am having a problem with SD array .i have to find the ASCII no. of names entered.
import java .io.*;
class ASCII
{
public static void main()throws IOException
{
InputStreamReader read = new InputStreamReader(System.in);
[Code] .....
View Replies
View Related
Oct 6, 2014
I'm writing a program to print an ASCII image using nested for loops. The output is a rocket ship that looks like this.
/**
//**
///**
////**\
/////**\
+=*=*=*=*=*=*+
|../..../..|
|.//..//.|
|//////|
|//////|
|.//..//.|
|../..../..|
+=*=*=*=*=*=*+
|//////|
|.//..//.|
|../..../..|
|../..../..|
|.//..//.|
|//////|
+=*=*=*=*=*=*+
/**
//**
///**
////**\
/////**\
I'm having problems with the mid section of the rocket, specifically the bottom part of the mid section:
|../..../..|
|.//..//.|
|//////|
I'm having difficulty writing the for loop to correctly print the dots. You're supposed to incorporate a constant which allows you to adjust the size of the overall figure. The loop doesn't work when I adjust the size, only when the value of HEIGHT is 3. The loop, however, for some reason works with the top part of the mid section.
This is the for loop for the top section.
for (int dots = 1; dots <= -1 * line + 1 * HEIGHT; dots++) {
System.out.print(".");
}
This is the for loop for the bottom section.
for (int dots = -1 * line + 1 * HEIGHT; dots <= 1; dots++) {
System.out.print(".");
}
Usually reversing the iteration of the loop just requires flipping the conditions, right? But it didn't work this time for some reason. Why this doesn't work? I can post the code to my entire program for compiling.
View Replies
View Related
Mar 4, 2014
I am busy programming a clone of the popular phone game they had on Nokia cellphones a long time ago called Snake II but since I know very little about programming I will be using ASCII graphics instead of a 2D graphics engine.
My idea for implementation is having a main class called game which should refresh a grid of ascii characters every, say 0.2 seconds. Then I have another class called Dot. Each Dot object has x and y coordinates, and a direction in the x and y planes (dirx = -1 means left, dirx = 1 means right, diry = 1 means up, diry = -1 means down, and obviously the snake cant move the diagonals)
The Game class prints a "*" symbol where the Dot is, and what I'm trying to do is get the screen to refresh (I think I need to use the sleep() function for this to slow the game down to a reasonable pace), and go in the direction it is supposed to go.
(I haven't programmed this in yet but the snake will be an array of Dot, and at each refresh Dot at position 0 will pass it's coordinates and direction to Dot at position 1, Dot1 to Dot2, Dot2 to Dot3, etc.
Here's my code so far:
A first class called Game.
Java Code: //Not done yet but this is the start to my game of Snake. Basically the class Game generates a Grid of ASCII characters
import java.util.Scanner;
public class Game {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
final int WIDTH = 79;
[Code] .....
My problem now is that I am taking input from the Scanner class. What it does is wait for my input, then it goes on to executing the rest of the code in other words refresh the ASCII grid. This is a problem because I need the snake to keep moving at constant pace while listening to the keyboard.
How can I get my while loop to keep going (i will add a sleep() function later) while listening to the keyboard without stopping?
View Replies
View Related
Nov 12, 2014
I have a problem with this ascii animation program I am working on. I declared a method inside of my class AsciiAnimation extends JFrame implements ActionListener, called
package AsciiAnimation;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
public class AsciiAnimation extends JFrame implements ActionListener{
int currentFrame = 0;
ArrayList<String> frameList = new ArrayList<String>();
[Code] ....
Basically I just am trying to figure out how java works with me accessing those 2 data members, currentFrame and frameList inside of my first class ALL in the same package.
View Replies
View Related
Mar 2, 2014
I need to insert a break line to a text message on hitting enter by taking its ascii value i.e 10.I have used node.insert commands.I have tried using node.insertAttribute and node.insertChars but is not working ....
View Replies
View Related
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
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
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
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
View Related
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
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
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
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