Passing A Boolean Parameter From One Method To Other
Jan 30, 2015
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.
View Replies
ADVERTISEMENT
Apr 30, 2014
I'm using Java in BlueJ where I'm trying to write a class to store cycling club membership details in a map. I'm trying to pass a map as a parameter to a function that will iterate over the map and print out the member details. My code is:
public class CtcMembers
{
//instance variables
private Map<String, Set<String>> memberMap;
/**
* Constructor for objects of class CtcMembers
[Code] ....
When I execute the following in the OU workspace:
CtcMembers c = new CtcMembers();
c.addCyclists();
I can see a map populated with the expected details.
When I execute the following in the OU workspace:
c.printMap(c.getMap());
I get the following error:
java.lang.ClassCastException: java.util.HashSet cannot be cast to java.lang.String
in CtcMembers.printMap(CtcMembers.java:81)
in (OUWorkspace:1)
I wasn't aware I was trying to cast anything so this has got me baffled.
View Replies
View Related
Aug 8, 2014
i want to pass an object of type Software to assign it to a computer from Computer class...
i should note that computer and software are arrays of objects thats the variable and method to set software in Computer class
private Software[] software;
public void setSoftware(Software software,int index){
this.software[index]=software;}
note: the user choses the a computer from a list and a software as will
for example the program will show the user 2 computers
0 for computer: apple, Model: mac mini, Speed: 2.8
1 for computer: sony, Model: vaio, Speed: 2.2
the user enters the index he wants then the program will show a list of software to add to the computer selected
the error I'm having is run time error Exception in thread "main" java.lang.NullPointerException and it points to these 2 lines
1.comp[Cch].setSoftware(software,Sch);
2. the method setSoftware
every thing is running correctly but this step above
Cch= the chosen computer index
Sch= the chosen Software index
why am i getting an error and how to fix it?
View Replies
View Related
Oct 15, 2014
I'm asking if there is a way to pass parameter between try/catch block.
I have a method:
public void invia(OiStorto invioaca) throws Exception {
Long id=0L;
try {
//some code
for (VElenpere elenpere : elenperes) {
[Code] ...
The method called in the for:
private void popolaScompiute(Long anno, InviaEOI inviaEOI0, _4IntegerType param, ElOpeIncType opereIncompiute,
VElencoOpere elencoOpere,Long id) {
try {
//some code
for (OiOpera opere : oiOpere){
[Code] ....
And finally the method in which the error can occur (the method poputa is called for every id)
private void poputa(ElOpeIncType opereIncompiute, OpeIncType operaSingola, OiOpera opere) {
try {
//some code
} catch (NullPointerException e) {
e.printStackTrace();
//return id;
}
So method invia call the method popolaScompiute, inside popolaScompiute there is an iteration through some id and for some id can occur an error; what i want is the getting the value of id in the first method invia, using the block try/catch. Is there a way to accomplish this?
View Replies
View Related
May 14, 2014
I am trying to run an example in which I pass a parameter to imported file but its not working.
This is my header.jspf file which I will include in a jsp file.
<img >
<br>${param.sub}
And This is the JSP file contact.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
<c:import url="header.jspf">
<c:param name="sub" value="We love to hear from our clients------------" />
</c:import>
<br><br>
Now this is JSP page content
</body>
</html>
When I hit the contact.jsp file , It does show me the image I have on header.jspf , but its not able to print the parameter that I am setting in <c:param>
So after showing image it just shows ${param.sub}. So EL is not translated properly.
View Replies
View Related
Mar 8, 2015
I have an object that has an instance of another object class as its parameter :
CombinationLock oneHundred = new CombinationLock(28,17,39);
Locker Mickey = new Locker(100, "Mickey", 3, oneHundred);
This is for a locker, which has a combination assigned to the student. Within the locker class I have the following constructor:
public Locker(int locker, String student, int numberOfBooks, CombinationLock combo) {
this.locker = locker;
this.combo = combo;
this.student = student;
this.numberOfBooks = numberOfBooks;
}
combo is the private CombinationLocker object I created within the Locker class. Do I need to pass the combo object on to the CombinationLock class? For reason, I do not comprehend, the combination password from the main class is not passing through to the CombinationLock class, and the combination values are all zero.
View Replies
View Related
Feb 23, 2014
I am trying to make a class definition file for an ASCII File.
Ultimately, I want to be able to add methods to allow the image produced by the file to be printed normally, then printed with various manipulations.
However, for some reason, whenever I try to run the program to test my normalPrint method, it terminates without printing anything.
I think this is because the array's values width and height are not within the scope of the method. I tried passing the array as a parameter for the method like so:
Java Code:
public void normalPrint(char [][] poop){
//method here
} mh_sh_highlight_all('java');
But it gave me an error that stated
"The method normalPrint(char[][]) in the type asciiFile is not applicable for the arguments ()"
Class Definition:
Java Code:
import java.io.*;
import java.util.Scanner;
public class asciiFile {
int height;
int width;
[Code] .....
View Replies
View Related
Mar 5, 2014
Which method is used while passing or returning a java object from the native method?
View Replies
View Related
Dec 1, 2014
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;
[code]....
View Replies
View Related
Feb 18, 2014
I have been writing test scripts for my class but I'm stuck on this method. how do i test for an object?
@Override
public boolean equals(Object obj) {
if (obj.getClass() != Fraction.class)
return false;
return (this.toString().equals(obj.toString()));
}
View Replies
View Related
Jul 20, 2014
I was following a tutorial for libGdx and suddenly became confused by the following syntax:
up.addListener(new ClickListener(){
public void clicked(InputEvent event, float x, float y){
position.y += 1f;
//currentFrame = animation.getKeyFrame(12);
}
});
"up" is basically a text Button:
TextButton up = new TextButton("up", textButtonStyle);
and .addListener is just one of the methods "TextButton" has (actually I think its inherited from "Button" but that doesn't matter).
Basically my question is what's going on inside the parentheses? From what I see its a new instance of "ClickListener" but then suddenly they override an actual method within. Is this simply just a way to override a method from the ClickListener class or is it something else?
View Replies
View Related
Sep 20, 2014
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.
View Replies
View Related
Feb 12, 2015
Why is the logic not correct with the method public static boolean containsColor(String color, Circle [] ca)? It only returns me only false values.
Java Code: public class Circle {
private double radius;
private String color;
public Circle()
{
radius = 1;
color = "red";
[code]....
View Replies
View Related
Jun 28, 2014
Write a static method odd() that takes three boolean inputs and returns true if an odd number of inputs are true, and false otherwise.
View Replies
View Related
May 21, 2014
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 ....
View Replies
View Related
May 8, 2014
Does the following code pass a value into a method?
/code
lnValue[x][y] = computelnValue();
View Replies
View Related
Jan 2, 2014
So, I am learning Swing, and Swing Layouts. I just came across a really confusing (for me) line of code.
Java Code:
setLayout(new BorderLayout()); mh_sh_highlight_all('java');
So, this is weird for me because I don't really understand why the BorderLayout class constructor is being initialized as a parameter for the setLayout..
View Replies
View Related
Jan 3, 2015
I have a method that accepts as a parameter an object:
public void addClient(Client c){ }
Client is a class which has a constructor that has two String parameters:
public Cliente (String name, String lastname){
this.name = name;
this.lastname = lastname;
}
In the main add a Client in this way:
addClient(new Cliente("first", "second"));
Now, i have an array of Client, so I would like to enter within this. Example:
public void addClient(Client c){
for (int i = 0; i<client.length ; i++) { // client is an array of Client object
client[i] = c; // Enter a c in the array, but does not work!
System.out.println("test "+clienti[i]); // print Client@15db9743
}
}
I have used the println for check if worked insertion, but the result shows no
View Replies
View Related
Jan 15, 2014
how is cast a class at a methods parameters? i have a problems in a methods paramter. i draw red line my exception and mymethods is orage color ....
Caffe drink = new Caffe();
CoffeCup cup = new CoffeCup();
cup.setTempeture(100);
drink.drinkcaffe((CaffeCup)(cup.getTempeture()));
[code]....
View Replies
View Related
Jul 1, 2013
I was going through some lectures online and found that to compare or even swap, the use of comparable or comparator argument like
public static boolean less(Comparable v,Comparable w)
{
return v.compareTo(w)<0;
}
public static void swap(Comparable []a,int i,int j)
{
Comparable swap=a[i];
a[i]=a[j];
a[j]=swap;
}
I did not get the use of passing Comparable or Comparator to the function as parameters. Object as parameter could have been used too?
View Replies
View Related
Nov 3, 2014
Can we pass more than one array in a method?
View Replies
View Related
Jul 31, 2014
I have the following method:
public static void doSomething(List<? extends GenericClass> input)
{
// op
}
^
This compiles and works, ensuring I can only pass in a List of a type extending GenericClass.But now I want it to accept an Array instead of List. This is where I'm stuck:
public static void doSomething(<? extends GenericClass>[] input)
{
// op
}
^
A wrong guess at the syntax which does not compile. One solution is to convert Array into ArrayList before calling the 1st method above, but I'd rather bypass this if possible.
View Replies
View Related
Apr 28, 2015
I have a drop-down which contains the four sections simple buttons(filters). When click any of these buttons some settings are applied. I have successfully auotmated it using simple if else and switch but in that case i have to use 8 parameters(8 are the number of button)
public void editFilters(WebElement filter1, WebElement filter2, WebElement filter3, WebElement filter4,WebElement filter5,WebElement filter6,WebElement filter7,WebElement filter8 String edit, String expectedColour) {
switch (edit) {
case "selectFilter":
if (filter1 != null) {
[Code] .....
But want to make it more effective by using hashes. I do not want to use 8 different parameters to perform action on the respective button.
So now what i want to implement.
Create a method in which i pass the parameter1 as hash and 2nd parameter as 0 or 1, 0 means unSelectFilter and 1 means select the filter.
With parameter 1, in code i want to pass the name or xpath or anything else for any number of filters , that those filters names should be stored into that hash and then by passing 0 or 1, i can select/unselect those filters.
View Replies
View Related
May 5, 2014
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;
[Code] ...
View Replies
View Related
Feb 28, 2014
Passing Information to a Method or a Constructor
They show a line of code that goes like this:
public Polygon polygonFrom(Point[] corners) {
// method body goes here
}
So from what I understand this is a constructor method for a Polygon object from the Polygon class. What I dont get is the name of the method polygonFrom()
Shouldn't a constructor for a Polygon just have the same name as the class? Because from earlier examples in the tutorial it seems to me that this is what has been done
For example:
public Bicycle(int startCadence, int startSpeed, int startGear) {
gear = startGear;
cadence = startCadence;
speed = startSpeed;
}
View Replies
View Related
Oct 29, 2014
I am working on an independent project it is a simple little text based rpg that will run in a counsel window. I have an object for Character that is creating during a CreateCharacter method. I want the play to be able to enter a character that will open up a menu that displays things like the name and health and stuff of the character from the object created in CreateCharacter, but because I have it in a different class I don't know how to reference the object made in CreateCharacter.
I have it in 6 files
Character --- Object with getters/setters for things like name, age, race, class, ect
MainMenu --- Displays title and promts for new game and quit
CreateCharacter --- Walks through and sets all values in Character
Stats --- Keeps the players stats (health, attack, ect) in an array
Intro --- Beginning demo thing (not really important for this question)
Menu --- Displays all current user stats (Having issues with this one)
Example I have this in Menu
System.out.println("Name: " + ????.getName());
View Replies
View Related