Error On Import Statement For Stacks

Apr 20, 2015

I'm getting errors on all the exceptions called EmptyCollectionException. I think this is because the import statement has a error on it but I'm not sure. I'm suppose to add methods for peek, isEmpty, size, and toString methods. I only started isEmpty also am wondering what I have to change from peek method if anything at all.

import jsjf.exceptions.*;//Error on jsjf
import java.util.Arrays;
public class ArrayStack<T> implements StackADT <T> { //Error on StackADT
private final static int DEFAULT_CAPACITY = 100;
private int top;
private T[] stack;
 
[Code] .....

View Replies


ADVERTISEMENT

Finding The Right Import Statement?

Feb 13, 2014

Often times i don't remember which package a specific class (like ArrayList) belongs to. Is there an easy way to find that java.util.* is what i need to import, if i wanted to use the class ArrayList ?

View Replies View Related

File Import Which Is Not Standard Import

Apr 5, 2014

Usually, most of the time, I import the standard java stuff.But what happens when I find a code with a list of those com. imports:

import java.io.File;
import java.io.IOException;
import com.itseasy.rtf.RTFDocument;
import com.itseasy.rtf.text.Border;
import com.itseasy.rtf.text.Field;

Where are these imports and how do I "get" them?

View Replies View Related

Logical Error With Else If Statement?

Aug 12, 2014

I was almost finished with my program when I noticed I had a big logical error. At the very beginning of my else if statements I would jump down to my else statement.

Java Code:

import java.util.Scanner;
public class InternetServiceProviderNew
{
public static void main(String[] args) {
double packageA, packageB, packageC, extraA, extraB, userHours, aHours, bHours, cHours, userCharges;
packageA = 9.95; packageB = 13.95; packageC = 19.95; aHours = 10; bHours = 20;
String userPackage, A, B, C ;

[code]....

View Replies View Related

If Statement Syntax Error

Dec 13, 2014

This is what i have so far, I use BlueJay to write this:

import javax.swing.JOptionPane;
public class payroll
{
String again = y;
//
private String name;
private double rate;
private double hours;
static double gross; //gross pay

[code]....

my first problem is that it expects a ")" on this line :"if ((hours <=40)rate *1);"For the assignment itself these are the requirements:

-Create a class called payroll with private variables for rate hours and name

-Create static variables for gross pay, union dues, health coverage (hp in my case), FICA taxes, State taxes, Federal taxes, net pay, all must be initialized to 0

-default constructor that assigns default values

a function called calcPay that will do the following tasks and print it to a pay stub :

- function that checks the hours ( if hours are 40 or less pay rate, if over 40 pay 150% of the rate)
- calculates gross pay before any deductions (using user inputted hours and rate)
- deduct medical coverage and union dues from gross pay and call this adjusted gross pay (also this should have its own line on the paystub)
- A function that deducts State, federal and fica taxes from adjusted gross
- FICA - 7% for any income
-Federal - 2% for $0-$150 / 6% for 150.01 - 300 / 14% for 300.01 - 600 / 18% for 600.01 - unlimited
-State - 1% for 0-150/ 3% 150.01 - 300 / 5% 300.01 - 600/ 8% 600.01 - unlimited
- amount after all deductions is the net pay ( show this amount on its own line)
- Start a loop that asks each time if there are more employees (y/n) y should continue the program and n should end it
-dialog boxes should be created to recieve values for name, hours and rate
- if the rate is entered below $8 dollars a new box should pop up and ask for a higher value
- When there are no more employees, print out a summary of quantities stored in static variable (also had a problem with this)
- End

So I think i completed most of these objectives but am having trouble with the syntax and some of the objectives

View Replies View Related

Unreachable Statement Error

Jun 11, 2014

I cannot see why I am getting an 'Unreachable statement' error on 'return -1;' on line 13126.I am also getting a 'missing return statement' error on the very last line.

/* 12992: */ private int extractInterfaceValues(RSInterface class9, int j)
/* 12993: */ {
/* 12994:11712 */ if ((class9.valueIndexArray == null) || (j >= class9.valueIndexArray.length)) {
/* 12995:11713 */ return -2;
/* 12996: */ }
/* 12997: */ try
/* 12998: */ {
/* 12999:11716 */ int[] ai = class9.valueIndexArray[j];
/* 13000:11717 */ int k = 0;

[code]....

View Replies View Related

2D Array Addition - Not A Statement Error

Dec 19, 2014

I am new to java programming. I want to write a java program for 2D array addition. My code is:

Java Code:

class Matrixadd {
public static void main(String...s) {
int x[][]={
{1,2,3},
{4,5,6},
{7,8,9},

[Code] .....

I am getting a 'Not a statement' error at line 36.

View Replies View Related

Editing Jar File - Not A Statement Error

Jun 22, 2014

So, I decompiled a jar file and went to edit some code, but this is the only error i get upon decompiling which I am unable to find a fix for.

int i3 = var32.read(abyte0, k2, exception4);
if(i3 < 0) {
"Length error: " + k2 + "/" + j2; //Not a statement
throw new IOException("EOF");
}

View Replies View Related

If-else Statement Not Working - Syntax Error

Sep 14, 2014

My if else statement is not working...it keeps telling me that the else in the statement is a syntax error and that I should remove it. Whats wrong with it?
 
package Homework2;
import java.util.Scanner;
public class Homework2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Welcome to the Triangle Program.");
 
[Code] ....

View Replies View Related

Amount Of Money - Compile Error / Unreachable Statement

Feb 14, 2014

This method accepts 1 integer, amount (the amount of money). Output the minimum number of in quarters, dimes, nickels and pennies used to make up the amount. For example, an amount of 32 would require 1 quarter, 1 nickel and 2 pennies.

This is the question^

My codes are:

public static int change (int amount) {
int quarters = amount / 25 ;
int firstresult = amount % 25 ;
return quarters ;
int nickel = firstresult / 5 ;

[Code] .....

The codes were working when i used System.out.println instead of return, but our teacher required us to use return (functions).

I get the compile error: Unreachable statement.

View Replies View Related

Program Outputting Null Into Validation Statement - Runtime Error

Oct 17, 2014

I am Having trouble with my program to validate. It is outputting null into the validation statement then it brings back a run-time error to that validation Statement for the String.

public String validateData ()
{
if (nm == null)nm = "Error! Must enter at least one character";
else nm = name;
return name;
}//end validation method

Why is this happening, and then once that is completed, why is the validation Sentence in tests Scores not able to validate. I traced it back to out put "Error, a number between 1<100".

public void validateTests ()
{
String testschange;
if (test1 < 0 || test1 > 100) {
testschange = " You have entered an invalid number, between 1-100. Please restart!";
testschange = Integer.toString( test1 ) ;

[Code] .....

View Replies View Related

Numeric Or Value Error In Procedure When It Is Called In Callable Statement In Java?

Jun 3, 2014

I have a problem about this numeric or value error on my java class. Whenever I am calling for the procedure in callable statement it says that error. I don't know what is the problem with my sql code because I;ve tried running it on database alone and it runs perfectly. The results that I need came out fine. But when I'm already calling it in java that error appears. But I tried on finding the line that the said error is coming from and here is the code...
 
create or replace
PROCEDURE RENTING
(P_NNAME IN VARCHAR2,
P_ADD IN VARCHAR2,
P_PHONE IN NUMBER,

[Code] ...

View Replies View Related

Sorting With Two Stacks

Oct 16, 2014

So we have to ask the user to put in a string of letters, and bring those letters in as cars to where there is a storage area and an assembly area, and we have to sort them from there into the assembly area with the smallest (A) at the head. I think I set up my code pretty well, but when I run it, no matter what I put in it returns CBAo. Say I input KATE, it should return TKEA but instead CBAo or if I input JANICE it should return NJIECA but it just returns EDCBAo. Here's my code:

import java.util.Scanner;
import java.util.Stack;
public class carStacksDessart
{
public static void main(String[] args) {
Stack<Integer> storage = new Stack();

[Code] ....

View Replies View Related

Write A Code Using The Stacks?

May 15, 2014

write a code using the stacks?i want the output to produce my name.

View Replies View Related

Printing 8 Queens Using Stacks

Nov 16, 2014

I am having some trouble with this program. I am getting only one result to print when it should show all the solutions. Also the 1 solution I am getting is only printing 7 queens not 8.

import java.util.Stack;
public class Queen1 {
boolean conflict, complete = false;
public int solve(int n) {
//create a stack
//each element stores the position of the queen on a different row
Stack<Integer> s = new Stack<Integer> ();

[Code] ......

View Replies View Related

How To Make Calculator Using Stacks

Feb 5, 2014

I got to make a java code for my class. I must make a calculator using stacks. I have a code but i got some mistakes. Here is the code

Java Code:

package stackscalc;
import java.util.Scanner;
import java.util.Stack;
import java.util.EmptyStackException;
class Arithmetic {
int length;
Stack stk;
String exp,

[Code] .....

View Replies View Related

Make A Calculator Using Stacks

Feb 4, 2014

i got a problem with this program.I am supposed to make a calculator using stacks but it seems that i m stack. i can t get the right recognition

for () and {} []

its not necessary to use all these symbols.just a simple () will do .here s the program

package stackscalc;
 
import java.util.Scanner;
import java.util.Stack;
import java.util.EmptyStackException;
class Arithmetic
{
int length;
Stack stk;
String exp,
postfix;
 
[code]....

View Replies View Related

Make Array With Three Stacks

May 17, 2014

public class ThreeStackArray
{
static int row = 10;
static int col = 2;
int[][] stack = new int[row][col];
//place numbers into the first row of array
public void push(int num)

[Code] .....

I found this program idea online. Make a array with three stacks. Either I jump out of bounds if I use "continue" instead of "break" in my loop in the push method. If I use break the output looks like:

12900
0000
0000
0000
0000

if I use continue the output looks like:

An error has occured java.lang.ArrayIndexOutOfBoundsException: 2
1212
1212
1212
1212
1210

View Replies View Related

Exception In Matching Parentheses Using Stacks

May 11, 2014

I am trying to write a program that checks for parentheses matching using stacks.This is my ArrayStack class.

public class ArrayStack{
private final int DEFAULT_SIZE=10;
public int tos;
Object[] array;
public ArrayStack(){
array=new Object[DEFAULT_SIZE];

[Code] ....

But the problem is when I compile matching I get an error as unreported exception EmptyStackException.must be caught or declared to be thrown. I think the problem is with exceptions which I don't have a good knowledge of.

View Replies View Related

Check If A String Is A Palindrome By Using Stacks

Oct 23, 2014

I'm supposed to use stacks (implemented with an array) to check to see if a string is a palindrome. I've finished all my classes and methods, but I'm getting an ArrayIndexOutOfBoundsException when I try to run my demo program.Here are my classes:

public interface Stack {
// Creates an empty stack
public void initializeStack()
// Returns true if the stack is empty, returns false otherwise
public boolean isEmpty();
// The stack can never be full, so always return false
public boolean isFullStack();

[code]...

View Replies View Related

Stacks And Priority Queues Project

Feb 21, 2014

So I have 3 classes in this project, and When it compiles, I get a null pointer.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
public class Project2 {
 
[Code] .....

View Replies View Related

How To Perform Calculations Using Stacks Java

Nov 23, 2014

I am doing a calculator using stacks but when i try to calculate I getting the wrong data example stack contains 8 and user enter -3 stack should change to 5.

package comp10152.lab5;
import java.util.Scanner;
import java.util.Stack;

[Code].....

View Replies View Related

Evaluating Infix Expressions Using Generic Stacks

May 12, 2014

I am given the task to create a program that evaluates infix expressions using two generic stacks, one operator stack and one value stack.

This is my GenStack.java file:

import java.util.*;
public class GenStack<T>{//T is the type parameter
private Node top;//top of stack
public class Node {//defines each node of stack
T value;
Node next;

[Code] ....

I'm having trouble with the eval and apply methods. The eval method doesn't appear to pickup ')' characters, like it doesn't even see them.

View Replies View Related

How To Turn If Statement Into A Case / Switch Statement

Jun 19, 2014

So from what iv learnt in Java and programming in general is that using a case statement is far more efficient that using multiple IF statements. I have an multiple IF statements contained within a method of my program, and would like to instead use a case statement.

public String checkPasswordStrength(String passw) {
int strengthCount=0;
String strengthWord = "";
String[] partialRegexChecks = { ".*[a-z]+.*", // lower
".*[A-Z]+.*", // upper
".*[d]+.*", // digits
".*[@#$%!]+.*" // symbols

[code].....

View Replies View Related

Changing Infix To Postfix Notation Using Stacks - How To Utilize Hash Maps

Apr 7, 2014

So I am supposed to be changing infix notation to postfix notation using stacks. This is simply taking a string "3 + 5 * 6" (infix) and turning it into (3 5 6 * +" (postfix).

To do this, we are to scan the string from left to right and when we encounter a number, we just add it to the final string, but when we encounter an operand, we throw it on the stack. Then if the next operand has a higher input precedence than the stack precedence of the operator on the top of the stack, we add that operator to the stack too, otherwise we pop from the stack THEN add the new operator.

I am supposed to be utilizing a hash map but I don't see how you would go about doing this. We are supposed to store operators on the hash map but operators need their own character, input precedence, stack precedence, and rank. How do you use a hash map when you need to tie a character to 3 values instead of just 1? I just don't get it.

The following is our Operator class that we are to use. Another problem is this isn't really supposed to be modified, yet we were given two important variables (inputPrecedence and outputPrecedence) that we can't have nothing to be initialized to and no way of accessing? So that might be where a hash map comes in but I am not sure. I am not very sure on how they exactly work anyway...

public class Operator implements Comparable<Operator>
{
public char operator; // operator
privateint inputPrecedence; // input precedence of operator in the range [0, 5]
privateint stackPrecedence; // stack precedence of operator in the range [-1, 3]

[Code] ....

So my question mostly revolves around how I tie an Operator character to its required values, so I can use it in my code to test two operators precedence values.

My original thought was turn string into character array, but then I would need nested for/while loops to check if it is a number or letter, or if it is an operator and thus result in O(n^2) time

View Replies View Related

Using Switch Statement Inside If Statement

Nov 18, 2014

So I want to make a simple Java that ask the user to pick a powers and it has two options.If the user picks magic then execute the first if statement then ask the user again which type of magic the user wants.I can't make it work it keeps printing the else statement. Why is that?

import java.util.Scanner;
public class Variable {
static Scanner zcan = new Scanner(System.in);
public static void main(String[] args)

[code]....

View Replies View Related







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