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.
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 need the user to be able to input a number, and for the program to assign this value to an 'int' variable. I know how to do this with a 'string' variable:
Java Code:
String options = JOptionPane.showInputDialog(null, "In your decision, how many options do you have? " +" (NOTE: The maximum number of options = 5, and you must enter your answer as a numeral.)"); mh_sh_highlight_all('java');
But I need to know how to do this with an 'int' variable.
I'm studying about arrays and I have some questions:
First, is there any difference between these two?
Java Code:
int x[] = new int[3]; int[] x = new int[3]; mh_sh_highlight_all('java');
It seems to me when I try them they do exactly the same, is that correct?
Second, more important question. If I want to make an int variable that refers to the index number of an array, how do I write? For example if we have
Java Code: String[] string = new String[10]; mh_sh_highlight_all('java');
And I want to have a variable "int n" that refers to an index number, so that if I set n = 5 then string[5] is selected. Note that the int n is NOT an array, but just a regular integer variable. How can I do that?
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.
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;
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();
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'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.
The program i am working on is to take string from the user which should be a phone number then it will return true or false based upon the method that checks to see if it meets the criteria of a certain format if does not it will return false otherwise return true. I am working on a if/else structure that will print this number is valid if it meets the criteria of the method i previously mentioned or return the number is not valid if it is false. the logic of the expression i put in the parentheses of the if/else statement. This is what i have so far:
if(){ System.out.println("The phone number is valid"); } else { System.out.println("This isn't a valid phone number"); }
Do i need to compare it based upon the method that checks if it is true?
I have searched for totalPay is always 0 and the responses are not related to my problem (that I can tell).This is a class assignment and I have other questions besides why the method is not working.
Here are the instructions: Create class Employee which contains a String variable Employee Number, a String variable Employee Name, an integer Hours Worked, and a double Pay Rate. Create get and set methods for each variable. Provide method "totalPay" which calculates and returns the total pay by multiplying the hours worked by pay rate. Use figure 8.12 as an example of an object with get and set methods.
Unlike other examples of this type question online this one has Employee Number as a String variable. The book is How to Program Early Objects by Deitel 9th edition.We have instructions to do only what she has told us too. At this point it is objects and getter and setter methods. It is only the beginning of week 2.
ON THE LINES WHERE I HAVE QUESTIONS I AM COMMENTING IN ALL CAPS. NOT SHOUTING, JUST TRYING TO MAKE IT EASIER
package test11; import java.util.Scanner; public class Test11 { public static void main(String[] args) { Scanner input = new Scanner(System.in);
[code]..
Essentially I cannot figure out how to get the method getTotalPay to be called by the Scanner and do the math. I also have this random bracket problem that showed up about an hour ago.
The concept I don't get is that if I omit this.employeeNumber =id; etc. I error all over the place. If I change it to this.employeeeNumber = employee Number Netbeans tells me it is assigning itself to itself, which I know. When I try to use id instead of employeeNumber I get errors all over. If i remove "this" from it the same happens. why in public class employee I have to change to those values (id, name, etc) in the construct and set them again? I don't see where or how they can be used, so why do i have to do it?
I've decided to go back to basics and start using pseudocode--but i want to see if my logic is correct.so here's the first program:each delegate to a certain conference must wear a tag showing their name and the organization they represent as shown below:
######################
#### Annual Conference #####
######################
##NAME: ##
######################
##ORGANIZATION: ##
######################
write a class called TagMaker that prints out tags. supply methods to (a) set the name (b) set the organization (c) print tag with the name and organization (d) clear the name and organization (e) print a blank tag. then write a TagTester class to test the TagMaker class. so this is the pseudo code (or logic) that i've come up with for the program:
TagMaker main class:
-Prompt user to enter in first and last name, as well as their organization.
-Read user input for the name and organization.
-Return user input.
-Write conference tag showing the person's information.
-Clear information.
-Print blank tag.
1. i assume i would have to import a few java libraries.
Java Code: java.util.Scanner mh_sh_highlight_all('java'); and Java Code: java.io.*; mh_sh_highlight_all('java');
2. afterwards i would declare the instance variables (private, i assume). static too? so for example: Java Code: private static string firstName mh_sh_highlight_all('java');
3. i'm not sure if this program requires a constructor...being that i'm supposed to clear the program at the end anyway.
4. i create a public class declaring my input variable. example: Java Code: String first = firstName.nextLine(); mh_sh_highlight_all('java');
5. so i then i have to create methods that get/set the user input.
getter/setter example:
Java Code:
public String getFirst(){ return first; } public void setFirst(){ this.first = new first; } mh_sh_highlight_all('java');
6. to print out both tags, would i write most of the code as part of a loop and make an "if" statement where the user input is valid, it prints out a tag with information, and another "if" statement that would automatically clear the buffer?
7. last i would create a tester class that would primarily be responsible for the program's output.
I'm trying to fix this logic error in my slot machine game where no matter what slot combo comes up, it says you have won $10 and proceeds to add that amount to the balance and subtract the bet amount to the balance, even though it is not a winning combo! I've been trying to solve that and when doing so, I commented out Slot1.randNum1 == 0, Slot2.randNum2 ==0, and Slot3.randNum3 ==0 and anything relating to see if that was the problem, and it seemed like it was, because after that, the logic error described above was gone, but in doing so, the loss/win counter didn't increment, nor did the program pick up on the winning combos. However, I do not know why commenting out anything relating to randNum ==0 would cause that.
Here is the code for the processing (as you can see, some parts are commented in attempt to fix the logic error, but right now the code below is for the logic error that keeps on telling that the user has won):
public void askData () { title (); int betAmount; while (true) { try { c.setCursor (3, 1);
My code runs and populates an arraylist. However my break statement, while stopping the loop ends up being added to the arraylist. And I'm not sure how to fix this error.
public static void main(String args[]) throws Exception { // declaring variables String input = ""; // creating array list ArrayList<String> nameList = new ArrayList<String>();
I want to run a few things in my main when a JButton is pressed but can't work out the best way to do it. Here's the code in the main.
public static void main(String[] args) throws FileNotFoundException, ParseException, InterruptedException{ Map m = new Map("defaultMap"); GameLogic g = new GameLogic("defaultMap"); GodsEyeView gev = new GodsEyeView(g, m); gev.initialRun();
//Want to run this when a button is pressed. HumanUser h = new HumanUser(g); playerGUI gui = new playerGUI(h); gui.run(); gev.run(); }
I was tasked with creating a program that encrypts a line of text (for example, CANDY) by shifting the letters X amount of times. For example, if the user inputs the sentence CANDY and selects a shift of 5, the output would be: HFSID. I got this part working fine. The issue I am having is with the decryption part of the program.
This is simply the reverse of the above, as the user would enter the phrase HFSID, with a shift of 5, and the program would output: CANDY. It works fine, all except for one letter, being the "F" letter. With my code, when I enter the above word to be decrypted it outputs: C[NDY
Obviously, that [ bracket is not an 'A'. I realise the issue falls with the equation, Here is my code:
public class SimpleEncryption {
/** * @param args the command line arguments */ static int answer; public static void main(String[] args) { String cipher = JOptionPane.showInputDialog(null, "Please enter a sentence or word that you wish to encode or decode. This program uses" + " a basic cipher shift.");
I need to find the Winner using Object Orientation logic I have my old logic from my Tic Tac Toe game but it is not Object Orientated. So I want to convert it and add that code to my GUI Tic Tac Toe. I need to return a winner or tie.
I am going to develop a new web application of medium complexity. Right now i am somewhat comfortable with JSF and hibernate. I have never used JSF and hibernate together before.I just wanted to ask if it is good practice to use JSF (for both view layer and handling business logic) and hibernate(for persistence) without spring as a middle layer. The reason why i am asking this is i don't know anything about spring framework.