homework

Stacks in Java with exceptions

Question : b) A Stack is a last-in first-out (LIFO) data structure. Write a Java class Stacklnt that stores a stack of integers using an alray as its private data structure. A Stacklnt has: A maximum size, which is set when a Stacklnt object is created. An exception should be thrown if the size is outside the range 10 to . 1000 A met...

Compile error when adding ActionListener to Array created GUI

I had a huge file for creating this GUI and I have shortened by using arrays. I am trying to add an ActionListener when the arrays are being added and I am getting this error /tmp/jc_3531/GUI.java:60: addActionListener(java.awt.event.ActionListener) in javax.swing.AbstractButton cannot be applied to (GUI) nButtons[c].addActionList...

Object Oriented Approach for C#

Hi there I am exploring this and see if this one make sense. For instance I have 2 abstract objects called: Customer and Tender. The relationship is that Customer can have many Tenders. My question is how to achieve like this on the TestClient app: 1) customer.InTender[0].ID = ??? What method to handle to handle this? Do I need to p...

Not writing the int value.Pl correct the prg.

Hi All, pl correct the prg. Q. Write a java prg to accept RollNo, Name of a Student and store it in Student.txt.Accept n records and store it. Following are the drawbacks of o/p produced 1. When we write rno i.e. int {roll no of stud} to the file "Student.txt" it does not write the int value i/p C:\j2sdk1.4.1_01\bin>java StudentInfo...

How to randomly select a string using C#?

When I click a button a string should appear as output ex. good morning or good afternoon. How can I use C# to randomly select the string to display? ...

How to print multiple arrays of different types in Java?

How do i print out multiple arrays, with my code below i only get the double array printed out? import javax.swing.JOptionPane; public class Matriseoppgave { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Du skal nå skriv inn 3 navn"); String getnavn1 = JOptionPane.showInputDialog("Skriv inn...

Multiply Variable by Another Variable?

I have a program for a C class I need to write. The program asks for a quantity, and I need to multiply that quantity by another variable which the user inputs. Basic calculator script for a c class :) I have it set up like this, int qty; //basic quantity var float euro, euro_result; //assign values to my float vars euro = .6896; ...

Java errors and syntax. Any help appreciated

I am asking for help on self-help, which is kind of an oxymoron. How do I bug you nice folks less by solving more of my own problems? I am in my last week of Java programming and I am having a huge hurdle with learning Java. I have read all the books but I keep getting hung up on tiny little issues. It is like trying to build a house ...

Adding Multiple Lines to a Text File Output?

I am using a basic C code to print to a text file: FILE *file; file = fopen("zach.txt", "a+"); //add text to file if exists, create file if file does not exist fprintf(file, "%s", "This is just an example :)\n"); //writes to file fclose(file); //close file after writing printf("File has been written. Please review. \n"); My question...

C++ Stack Implementation HWQuestion

Hey all! Having a little trouble with my stack. Im trying to print each element that i've pushed onto the stack. Starting with the stack ctor we know that we have a fixed size for the array. So I allocate the items struct object to hold just that much space: stack::stack(int capacity) { items = new item[capacity]; if ( items ==...

how to handle NAT traversal in c++ peer to peer application ( please code examples not theory )

Hello all i need to develop simple game that will be using peer to peer connection using centralize index manger server i know there is problem when client trying to connect other client behind router . i was reading about NAT traversal that explain mainly theory , but what i really like to see is code examples c++/java can you help m...

Getting and printing chars in C?

How do I get and print a char from a user? This want do it... #include <stdio.h> int main() { float number1; char mychar = ' '; printf("Number?\n"); scanf("%f", &number1); printf("Character?\n"); scanf("%c", &mychar); printf("You typed number: %f\n", number1); printf("You typed the char: %c\n", mycha...

highlight word in div using javascript

hi i have to implement find and replace functionality in my project. in this functionality there is one find and replace button on the top of contenteditable div. when user click on this button, popup window will open and ask for the search word when specify word and press find it will find word in that div only. and if match found it wi...

use of goto versus runtime code evaluation

Recently for a programming class, we were given the assignment to write a program in any language that, given n, will produce all the possible derangements for an array p of size n such that p[i] != i for all i: 0 <= i < n. We had to use iterators, e.g. yield. Example: n=3, [0, 1, 2] is not a derangement, but [2, 0, 1] is as well as [...

Does someone know how to solve this C# Math Algorithm?

Does someone know how to solve this C# Math Algorithm? The control number calculates by multiplying each number in a "social security number" with changing 2 and 1 (starting with 2). Then it calculates and adds together. The control number should be equal divided with 10 to be correct and pass. Ex, 720310-1212 "Social security number...

C Programming. How to make method to print a string

I am trying to make a function in C that will print a string taken as a parameter. Is this even possible in C? I have something like this in my header file, but string is not a valid identifier. I understand there are no strings in C, but what's the string.h class for? #include <string.h> #ifndef _NEWMAIN_H #define _NEWMAIN_H #i...

How do I use linkedlists for java?

I need to use a LinkedList to add cells of a prison with the cell numbers 1.1, 1.2, 1.3, 1.4 etc. There are two levels and odd numbered cells have 1 bunk whereas even numbered cells have 2 bunks. How can I do this? I did this to create a linkedlist. That is in my Cells class and I have 2 child classes which inherit from the Cells class ...

storing names and other information

I am creating a prison system where I need to store the names and because I need to print out all the prisoner information in one of the methods. I want to make it remember and store information such as name, id and crimes etc. How can I go about doing this? About the posted answers, I don't think it needs to be something that complica...

Unit test proper data structure creation

How would one test whether data structure built properly? I'm implementing kind of modified radix tree, and been wondering how do you check if your data structure builds up correctly. Consider a tree of TreeNode {String, Int} nodes. You always want to append new child to deepest node of value equal to 0, as in following example: Root,...

GregorianCalendar

I am doing an assignment and it involves using the GregorianCalendar. The specs say I need to use setLenient(false); how do I do this? I also need to set a constant date (1/1/2009) so that the first day of my program is always that. It also says to access the day, month and year through this: get(1) //returns the year get(2) // returns...