I read in a book that when you change the value of a method parameter that's a boolean or other basic datatype within the method it only is changed within the method and remains the same outside. I want to know if there is some way for me to actually change it within the method. For example:
public class Change {
void convert(boolean x, boolean y, boolean z) { //i want to set x,y, and z to false in this
x = false;
y = false;
z = false;
[code]...
I want to put in part1, part2, and part3 when i call the method than i want them to be set to false within the method. The specific reason i asked this question was because im trying to code a battleship and i have a subroutine class with a method that when its called it checks if a ship has been sunk. If the there was a sink than the method will set a ton of boolean variables to false.
Just to clarify, I want something like this:
void convert(thing1,thing2,thing3,thing4) {
//some code here that sets thing1,thing2,thing3, and thing4 to false
}
// than in main:
boolean test1 = true;
boolean test2 = true;
Java SE Runtime Environment build 1.8.0..This is part of the code:
public static int addAddress (String[] number, boolean[] front, double[] total) { int num = 0; double ffee = 0; /*boolean value = false;*/
[code]...
I have tried using the line of code commented out, /*boolean value = false;*/. However, another error is displayed. The compiler shows the following...
Inspection.java:33: error: incompatible types: boolean cannot be converted to boolean[] front[num]= defineFront(num, value); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output error...I know that boolean values are by default stored as false, once you create the array. However, I'm having trouble passing the variable to the method.
I am working on a program that simulates someone logging in. For this program, I have three methods:
public void input(String text) public void click(String button) public boolean loggedIn()
Naturally, the default status of loggedIn() is false, but I am having trouble changing the boolean to true when a user has successfully entered a username and password.
Specifically,
public void click(String button) { Button = button;//Button is declared at the beginning of the class if(Button == "Submit") { //Statement that changes loggedIn() from false to true when the user clicks the "Submit" button. }
No matter what I try, I get various errors about how what I tried was illegal.
I've been trying to program a software for minimizing (sum of products and products of sum) a boolean algebra using Quine mccluskey method... I've created the GUI and I got stuck in the process... I need a code for minimizing a 10 variable function ....
This program contains a superclass and a subclass that will gather the following information from the user:
name, address, phone number, and customer number.
Everything works fine except that I have to create a boolean method in this program that is required to determine based on user input whether they want to be added to a mailing list.
I cannot get this method to work with main, each time it is called it will always return the value but main will constantly read the last statement (else, where it will read "not wanting to be added to the mailing list).
The only way I can get this part of the program to work is by adding an equals method in main that ignores the case, but I am required to write a boolean method so this is not allowed.
Superclass:
public class Person { private String name; private String address; private String phoneNum; public Person(String pName, String add, String number) { name = pName; address = add;
I am having trouble with a mouse click method. In short I have a hexagon grid, and every time I want to click on one particular hexagon I want the color of the hexagon to change to blue(by default the color is grey). This part works, but when I go to click on another hexagon I want the color of the previous hexagon to change back to grey while at the same time changing the color of the current hexagon clicked to blue. So in other words, I only want one hexagon blue at a time. How might I do this?
I have a hexagon class for one particular hexagon, and a hexmap class for multiple hexagons. I know I should probably be handling mouse clicks in the hexmap since it deals with the whole thing. But I cannot say something like hexagon.setColor within a mouselistener in that class(it gives me a lot of issues). Here is some of my code :
public class Hexagons() public Hexagons(HexMap theMap, int mapRow, int mapCol, int width, int height) { this.map = theMap; this.row = mapRow; this.col = mapCol; this.width = width; this.height = height;
Exception in thread "main" java.lang.NullPointerExceptionat DogTestDrive.main(DogTestDrive.java:19)
Here is the source
class Dog { int size; String name; void bark () { if (size < 60) { System.out.println("Woof woof");
[code]....
Some background: I'm reading "Head first Java 2nd edition" and I'm going through the examples which is showing me how to change the state of an object. The original code looks like the code below, however the previous chapter went over creating array's of an object, so I created an array of the object "Dog" and wanted to re-write it this way. To my understanding, it should work but it's giving me that error when I execute it. The error itself isn't very clear, if I could get a line number pointed to, that would work.
class Dog { int size; String name; void bark() { if (size > 60) { System.out.println(“Wooof! Wooof!”); } else if (size > 14) { System.out.println(“Ruff! Ruff!”); } else { System.out.println(“Yip! Yip!”);
I have two classes involved in this portion. CheckIn_Search
(class #1) is my main UI and I am collecting search information from the user in a jPanel form. When they click "Search" it passes the search criteria to a method that contacts a web service and gets the results. These results are passed to coSearchResults
(class #2) that opens a jFrame and jTable (in modal format, over the main window created by CheckIn_Search.
The user selects a row in the table and that selection data is passed back to coSearchResults to populate a new jPanel form. When the data is passed from coSearchResults, I want to close its window, hide the first jPanel in CheckIn_Search and make the second jPanel visible. To accomplish this, I created a method in CheckIn_Search that simply hides/shows the panels (it will do more later).
I instantiate and call the method in CoSearchResults as part of the button click event. The problem is, it doesn't work. The panels are unaffected and there are no errors. I've put in break-points and it goes into the method.. Here is the coSearch_Results code.
Here is am retrieving the jtable row id and using the first value in the row to get the data from the table model as there is more data than what is displayed in the table. I'm sending that whole row of data to the method that changes visibility.
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed // TODO add your handling code here: int rowNum = jTable1.getSelectedRow(); String coNum = jTable1.getValueAt(rowNum,0).toString(); String[] text;
As you can see there are two listener in my xhtml file one for filetype and other for signmethod. When filtype changes signmethod has to change which in turn changes servers. And if user changes signmethod using dropdown then also server should change. But my problem is when filetype changes, both the listeners are called, as signmethod also changea but the value in event object (e.getNewValue()) is not the new one but old one. Here is the SelectView Bean.This is the static initialisation part just for checking the output at the end of question.
I am changing servers in changeServerAndSignmethod by selecting first signmethod from signmethod arraylist which is giving correct result. But changeServers is also getting fired taking wrong event object's newValue method and changing servers to wrong values. When changeServers is fired bydirectly changing signmethod, by dropdown, it gives correct result. Is there a way I can stop changeServers to fire when the change came from changing filetypes rather than direct change by user on signmethod selectOneMenu.
I am making a program which accepts two user inputs one being a letter either upper or lower case and the other being a number. the out come should be some thing like this:
G GG GGG GGGG GGGGG
This is assuming the user inputted 'G' and '5'.
here is the code i have so far:
package week10; import java.util.Scanner; public class integer { public static void main(String args[]) { Scanner user_input = new Scanner( System.in );
[Code] ....
The problem i am having is that i cant get the number that is inputted to be accepted as a variable to be used for the program.
how to determine if an integer is even or odd by using a boolean method. I think I have the method right, but it's calling the method into the main that has got me stumped.
import java.util.Scanner; public class Odd_Even { public static void main(String[] args) { //Scanner, variables Scanner input = new Scanner(System.in); int number;
So I'm trying to check if the new coordinates vs original coordinates are diagonal and 1 line further, and if there is a piece there(getNum()) if it's 2 lines further, so I'm trying to return a boolean value then.
so if it's the first if, it returns true, if it's the 2nd it returns true, then I say else for all other scenario's, and return false there, but my compiler says my method is missing a return statement.
public boolean check(int[] d) { int x,y; x = loc[0][0]; y = loc[0][1]; int sx = d[0]; int sy = d[1];
[Code] .....
Edit: used a local boolean and returned that after my if's.,
code=Java import java.util.Random; import java.util.Scanner; public final class Derp { public static int WIN, Tick; public static Scanner Input = new Scanner(System.in);
[code]...
why this boolean statement isn't working correctly. It's not detecting that the WIN and Tick are the same and instead chooses to always run the second statement.
I have this project due and its asking that i print out what type of triangle it is when the user inputs 3 sides. I have most of it done and working, but it pops up different windows instead of using one window for everything. The assignment says it needs all the final info to be in one window. The boolean is coming from another method. I'm unsure how to get it into a string (Or if that's what i have to do). The method must return a boolean true/false.
import javax.swing.*; public class Triangle { public static void main(String[] args) { int side1 = getSides(); int side2 = getSides(); int side3 = getSides();
I wrote a class for encapsulating coins and I was to do a boolean statement but when I test the statement the results are not showing.Here is the code for my coin class coins.java
package project_3; /** * * @author user a */ public class Coins { private double pennies; private double nickles ; private double dimes ; private double quarters ; private int dollars ;
I want to write a program that ask if you want to go to the movies. If the user type in yes then it'll print out (Alright let go) but if the user type no then it would print (whatever). The trouble that I'm having is. What's the best way to use Boolean and Strings together in a if statement?
public class Night { static Scanner UserInput = new Scanner (System.in); public static void main (String [] args){ boolean user1, user2; user1 = true; user2 = false;
package Week_8; import java.util.Scanner; public class Task_1 { public static void main(String[] args) { Scanner kboard = new Scanner(System.in); int customer_number; String customer; int items; char category;
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean at javax.swing.plaf.synth.SynthTableUI$SynthBooleanTa bleCellRenderer.getTableCellRendererComponent(Synt hTableUI.java:731) at javax.swing.JTable.prepareRenderer(JTable.java:573 1) at javax.swing.plaf.synth.SynthTableUI.paintCell(Synt hTableUI.java:684)
Boolean retrieval model using skiplist. I don't know how to code it. I have modified it but I'm not sure it work out. What are the modifications I can made.
/**My requirement is to implement two methods for Boolean Retrieval:
● index(String dir) ○ index()supposed to go over all files under "dir". There will be no subdirectories inside it.
● retrieve() ○ retrieve() supposed to return name of all the documents under "dir" that satisfies the given query. Note that, only basename of the files are to be returned, not the full path. ○ Query can be of two forms: ■ OR: returned doc should contain at least one term from the query. ■ AND: returned doc should contain all the terms from the query. **/
import java.util.HashSet; import java.util.Vector; public class BooleanRetrievalModel implements DocSearch { // begin private class private class SkipList { // Node in skip-list
I reserved one row for first class and another for economy class. This code works just as I want but my question is how can I loop through it so I don't need all the if statements? I tried it many ways. I tried something like this but I cant get it to work.
for (int row=0;row<seat.length;row++{ for (int col=0;col<seat[row].length;col++){ if (seat[0][col]==false){ seat[0][col]=true; System.out.println("You have number 0" + row + in first class);