Jose Carrillo

Greenhorn
+ Follow
since Nov 13, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jose Carrillo

Hi well I creating a program with two classes and one of those classes is a test class which test the other class that basically is an ADT of giant number of 100 digits. but I'm having a problem and I do not know what is it here is my code:
public class GiantNumber
{
private short[] digitsArray;
public GiantNumber(int value)
{
this();
int x = 99;
while (value !=0);
{
digitsArray[x] = (short) (value % 10);
value = value /10;
x--;
}
}
public GiantNumber ()
{
for (int j = 0; j < 100; j++)
{
digitsArray [j] = 0;
}
}
public void add(GiantNumber otherNumber)
{
int a = 0;
int b = 0;
for(int y = 99; y >= 0; y--)
{
this.digitsArray[y] += otherNumber.digitsArray[y] + a;
this.digitsArray[y] = (short) b;
b = this.digitsArray[y] % 10;
a = this.digitsArray[y] / 10;
}
}
public void substract(GiantNumber otherNumber1)
{
GiantNumber a = new GiantNumber(20);
GiantNumber b = new GiantNumber(15);
a.substract(b);
}
public void greater()
{
}
public boolean equals()
{
return true;
}
public String toString();
{
}
}
public class TestGiantNumber
{
public static void main(String[] args)
{
TestGiantNumber GiantNumber = new TestGiantNumber();
GiantNumber a = new GiantNumber(2);
GiantNumber b = new GiantNumber(2);
a.add(b);
}
public TestGiantNumber()
{
}
}
and when I run the program the error is:
java.lang.ClassFormatError: GiantNumber (Code attribute is absent in method that is not abstract or native)
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:502)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:250)
at java.net.URLClassLoader.access$100(URLClassLoader.java:54)
at java.net.URLClassLoader$1.run(URLClassLoader.java:193)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at TestGiantNumber.main(TestGiantNumber.java:20)
Exception in thread "main"
14 years ago
No what I mean is let's say that the user input the number: 15, but since it is an array of 100 digits it would appear a bunh od zeros and then the 15 something like 0000000000000000000000000000000000015. I want to get rid of those zeros.BUT I DO NOT KNOW HOW. thanks.
14 years ago
hi it's me again well when I say inicialized to zero I meant that that for example if the user enter a number for example 15 It won't appear 0000000015. IT has to be 15. I really I have not Idea how to do that I was planning with aloop but I have not Idea how to do it. if any one could help me I would appreciated. here es my code:
public class GiantNumber
{
private short[] digitsArray;
public GiantNumber()
{
digitsArray = new short [100];
}
public void add()
{
GiantNumber a = new GiantNumber(3);
GiantNumber b = new GiantNumber(5);
a.add(b);
}
public void add(GiantNumber b)
{
}
public GiantNumber(int i)
{
}
}
thanks!
14 years ago
Hello well I have to make a BigNumner class that store 100 digits using and array where each element of the array will represent a digit. my question is I have declare the array to 100 elements and then I have to incialized to zero and I do not have any idea how to do that this my code so far:
Public class GiantNumber
{
private short [] digitsArray;

public GiantNumber()
{
digitsArray = new short[100];
}
public GiantNumber1()
{
//here I have to include a default constructor that initializes our number to 0
}
}
I really apreciated
14 years ago
Hello hey nick thanks for this code is really similar to one that I'm working it helps me alot.
thanks.
14 years ago
this program suppose to have three buttons draw line, oval, and rect. when someone click on them they will turn red and the user will be able to draw a oval or a line depends of what button he or she clicked. it works just as the paint program in windows and it has to save the shapes of the lines, ovals, and rect.
14 years ago
Hi I'm having problems with a program that save the shapes of a paint program this program has three buttons draw line, oval, rect here is my code:
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
public class shapes extends JApplet implements MouseListener, MouseMotionListener, ActionListener
{
public shapes()
{
buttons = new JButton[3];
shapes = new Vector();
}
public void init()
{
buttons[0] = new JButton("Line");
buttons[1] = new JButton("Rectangle");
buttons[2] = new JButton("Oval");
buttons[0].setBackground(Color.red);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.orange);
for(int i = 0; i < 3; i++)
controlPanel.add(buttons[i]);
drawPanel = new JPanel();
drawPanel.setBackground(new Color(0xffffcc));
Container container = getContentPane();
container.setLayout(new BorderLayout());
container.add(controlPanel, "North");
container.add(drawPanel, "Center");
for(int j = 0; j < 3; j++)
buttons[j].addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent mouseevent)
{
mouseX = mouseevent.getX();
mouseY = mouseevent.getY();
showStatus("Mouse is moved to (" + mouseX + "," + mouseY + ")");
}
public void mouseDragged(MouseEvent mouseevent)
{
mouseX = mouseevent.getX();
mouseY = mouseevent.getY();
showStatus("Mouse is dragged to (" + mouseX + "," + mouseY + ")");
s.setSize(mouseX, mouseY);
shapes.addElement(s);
repaint();
}
public void mouseEntered(MouseEvent mouseevent)
{
}
public void mouseExited(MouseEvent mouseevent)
{
}
public void mousePressed(MouseEvent mouseevent)
{
s = new Shape(shape, mouseX, mouseY);
}
public void mouseReleased(MouseEvent mouseevent)
{
}
public void mouseClicked(MouseEvent mouseevent)
{
}
public void actionPerformed(ActionEvent actionevent)
{
for(int i = 0; i < 3; i++)
{
buttons[i].setBackground(Color.lightGray);
if(actionevent.getSource() == buttons[i])
{
shape = i;
buttons[i].setBackground(Color.red);
}
}
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.blue);
for(int i = 0; i < shapes.size(); i++)
((Shape)shapes.elementAt(i)).draw(g);
}
private int mouseX;
private int mouseY;
private int mouseXold;
private int mouseYold;
private JButton buttons[];
private JPanel controlPanel;
private JPanel drawPanel;
private int shape;
private Shape s;
private Vector shapes;

and having these problems when I compile it:
jcarrill@linux:~/cs201> javac shapes.java
shapes.java:51: cannot resolve symbol
symbol : method setSize (int,int)
location: interface java.awt.Shape
s.setSize(mouseX, mouseY);
^
shapes.java:66: java.awt.Shape is abstract; cannot be instantiated
s = new Shape(shape, mouseX, mouseY);
^
shapes.java:96: cannot resolve symbol
symbol : method draw (java.awt.Graphics)
location: interface java.awt.Shape
((Shape)shapes.elementAt(i)).draw(g);
^
please help I'm fustrated.
14 years ago
hi I'm having a problem and I do not find what is problem well. I creating an applet with 4 buttons draw lines, rect, ovals, and fill. when fill button is click it will draw the rect and ovals fill. well my program compile and everything but I does not load the applet in the web can somebody help please. here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.EventObject;
public class mouseDraw extends JApplet implements MouseListener, MouseMotionListener, ActionListener
{
private int mouseX, mouseY, mouseY1, mouseX1;
private JButton[] buttons = new JButton[4];
private JPanel controlPanel, drawPanel;
private int shape;
private Button fillButton;
private Panel currentcolorPanel;
public static boolean FillShape;
public void init()
{
buttons[0] = new JButton("Line");
buttons[1] = new JButton("Rectangle");
buttons[2] = new JButton("Oval");
buttons[3] = new JButton("Fill");
buttons[0].setBackground(Color.red);
currentcolorPanel.add(fillButton);
fillButton.addActionListener(this);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.orange);
drawPanel = new JPanel();
drawPanel.setBackground(new Color(0xffffcc));
for (int i=0; i<4; i++)
controlPanel.add(buttons[i]);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(controlPanel, BorderLayout.NORTH);
pane.add(drawPanel, BorderLayout.CENTER);
for (int i=0; i<4; i++)
buttons[i].addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
super.paint(g);
int x = Math.min(mouseX1, mouseX);
int y = Math.min(mouseY1, mouseY);
g.setColor(Color.blue);
int w = (int)Math.abs(mouseX1 - mouseX);
int h = (int)Math.abs(mouseY1 - mouseY);
switch (shape)
{
case 0: g.drawLine(mouseX1, mouseY1, mouseX, mouseY);
int [] a = new int [x];
int [] z = new int [y];
break;
case 1: g.drawRect(x, y, w, h);
int [] b = new int [x];
break;
case 2: g.drawOval(x, y, w, h);
int [] c = new int [x];
break;
case 3: g.fillRect(x, y, w, h);
break;
}
}
public void mouseMoved(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
}
public void mouseDragged(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
repaint();
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
mouseX1 = mouseX;
mouseY1 = mouseY;
}
public void mouseClicked(MouseEvent e)
{
}
public void actionPerformed(ActionEvent actionevent)
{
if(actionevent.getSource() == fillButton)
{
if(FillShape)
{
FillShape = false;
fillButton.setLabel("Unfilled");
return;
}
FillShape = true;
fillButton.setLabel("Filled");
}
for (int i=0; i<4; i++)
{
buttons[i].setBackground(Color.lightGray);
if (actionevent.getSource() == buttons[i])
{
shape = i;
buttons[i].setBackground(Color.red);
}
}
}
}
thanks
14 years ago
hi well my question is I have to create an applet with 3 button, one to draw a line, other to draw a rect, and other to draw an oval. Also an additional button that fill the rect and ovals how can I do that because I have not idea I have try everything and nothing works. please help me here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mouseDraw extends JApplet implements MouseListener, MouseMotionListener, ActionListener
{
private int mouseX, mouseY, mouseY1, mouseX1;
private JButton[] buttons = new JButton[4];
private JPanel controlPanel, drawPanel;
private int shape;
public void init()
{
buttons[0] = new JButton("Line");
buttons[1] = new JButton("Rectangle");
buttons[2] = new JButton("Oval");
buttons[3] = new JButton("Fill");
buttons[0].setBackground(Color.red);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.orange);
drawPanel = new JPanel();
drawPanel.setBackground(new Color(0xffffcc));
for (int i=0; i<4; i++)
controlPanel.add(buttons[i]);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(controlPanel, BorderLayout.NORTH);
pane.add(drawPanel, BorderLayout.CENTER);
for (int i=0; i<4; i++)
buttons[i].addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
super.paint(g);
int x = Math.min(mouseX1, mouseX);
int y = Math.min(mouseY1, mouseY);
g.setColor(Color.blue);
int w = (int)Math.abs(mouseX1 - mouseX);
int h = (int)Math.abs(mouseY1 - mouseY);
switch (shape)
{
case 0: g.drawLine(mouseX1, mouseY1, mouseX, mouseY);
break;
case 1: g.drawRect(x, y, w, h);
break;
case 2: g.drawOval(x, y, w, h);
break;
case 3: g.fillRect(x, y, w, h);
break;
}
}
public void mouseMoved(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
}
public void mouseDragged(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
repaint();
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
mouseX1 = mouseX;
mouseY1 = mouseY;
}
public void mouseClicked(MouseEvent e)
{
}
public void actionPerformed(ActionEvent e)
{
for (int i=0; i<4; i++)
{
buttons[i].setBackground(Color.lightGray);
if (e.getSource() == buttons[i])
{
shape = i;
buttons[i].setBackground(Color.red);
}
}
}
}
thanks
14 years ago
Hello I'm creating an applet that draw a line, rect, and oval. and I have create a another button that fill the rect and ovals. also I have to create 3 array that storage 10 shapes in that way the shapes will not be erase if I go to other page or something. here is my code so far:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mouseDraw extends JApplet implements MouseListener, MouseMotionListener, ActionListener
{
private int mouseX, mouseY, mouseY1, mouseX1;
private JButton[] buttons = new JButton[3];
private JPanel controlPanel, drawPanel;
private int shape;
public void init()
{
buttons[0] = new JButton("Line");
buttons[1] = new JButton("Rectangle");
buttons[2] = new JButton("Oval");
buttons[0].setBackground(Color.red);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.orange);
drawPanel = new JPanel();
drawPanel.setBackground(new Color(0xffffcc));
for (int i=0; i<3; i++)
controlPanel.add(buttons[i]);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(controlPanel, BorderLayout.NORTH);
pane.add(drawPanel, BorderLayout.CENTER);
for (int i=0; i<3; i++)
buttons[i].addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
super.paint(g);
int x = Math.min(mouseX1, mouseX);
int y = Math.min(mouseY1, mouseY);
g.setColor(Color.blue);
int w = (int)Math.abs(mouseX1 - mouseX);
int h = (int)Math.abs(mouseY1 - mouseY);
switch (shape)
{
case 0: g.drawLine(mouseX1, mouseY1, mouseX, mouseY);
break;
case 1: g.drawRect(x, y, w, h);
break;
case 2: g.drawOval(x, y, w, h);
break;
}
}
public void mouseMoved(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
}
public void mouseDragged(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
repaint();
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}

public void mouseExited(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
mouseX1 = mouseX;
mouseY1 = mouseY;
}
public void mouseClicked(MouseEvent e)
{
}
public void actionPerformed(ActionEvent e)
{
for (int i=0; i<3; i++)
{
buttons[i].setBackground(Color.lightGray);
if (e.getSource() == buttons[i])
{
shape = i;
buttons[i].setBackground(Color.red);
}
}
}
}
please Help me thanks
14 years ago
well but how can I make this changes in my code.
14 years ago
and how I do those changes??
14 years ago
hello well I'm creating an applet that has 5 buttons drawline, drawrect, drawoval, filloval, and fillrect. and it compiles and everything but the applet does not appear. here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mouseDraw extends JApplet implements MouseListener, MouseMotionListener, ActionListener
{
private int mouseX, mouseY, mouseY1, mouseX1;
private JButton[] buttons = new JButton[3];
private JPanel controlPanel, drawPanel;
private int shape;
public void init()
{
buttons[0] = new JButton("Line");
buttons[1] = new JButton("Rectangle");
buttons[2] = new JButton("Oval");
buttons[3] = new JButton("Fill");
buttons[0].setBackground(Color.red);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.orange);
drawPanel = new JPanel();
drawPanel.setBackground(new Color(0xffffcc));
for (int i=0; i<3; i++)
controlPanel.add(buttons[i]);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(controlPanel, BorderLayout.NORTH);
pane.add(drawPanel, BorderLayout.CENTER);
for (int i=0; i<3; i++)
buttons[i].addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
super.paint(g);
int x = Math.min(mouseX1, mouseX);
int y = Math.min(mouseY1, mouseY);
g.setColor(Color.blue);
int w = (int)Math.abs(mouseX1 - mouseX);
int h = (int)Math.abs(mouseY1 - mouseY);
switch (shape)
{
case 0: g.drawLine(mouseX1, mouseY1, mouseX, mouseY);
break;
case 1: g.drawRect(x, y, w, h);
break;
case 2: g.drawOval(x, y, w, h);
break;
case 3: g.fillOval(x, y, w, h);
break;
case 4: g.fillRect(x, y, w, h);
break;
}
}
public void mouseMoved(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
}
public void mouseDragged(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
repaint();
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e)
{
}
public void mousePressed(MouseEvent e)
{
mouseX1 = mouseX;
mouseY1 = mouseY;
}
public void mouseClicked(MouseEvent e)
{
}
public void actionPerformed(ActionEvent e)
{
for (int i=0; i<3; i++)
{
buttons[i].setBackground(Color.lightGray);
if (e.getSource() == buttons[i])
{
shape = i;
buttons[i].setBackground(Color.red);
}
}
}
}
please somebody help me
14 years ago
hi I'm creating a program that draw a oval,line,and a rect. but I'm having this problem please can somebody help me
mouseDraw is not abstract and does not override abstract method mouseClicked(java.awt.event.MouseEvent) in java.awt.event.MouseListener
public class mouseDraw extends JApplet implements MouseListener, MouseMotionListener, ActionListener
^
mouseDraw.java:85: missing method body, or declare abstract
public void mouseReleased(MouseEvent e);
^
mouseDraw.java:89: missing method body, or declare abstract
public void mousePressed(MouseEvent e);

please here is my code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class mouseDraw extends JApplet implements MouseListener, MouseMotionListener, ActionListener
{
private int mouseX, mouseY, mouseY1, mouseX1;
private JButton[] buttons = new JButton[3];
private JPanel controlPanel, drawPanel;
private int shape;
public void init()
{
buttons[0] = new JButton("Line");
buttons[1] = new JButton("Rectangle");
buttons[2] = new JButton("Oval");
buttons[0].setBackground(Color.red);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.orange);
drawPanel = new JPanel();
drawPanel.setBackground(new Color(0xffffcc));
for (int i=0; i<3; i++)
controlPanel.add(buttons[i]);
Container pane = getContentPane();
pane.setLayout(new BorderLayout());
pane.add(controlPanel, BorderLayout.NORTH);
pane.add(drawPanel, BorderLayout.CENTER);
for (int i=0; i<3; i++)
buttons[i].addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
super.paint(g);
int x = Math.min(mouseX1, mouseX);
int y = Math.min(mouseY1, mouseY);
g.setColor(Color.blue);
int w = (int)Math.abs(mouseX1 - mouseX);
int h = (int)Math.abs(mouseY1 - mouseY);
switch (shape)
{
case 0: g.drawLine(mouseX1, mouseY1, mouseX, mouseY);
break;
case 1: g.drawRect(x, y, w, h);
break;
case 2: g.drawOval(x, y, w, h);
break;
}
}
public void mouseMoved(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
}
public void mouseDragged(MouseEvent e)
{
mouseX = e.getX();
mouseY = e.getY();
showStatus("Mouse is moved to (" + mouseX + mouseY + ")");
repaint();
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseReleased(MouseEvent e);
{
}
public void mousePressed(MouseEvent e);
{
mouseX1 = mouseX;
mouseY1 = mouseY;
}
public void actionPerformed(ActionEvent e)
{
for (int i=0; i<3; i++)
{
buttons[i].setBackground(Color.lightGray);
if (e.getSource() == buttons[i])
{
shape = i;
buttons[i].setBackground(Color.red);
}
}
}
}
please help me
14 years ago
Hi well I writing a program that use binarysearh and it looks an array and search for query and then say query found or not found; the program compile. however when I try to run it It shows and error saying:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 49
at InsertionSort.BinSearch(InsertionSort.java:35)
at InsertionSort.main(InsertionSort.java:21)
please help me this my code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class InsertionSort
{
public static void main(String[] args) throws IOException
{
InputStreamReader reader = new InputStreamReader(System.in);
BufferedReader console = new BufferedReader(reader);
int n = 100;
int[] array = new int[args.length];
System.out.print("Enter query: ");
String s = console.readLine();
int q = Integer.parseInt(s);
// StopWatch sWatch = new StopWatch();
// sWatch.start();
int index = BinSearch(array, q, 0, n-1);
// sWatch.stop();
if (index < 0)
System.out.println("Query is not found");
else
System.out.println("Query is found at position ");

}
public static int BinSearch(int[] a, int q, int start, int finish)
{
if (start > finish) return (-1);
int mid = (start + finish) /2;
int diff = q - a[mid];
if (diff == 0)
return (mid);
else if (diff < 0)
return BinSearch(a, q, start, mid-1);
else
return BinSearch(a, q, mid+1, finish);
}
}
14 years ago