In my application a series of inputs and a calculated result. At the end of each loop these inputs and calculations are displayed. After the loop is over with the user does not enter a string that is "y" or "Y", I want these inputs and the calculation to be displayed in a First in First Out format or a stack. I am using a LinkedList that is used in a class creating a stack.
Here is the code for my stack.
Java Code:
import java.util.LinkedList;
public class GenericStack<E> {
LinkedList<E> stack = new LinkedList<>();
public void Push(E element) {
stack.addFirst(element);
[Code] ....
Here is the code containing the main method. The methods other than the main method are probably not relevant to the problem, but take a look if you like.
Java Code:
import java.util.*;
import java.text.*;
public class FutureValueApp
{
public static void main(String[] args) {
GenericStack<String> stack = new GenericStack<>();
[Code] ....
The stack seems to be adding the same inputs and the same calculation from the first loop, even when it is on it's 2nd or third loop. I am getting this output.
Java Code:
Monthly Inv.Int. RateYearsFuture Value
$5.002.0%5$315.76
$5.002.0%5$315.76 mh_sh_highlight_all('java');
Right now I have three stacks. Each stack holds characters, with the normal operations of pushing and popping. I am trying to compare two characters from stack1 and stack2(each character is a digit character). I would like to be able to do arithmetic on the digit characters and the push the answer on to a result stack.
Ex.) I pop character '3' from stack1 and '5' from stack2. Then I add the two. equaling '8' and pushing that character on to the result stack. This will hopefully in turn allow me to add arbitrary large numbers that integers will not support.
I am having trouble because I believe I am getting some ascii character values when I pop off the result stack. here is a small piece of my code
public void addition() { char temp1 ,temp2; int i = s1.getSize(); for(int j= 0;j<i;j++) { temp1 = s1.pop(); temp2 = s2.pop(); if(temp1+temp2>=10)
I'm supposed to add characters to a stack and pop them once the adjacent delimiter is read in from a text file. Moreover, program is supposed to print out the incoming text from the file, but stop when the applicable delimiter is not on top of the stack. As in, a '[' doesn't have a ']'.
I've got the program so it can pop and add to the stack correctly, and stops adding at the correct time, but I cant seem to get it to stop printing. I know a switch statement method in another class seems obvious, but I was trying to practice nested loops.
This is the main program:
import java.io.*; import java.util.Scanner; import java.io.IOException; import java.util.Stack; public class DelimiterChecker { public static void main(String [] args) throws IOException {
I had to write a foor loop to count the values of a stack of quarters from 1.00 to 3.00 and I had to print the values, that I understood and got it working so I taught the next assignment was going to be easier but I am having a hard time with it. For this one I have to write a for loop to print all the positive integer factors of 144 and I am supposed to print of factor per line but I tried doing that but it doesn't work it just prints out 144.
This is my code. The quarter assignment is also in there because it is part of a lab so just ignore that part since it is working correctly.
public class ForLoopPractice { public static void main(String [] args) { // Write a for loop to count out the values of a stack of quarters from $1.00 to $3.00 // Print the value of each iteration. Print this all on one line, rounded to the nearest cent. // To print rounded, use printf, with a placeholder of %.2f // (%f is the floating-point placeholder; the .2 indicates the number of decimal places) /* YOUR CODE HERE */ for (double q = 1.00; q <= 3.00; q += .25)
I have a supermarket checkout line where i have a list of available products on the left and then a basket on the right with the products in. The products are listed in an array, here is the product class
public class Product { private String name; private double weight; private double price;
[Code] ....
with getters and setters excluded, and the list these are put into
public class productList extends DefaultListModel { public productList (){ super(); } public void addProduct (String name, double weight, double price, int code){ super.addElement(new Product(name, weight, price, code));
i have the price for each product to be displayed in a text field with the following code
addBasketItem = new JButton(); getContentPane().add(addBasketItem); addBasketItem.setText("Add >");
[Code] ....
defaultCheckoutList contains my available items and defaultMainList is the basket, with mainTillPrice being the jtextfield.
This works to get the price however it just replaces each time i make a new entry with the price for the next item, i want a total of the price of all the items i have added, but not sure how.
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Hmwk1 { public static void main(String[] args) { String fileName = "lotto.txt"; final int arraySize = 45; int[] count = new int[arraySize];
[Code] .....
My problem is where do I start or add the following code to be added?
I only want to use 1 array and may be or should I try a catch block? The number or numbers that were picked least frequently.
The average number of times that all of the numbers were picked. For example, the average might have been 210 times.
The number or numbers that were picked the average number of times.
The number or numbers that were picked most frequently.
Alright, so i'm working on this and what I want to do is calculate all of the answers when the values of the correct answer = 1 and the incorrect answer = -1 so at the end of the test I can calculate answer + answer2 + answer3 and so on to get a total score...How do I do this? I've been looking online for 3 hours and i'm just stumped.
import java.util.Scanner; class HorticultureQuiz { public static void main(String[] args){ String name; String major; String confidence;
[Code] ....
I thought I could make each answer = to 1 but then I would need a -1 if the answer was incorrect so I tried this.
char answer = sc.nextLine().toLowerCase().charAt(0); if (answer == 't' || answer == 'T') answer = 1; { System.out.print("Great Job, that is correct!"); } else answer = -1; { System.out.print("Correct answer is false"); }
I'm having an issues with adding integer values to a string list. The question is asking me "the method should iterate over runners, and for each runner generate a random number between 90 and 180 (inclusive) which should be used to set the time (in minutes) for that runner."
I have been able to get the random number and iterating over the runner arraylist but I haven't been able to figure out how to add the values generated into the runners list. I am also using BlueJ.
Here's the whole code I have at the moment:
import java.util.*; import java.io.*; import ou.*; import java.util.Random; /** * Write a description of class MarathonAdmin here. */ public class MarathonAdmin { // instance variables - replace the example below with your own
if I want to add a number of X consecutive values in an array and get the minimal total value along with the indexes that caused this result, how can I do that? for example:
X = 2 array[4] = (5,2,8,6,7)
start adding every 2 consecutive values as following:
I want to use JTable in which the user can enter the obtained marks of students and automatically add (total) the obtained marks in the total column. The structure of the table is given below.
Here is my problem: if I want to add a number of X consecutive values in an array and get the minimal total value along with the indexes that caused this result, how can I do that?
For example:
X = 2 array[4] = (5,2,8,6,7)
start adding every 2 consecutive values as following:
I need a way to store the pixels values currently on the screen and compare them to the values on the first frame. Right now I'm using glreadpixels as follows:
currentBuffer= BufferTools.reserveByteData(mapSize); glReadPixels(mapStartX, mapStartY, mapWidth, mapHeight, GL_BLUE, GL_UNSIGNED_BYTE, currentBuffer); for (int i = 0; i < mapSize; i++) { if (currentBuffer.get(i) != baseBuffer.get(i)) { //Do nothing continue; } //Do something }
This works perfectly fine but turns out to be a real bottleneck, dropping the fps to a third of what it was. Is there any quicker way? All I'm after is speed, I don't even need to show it on the screen if the comparison is made "behind the scene".
after i am done calculating everything from numbers stack, i pop the last number and return it... my question is how can i catch an exception if the size of my numbers stack is greater than 1;
public static String evaluate(String input) { char[] a = input.toCharArray(); if (input.isEmpty()) return "No input"; else if (input.equals(" ")) return "No input"; else if (input.equals(" "))
Write a method compressDuplicates that accepts a stack of integers as a parameter and that replaces each sequence of duplicates with a pair of values: a count of the number of duplicates, followed by the actual duplicated number. For example, suppose a variable called s stores the following sequence of values:
This new stack indicates that the original had 5 occurrences of 2 at the bottom of the stack followed by 2 occurrences of -5 followed by 4 occurrences of 3, and so on. This process works best when there are many duplicates in a row. For example, if the stack instead had stored:
bottom [10, 20, 10, 20, 20, 10] top
Then the resulting stack after the call ends up being longer than the original:
bottom [1, 10, 1, 20, 1, 10, 2, 20, 1, 10] top
If the stack is empty, your method should not change it. You may use one queue as auxiliary storage to solve this problem. You may not use any other auxiliary data structures to solve this problem, although you can have as many simple variables as you like. You may not use recursion to solve this problem. For full credit your code must run in O(n) time where n is the number of elements of the original stack.
I wrote a code but still having a problem with it , am I allowed to use 3 while loops ?
public void compressDuplicates(Stack<Integer> s ){ Stack<Integer> backup= new Stack<Integer>(); int count = 1; while(!s.isEmpty()){ int temp = s.pop();
For my classes I wrote I have puts strings into a stack and also a queue and am wondering how to take the top of the stack and the front of the queue and turn those into strings in my main class and run them through while loops that will detect if they are palindromes or not. Right now I am trying to peek and use first to put in my while loop but they don't work with the .charAt because they are not considered strings I think.
import java.util.Stack; public class Palindrome { public static void main(String[] args) { // TODO Auto-generated method stub String enteredLine; int leftStack, rightStack; int leftQueue, rightQueue;
I tried to write a program to implement a stack but it has a bug I am unable to solve.The bug is that whenever I choose an operation to perform, eg push, After performing the operation, the loop is executed once again and Invalid choice message appears, i.e. the default case. And then the loop again executes to choose further option. Here is my code
class Stack { private char[] stck; private int len; private int top;
I am getting a stack overflow error for my method that recursively gets the height of an AVL tree. The odd thing is that it returns the height of the tree the first time I call that method, but when I call it again later on, I get that error, which I does not make any sense to me. I have a base case, where it is supposed to stop when the node is null, but it never reaches that. Also, when I print out the values, it alternates b/w three values: 5, 4, and 24. Something else, which I think is important to state, is that if I put the print statement before my base case, the IF, I get a warning stating that my entire IF statement is dead code...but why?
is that everytime I insert/delete a value into the AVL tree I must make sure that it is height balanced (none of the siblings may have a difference in height from each other > 1); if its not height then I rotate certain nodes accordingly. The first 10 items that I input are: 100, 50, 24, 200, 190, 10, 5, 190, 100 and 4. The pre and in order prints of these, from the console are:
I am working on implementing a stack using a linked list. Programming the stack operations (push, pop, isEmpty, etc.) was easy but my directions were to provide the user with a menu to choose the operation that he/she wishes to perform. I am new to JFrames/Menus so how to make the stack operations available in a menu.
I have a question in mind that this is my registration form. I am sending these values from HTML form to server and database. I have question that in my case if I click next to Add Another Mobile no in HTML.then a block is genereated and each time a new name is generated.
My Question is if I click 6 times then 6 name attribute are generated. How can I send and differentiate them on my server side.
Because at their I will use something request.getAttribute("Attr_Name");
I'm trying to create a class that takes an String from a Stack and checking if it's a palindrome than taking a another String from a queue and checking if that is also a palindrome.
import java.util.Stack; public class Palindrome { public static void main(String[] args) { // TODO Auto-generated method stub String enteredLine; int leftStack, rightStack; int leftQueue, rightQueue; PalinedromeArray stack1 = new PalinedromeArray();
I have a Char stack: ArrayStack<Character> stek=new ArrayStack<>();
The stack is filled with numbers and characters (only '+' and '*' ), but I need to make calculations, so I need the INT values of the numbers i pop from the stack. So each time I need to make a calculation, I have to pop two numbers, convert them into INT ,then add/multiply them, and put them back into the stack again, but as CHAR (because the stack is not accepting them to be added as INT)
int a= Character.getNumericValue(stek.pop()); //stack no1 int b= Character.getNumericValue(rezultat.pop()); //stack no2 int tmp=a*b; char tmp2 = (char) tmp; stek.push(tmp2);
I have to implement all the stack methods in java such as push, pop empty, not using the ready methods but have to create them and to execute an exercise but is sth wrong with it
public class Stiva { /** the problem is here how to declare the stack 1 and stack 2 and kreu(head) gjmax(size)*/ int Gjmax; int array[] = new int[Gjmax]; int kreu; private Stiva stiva1; private Stiva stiva2;
I have the following code where I call panel repaint method from the action listener of the calc button but it causes stack over flow but when I modify it to call paint component method and removing the super term, the program executes. here is the code