Win a copy of Securing DevOps this week in the Security forum!

James Palmer

Ranch Hand
+ Follow
since Mar 15, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by James Palmer

For example i want to use 3 values,e.g 24, 35 and 55.I want a total value of 290.I would want the computer to make all the calculations needed with all the ways that they could be done using all 3 values or only one of them to find the closest value to 290.One of them could be 24 + 35 + 55 + 24 + 24 + 55 + 35 + 35 = 287. After this the value we get is not as close to 290 as the value we have now.I hope this has made it a bit clearer.Thanks

P.S:The combination i have made is only one of the so many that can be done with those 3 numbers.
[ August 03, 2004: Message edited by: James Palmer ]
13 years ago
Hello, am making a program and my main problem is that i ve got some numbers(about 20) which are standard values,not changing. I also have a total sum.That total sum is the number that i want to get to.How i get there is that i get 3-4 from the 20 values i have and put out all possible combinations to get to the target number as close as possible using as many digits as needed. The digit combination closer to the total mass target is our wanted combination.For example, if I have the letters P, Y and T, the program would start working out all possible combinations to get to the target number as close as possible using as many digits as needed. The digit combination closer to the total mass target is our wanted combination.We want the sum of the numbers put together.Any idea how this can be done?As i dont know the number of digits i will need this makes the program harder to make(or so i think so).Ideally, you could point to me with what parts of java i would want to do this program and i could learn to do it myself...Thanks a lot for your patience in reading this!
13 years ago
Hello
Basically my problem is i have two arrays,numbers(from 1 to 10) and persons. For each person there is an individual number and as both arrays already have their variables i want to put the numbers in descending order.The problem is that by sorting the numbers,i dont know how to sort the names at the same time to stick with their individual numbers.For example:
String[] names = {John, Andy};
int[] scores = {7,3};

By sorting the scores here they will become {3,7} so the 3 will be the first element of the array and it will go with John instead of Andy,which is what i would wish to do.Any ideas?Thanks
13 years ago
basically what i dont understand is that i get a number from the setNumber1 method and then in the main method i call the getNumber1() method which i thought would call the setNumber1 method to get the number itself.How am i supposed to call the setnumber method from the getnumber method in order to get a random number correctly instead of always getting a 0?
13 years ago
It gives me an error "cannot resolve symbol: max" .And why do i need to use that max?thanks
13 years ago
aha...sorry this is my first program with object oriented so am not very familiar with this...I thought by using:
public void setNumber1(int n1) {
n1 = (int) (Math.random() * 100);
number1 = n1;
}

that i had set number1 to a number but as it seems it does not happen.Then by calling getNumber1 it would get the number from number1.What am i doing wrong?
13 years ago
erm...sorry...i ve put it down the way you wrote and it still only gives me 0.Am gonna put the whole code down to see if you can find the error.Thanks(again)
public class MathsTest {

private int number1;
private int number2;
private int answer;

public MathsTest() {
number1 = 0;
number2 = 0;
answer = 0;
}

public void setNumber1(int n1) {
n1 = (int) (Math.random() * 100);
number1 = n1;
}

public void setNumber2(int n2) {
n2 = (int) (Math.random() * 100);
number2 = n2;
}

public int getAnswer() {
int a = (number1 + number2);
answer = a;
return answer;
}

public int getNumber1() {
return number1;
}

public int getNumber2() {
return number2;
}
}

import sheffield.*;

public class Maths1 {
public static void main (String[] args) {

String name;
int answer1;
EasyReader keyboard = new EasyReader();
System.out.println("What is your name?");
name = keyboard.readString();
System.out.println("Hello " + name);

MathsTest m = new MathsTest();
int total_correct_answers = 0;
for (int q = 1; q <= 10; q++) {
System.out.print("What is the sum of");
System.out.println(m.getNumber1() + "+" + m.getNumber2());
answer1 = keyboard.readInt();
if (answer1 == m.getAnswer()) {
System.out.println("Well done.Its the correct answer!");
total_correct_answers = (total_correct_answers + 1);
}
else {
System.out.println("Sorry.Wrong answer.The correct answer is " + m.getAnswer());
}
}
System.out.println("You got " + total_correct_answers + "out of 10");
}
}
13 years ago
sorry but i am not making sense...Could you please type the correct code?Thanks
13 years ago
could you just explain this a bit for me please?I ve given you quite a hard time but thanks a lot for your help!
13 years ago
Here it is:

public void setNumber1(int n1) {
n1 = (int) Math.random() * 100;
number1 = n1;
}

public void setNumber2(int n2) {
n2 = (int) Math.random() * 100;
number2 = n2;
}

public int getAnswer() {
int a = (number1 + number2);
answer = a;
return answer;
}
Cheers again for the help
13 years ago
erm,for some reason the only number it gives me is 0.I have this program which asks people what the sum is(like 5+3) and i wanted the numbers to come up in random.I have 10 quesitons and all it does is ask 10 times the sum of 0+0 so dont know whats the problem.Can someone help?Thanks
13 years ago
Hello,i have this method in a class:
public int getAnswer(int a) {
a = (number1 + number2);
answer = a;
return answer;
}


I use it in my main method and it gives the error message:
getAnswer(int) in class cannot be applied to ().
Any ideas?Thanks
13 years ago
Could you explain how this works?
int x = (int) (Math.random() * 20);
Thanks
13 years ago
Hello,i ve made a class with a method to get integer random numbers.I used the Math.random class first to get a random number obviously and then the Math.ceil class to make the double number an integer.When i compile it it gives me an error "possible loss of precision".Found double,required int
My code is:

----------------------------------------------
private int number1;
public void setNumber1(int n1) {
n1 = Math.ceil(Math.random());
number1 = n1;
}

----------------------------------------------
Is there a better way to get a random number or how do i sort out this problem?Also,if i want to get only random numbers below 20(or any number) how can i do that?Any help will be really appreciated.Thanks
13 years ago
Hello, basically i have a text field and a JEditorPane.What i want is to input an address in the text field and make the web page come up in the JEditorPane.I have this code so far(tfAddress is the variable name for the textfield).
tfAddress.addActionListener(new ActionListener()) {
public void ActionPerformed(ActionEvent ae){ //does something when enter is pressed
field.getText()
}
}
How can i make the JEditorPane display the page?(you can probably understand that am not very good with java yet as this is probably a bit of a silly question)
Thanks to everyone who helps with this.
13 years ago