I've created a truth table for logical operators. Now I'm supposed to alter the code so the table prints 1's and 0's instead of true or false. Here's a bit of the original code - just the header and the first line of the table.
System.out.println("p q AND OR XOR NOT");
System.out.println();
boolean p, q;
p = true; q = true;
System.out.print( p + " " + q + " " );
System.out.print( ( p & q) + " " + ( p | q) + " ");
System.out.println(( p ^ q ) + " " + ( !p) );
All of my ideas involve using an if-then statement, but that would be all kinds of inefficient and unwieldy, I think.
I'm supposed to take this truth table and alter it so it displays 1's and 0's instead of true false. I'm assumed to do this I would just need to change the variable type and replace true and false with 1 and 0 but every way I try this does not work.
//a truth table for the logical operators.
class LogicalOpTable { public static void main(String args[]) { boolean p, q; System.out.println("P Q AND OR XOR NOT"); p = true; q = true; System.out.print(p + " " + q +" ");
I am required to make a console calculator that takes the values as strings and turns them into doubles. The user needs to be able to enter something like 3+4+5*9/13 on one line and the application give the answer. As of this point I am currently on at the last section as making the user be able to enter the expression and present the answer. I have added an array list containing + - / * and the same with the numbers 1-9...I now need to actually get the information to all come together. I'm not sure how to do that. I *think* I have all the parts for it to work.
public static void main(String[] args) { String input = ""; // initalize the string boolean isOn = true; // used for the while loop...when false, the // program will exit. final String exitCommand = "Exit"; // exit command
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 ;
Total IS those numbers. But question[10] will not cooperate with me and it's getting a bit aggravating as I can't find a logical reason for it to be doing that.how to perhaps lock the value of total and sTotal after 10 button clicks from any?
The title says already where my difficulties are. I forgot to say, the "S" printing part works, but why the others doesn't. To make it more clear:
java Monoton 1 3 3 4 & java Monoton 1 3 4 1
=> nothing (my output)
I forgot to notice, with 1 3 3 4 as parameters it jumps out at if (b < c), which is expected. but it jumps out of the whole if instead just run the else part. that's the essence of my problem.
The Exercise:
=> The program should print the following letters;
S, if every number is true bigger than the before,
M, if every number is bigger or equal than the before,
N in the other cases
Examples (from the exercise)
=> java Monoton 0 1 2 4
S
=> java Monoton 1 3 3 4
M
=> java Monoton 1 3 4 1
N
The Exercise should done without the use of logical operators or other combined requirements.
Java Code:
public class Main { public static void main(String[] args) { int a = Integer.parseInt(args[0]); int b = Integer.parseInt(args[1]); int c = Integer.parseInt(args[2]); int d = Integer.parseInt(args[3]);
How do I get the code to use decimals? Also whenever you input 1, 2 or 3 as one of the operators, it always does that operator as well as the 4th operator at the end. So it always does subtraction. However when you use 4 as the only operator it works perfect.
import java.util.Scanner; public class Program05 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); double left; double right;
if (number % 2 == 0 && number % 3 == 0) System.out.println(number + " is divisible by 2 and 3");
if (number % 2 == 0 || number % 3 == 0) System.out.println(number+ " is divisible by 2 or 3");
if (number % 2 == 0 ^ number % 3 == 0) System.out.println(number + " is divisble by 2 or 3 but not both");
I understand the logic operators and the variable number, what i dont understand is what number % 2 == 0 and number % number == 0 mean. I know that % is a remaining operator and == means equals, i know that = and == are not the same.
So my little math game is working so far. I can only do addition though. I know how to fix it if I can find out how to generate random math operators. After that I want to use a loop (or a better technique) to ask ten different math questions before the game is over.
package pkgnew; import java.util.Scanner; import java.util.Random; public class New { public static void main(String args[]) { //Declare and construct variables Random randomnum = new Random();
Assuming that x, y, and z are integer variables, which of the following three logical expressions are equivalent to each other, that is, have equal values for all possible values of x, y, and z?
(x == y && x != z) || (x != y && x == z) (x == y || x == z) && (x != y || x != z) (x == y) != (x == z)
None of the three
A. I and II only B. II and III only C. I and III only D. I, II, and III
I selected B, but got it wrong. I really think I need understanding boolean logic. The correct answer says something else but I don't get the logic. Here is the correct answer:
Answer Key : The following model answer has been provided to you by the grader. Carefully compare your answer with the one provided here.
Expression III is the key to the answer: all three expressions state the fact that exactly one out of two equalities, x == y or x == z, is true. Expression I states that either the first and not the second or the second and not the first is true. Expression II states that one of the two is true and one of the two is false. Expression III simply states that they have different values. All three boil down to the same thing. The answer is E.
In exercise 4, I get the same problem:
The expression !((x <= y) && (y > 5)) is equivalent to which of the following?
A. (x <= y) && (y > 5) B. (x <= y) || (y > 5) C. (x >= y) || (y < 5) D. (x > y) || (y <= 5) E. (x > y) && (y <= 5)
Exercise 4 ABCDE Incorrect Score: 0 / 1 Submitted: 2/10/2014 8:21pm Your answer is incorrect. Answer Key
The following model answer has been provided to you by the grader. Carefully compare your answer with the one provided here. The given expression is pretty long, so if you try to plug in specific numbers you may lose a lot of time. Use De Morgan's Laws instead:
!((x <= y) && (y > 5)) !(x <= y) || !(y > 5)
When ! is distributed, && changes into ||, and vice-versa
I was told to create a class named Billing that includes three overloaded computeBill methods for a photobook store.
The first method takes the price of the book ordered, adds 8% tax and returns the total due. The second method takes the price of the book, and the quantity, adds tax and returns the total. The final method takes the price, quantity and a coupon discount, adds tax and returns the total.
All of this I have managed fairly well, although I keep getting a strange error at the end of my program that the constructor is undefined. The problem bits of code(the one throwing the errors) are under the comment //Enter values into each of the methods
Code:
package org.CIS406.lab2;
public class Billing { //Declarations double bookPrice; int quantityOrdered; double couponValue;
[Code] ....
My first thought was to create a constructor for each of the methods that I am using...
I am working in the field of validating data. I need to validate names and test scores and i keeping getting errors in my code. I keep tracing back all the errors and now I am stuck at a logic error. It is giving me a the validate sentence over and over even when i type stuff in. I have searched up how to do the .equals to a string but it doesn't give me a accurate enough to my problem.
import java.util.Scanner; public class P5A { public static void main (String args[]) { System.out.println( "Always Show" ); Scanner reader = new Scanner(System.in);
I am thinking of a project for my university the teachers liked it but I am not sure if its even possible.I am trying to make an andriod app. What I want to do is take a picture of a hand drawn logic circuit (having the AND, OR, NOT ... gates) recognize the gates, and make a circuit in the moblie and run it on all possible inputs.
For this I will have to make a simulator on mobile, that I dont think is the hard part. The problem is how could recognize the gates from a picture. Example of logical circuit is attached ( assume its hand drawn )..I found out that theres a edge detection plugin in java but still I dont think its enought to recognize the gates. Please share any algorithm or any technique or tools that I can use to make this thing.
I'm building an application in Netbeans and so far I'm making good progress with it. I have created an animated splash screen in myspacegen.com and then downloaded it as a GUI file. I've then imported it into my application in Netbeans but I was restricted in myspacegens.com to the size of the image I could create. I want to know if it is possible to add code to the splash screen project within Netbeans so that it automatically adjusts to fill the screen. I have used the java commands get width and get height elsewhere in my application so that the window I create in a project automatically adjusts to fill the operator's screen but that has a 'window' to adjust and I do not want my splash screen to have a visible window.
I need to process one component drag to the table. I misunderstand, how I can see to which Cell fall the component. I tried to use Event and Mouse event handlers in my custom Cell, but they do not work. I can copy the drag event to the table and table handles it, but how to get needed Cell I cant understand.
This is my codes in a button that if I click it . that information will send to Jtable but the problem is the jtable is in another frame so how can i connect this ?
DefaultTableModel model = (DefaultTableModel) new admin().tableBagtags.getModel(); if (txtName.getText().equals("")) { JOptionPane.showMessageDialog(null, "Please fill out all fields.", "Error!", JOptionPane.ERROR_MESSAGE);
This simple program should build a new table with random values and on the getValue method (perhaps called from othe TestClass) return back content of particular cell. why my getValue method doesn't work. Nay! It returns error while compilation.
import java.util.Random; class TablicaIntowa{ public int getValue(int a){ return tabl[a]; } //getValue method end