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;
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 ?
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 ;
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
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;
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.");
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 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 ) ;
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,
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();
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> ();
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
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.
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();
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.
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.
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.
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
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)