[Solved] Producing a Java program for other systems

You can pack your application in a .jar, actually a zip file with inside .class files and resource files. Those resource files, like your images, can be taken with getClass().getResource(“path/x.png”) or getResourceAsStream. The path is either package relative or absolute: “/abc/def.jpg”. These resources must be read-only (as they are inside the .jar). However you may … Read more

[Solved] setAdapter not recognize in android studio [duplicate]

Replace ViewPager.setAdapter(… with viewPager.setAdapter(… ViewPager (with a capital letter) is a class name and by using it here, you are trying to access the static method of that class. There is no static method setAdapter and hence the error. For readability, replace viewPager with pager. It will make it easier for you to avoid such … Read more

[Solved] Can i porposely corrupt a file through Java programming ? Also is it possible to scramble a file contents ?

A simple RandomAccessFile scrambler would be this: private static final String READ_WRITE = “rw”; private static final Random random = new Random(); public static void scramble(String filePath, int scrambledByteCount) throws IOException{ RandomAccessFile file = new RandomAccessFile(filePath, READ_WRITE); long fileLength = file.getLength(); for(int count = 0; count < scrambledByteCount; count++) { long nextPosition = random.nextLong(fileLength-1); file.seek(nextPosition); … Read more

[Solved] A class inside of a class [closed]

Yes you can do that but it would be better if you make the Males and Females into different classes and just inherit from the Human class. class Human: def __init__(self, height, weight): self.height = height self.weight = weight class Male(Human): def __init__(self, name): Human.__init__(self, height, weight) # This will inherit every attribute of the … Read more

[Solved] Please help me with this recursive function

Since it’s recursive and the recursive call comes before your printline, it will recursively call itself over and over until it reaches the base case. Only first after the recursive calls have ended will your print be allowed to execute. Something like this Do something first recursive call Do something second recursive call Do something … Read more

[Solved] How to add for loops to if statements?

here you go: public static void main(String… args) { String[] verifiedNames = { “barry”, “matty”, “olly”, “joey” }; System.out.println(“choose an option”); System.out.println(“Uselift(1)”); System.out.println(“see audit report(2)”); System.out.println(“Exit Lift(3)”); Scanner scanner = new Scanner(System.in); int choice = scanner.nextInt(); switch (choice) { case 1: scanner.nextLine(); // get ‘\n’ symbol from previous input int nameAttemptsLeft = 3; while (nameAttemptsLeft– … Read more

[Solved] Object comparison using == operator in Java

You are right about the fact that == compares the references of the two variables, but, references are not the same as hash codes. Hash codes are numbers returned by this method that you’ve written: @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + … Read more