Hi, I have a question involving me to write a program asking user to input the number of small and big bricks, as well as the intended result of the brick wall's length. The program will then return true or false if the wall length is possible
For example, if user input 3 small bricks and 2 big bricks, the following results input by user should return true. Otherwise, it will return false.
Results that return true: 1,2,3,5,6,7,8,10,11,12,13
Here is the code
The above logic is somewhat wrong or missing something. For example, if I input 3 for small bricks, 5 for big bricks and the results as 23, the program returns false but it should be true...Code:package program1;
import java.util.*;
import java.io.*;
import java.text.*;
import java.lang.*;
public class Program1 {
public int small, big, goal;
public boolean result;
/**
* @param args the command line arguments
*/
public int getSmall() {
return this.small;
}
public void setSmall(int smallBricks) {
small = smallBricks;
}
public int getBig() {
return this.big;
}
public void setBig(int bigBricks) {
big = bigBricks;
}
public int getGoal() {
return this.goal;
}
public void setGoal(int goalBricks) {
goal = goalBricks;
}
public boolean getResult() {
return this.result;
}
public void setResult(boolean resultCheck) {
result = resultCheck;
}
public static void main(String[] args) {
Program1 program = new Program1();
Scanner keyboard;
keyboard = new Scanner(System.in);
System.out.println("Please input number of small bricks:");
program.setSmall(keyboard.nextInt());
System.out.println("Please input number of big bricks:");
program.setBig(keyboard.nextInt());
System.out.println("Please input number of goal bricks:");
program.setGoal(keyboard.nextInt());
program.makeBricks(program.getSmall(), program.getBig(), program.getGoal());
System.out.println("makeBricks(" + program.getSmall() + ", " + program.getBig() + ", "
+ program.getGoal() +") ? " + program.getResult());
}
public void makeBricks(int small, int big, int goal) {
int newSmall = small * 1;
int newBig = big * 5;
if ((goal <= newSmall) || (goal % newBig == 0) || (goal % (newSmall + newBig) == 0)) {
setResult(true);
}
else {
setResult(false);
}
}
}
I am not sure what is wrong here...