Im try to create a java program that checks to see if a given boolean expression is a tautology or not
my code so far is as follows:
public static class TreeNode
{
char data;
TreeNode left;
TreeNode right;
TreeNode(char item)
{
data = item;
left = null;
right = null;
}
}
public static class Tree
{
boolean operator(char x) // if isUpperCase
{
if(Character.isUpperCase(x))
{
return true;
}
return false;
}
TreeNode buildTree(char s[])
{
Stack<TreeNode> stack = new Stack();
TreeNode tN;
TreeNode tN1;
TreeNode tN2;
for(int i = 0; i < s.length; i++)
{
if(!operator(s[i]))
{
tN = new TreeNode(s[i]);
stack.push(tN);
}
else
{
tN = new TreeNode(s[i]);
tN1 = stack.pop();
tN2 = stack.pop();
tN.right = tN1;
tN.left = tN2;
stack.push(tN);
}
}
tN = stack.peek();
return tN;
}
public void printTree(TreeNode tN)
{
if(tN != null)
{
printTree(tN.left);
System.out.print(tN.data);
printTree(tN.right);
}
}
//Evaluate/Solve
//To do....
} //End of Tree Class
public static void main(String[] args)
{
Tree newTree = new Tree();
Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a postfix expression:"); //Example: ppO
String s = keyboard.nextLine();
char[] array = s.toCharArray();
TreeNode trNode = newTree.buildTree(array);
newTree.printTree(trNode);
}
}
static void Main() { Console.Write("Enter a character: "); char c = (char)Console.Read(); if (Char.IsLetter(c)) { if (Char.IsLower(c)) { Console.WriteLine("The character is lowercase."); } else { Console.WriteLine("The character is uppercase."); } } else { Console.WriteLine("Not an alphabetic character."); } } }
Im try to create a java program that checks to see if a given boolean expression...
JAVA Lab Create a class called ArrayBasedStack. Declare the following variables: • data: references an array storing elements in the list • topOfStack: an int value representing the location of the stack top in the array • INITIAL_CAPACITY: the default capacity of the stack public class ArrayBasedStack <E> { private E[] data; private int topOfStack; private static final int INITIAL_CAPACITY = 5; } Add a constructor that will initialize the stack with a user-defined initial capacity. The top of the...
Convert infix to postfix, and evaluate postfix using custom Stack created using a singly linked list. This is only supposed to use THAT method, calling a normal Stack will give me a zero. I do have the conversion to postfix, but there may be error in there. But the main problem currently is the evaluation of postfix. I keep getting an error that I made for an empty stack, which I will include. For testing it is only supposed to...
Q1) Write a method called inToTree of ExpressionTree class which takes a string of infix expression (fully parenthesized), resets the root of the expression tree to such tree which constructed from the expression. The root set to null of the expression contains characters other than value, operator, and parenthesis or if it’s not an in-fix full parenthesized expression. You may assume each value is single digit only . public void inToTree(String expression){ You may use a JCF Deque class as...
java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then output comes like this 5 4 3 2 1 Stack is empty. here is the code that i'm going to use class Stack<T> implements Iterator<T> { LinkedList<T> list; public Stack() { list = new LinkedList<T>(); } public boolean isEmpty() { return list.isEmpty(); ...
Using Java programming: Modify the delimiter class (provided below) so that it can "incorrectly" evaluate simple parenthesized math expressions . a) ask the user for the whole expression to solve b) Solve the expression only if there is no mismatch in the delimiters. If there is a mismatch, then output an error. If there is an error, allow the user to reenter a corrected/new expression. c) The program should be able to evaluate expressions that uses only the following basic...
Complete the implementation of the LinkedStack class presented in Chapter 13. Specifically, complete the implementations of the peek, isEmpty, size, and toString methods. See Base_A06Q1.java for a starting place and a description of these methods. Here is the base given: /** * Write a description of the program here. * * @author Lewis et al., (your name) * @version (program version) */ import java.util.Iterator; public class Base_A06Q1 { /** * Program entry point for stack testing. * @param args Argument...
*JAVA* Can somebody take a look at my current challenge? I need to throw a different exception when a)(b is entered. It should throw "Correct number of parenthesis but incorrect syntax" The code is as follows. Stack class: public class ArrayStack<E> { private int top, size; private E arrS[]; private static final int MAX_STACK_SIZE = 10; public ArrayStack() { this.arrS = (E[]) new Object[MAX_STACK_SIZE]; this.top = size; this.size = 0;...
Please create a class in Java that completes the
following conditions
MorseTree.java
/* This program will read in letters followed by their morse
code
* and insert them properly in a tree based on the amount of
symbols
* it has and whether they are left or right descendent.
Finally
* it prints a few certain nodes.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class MorseTree {
public static void main(String[] args) throws
FileNotFoundException {
//...
I am trying to understand the following code I found in a website so that I can use it for a project that evaluates boolean expressions. The code is below but I think it is in java because I do not understand it. Can you help me describe what it is doing in c++ so that I can understand it better? The link to the code is here: https://stackoverflow.com/questions/16762057/algorithm-to-evaluate-value-of-boolean-expression The code is below: public static boolean evaluateBool(String s) { Stack<Object>...
What is wrong with my code, when I pass in 4 It will not run, without the 4 it will run, but throw and error. I am getting the error required: no arguments found: int reason: actual and formal argument lists differ in length where T is a type-variable: T extends Object declared in class LinkedDropOutStack public class Help { /** * Program entry point for drop-out stack testing. * @param args Argument list. */ public static void main(String[] args)...