public void println(String x){ if(x == null){ x = "null"; } try { ensureOpen(); textOut.write(x); } catch(IOException e){ trouble = true; } newLine(); }
boolean playButton; public void playMusic(){ if (playButton){ System.out.println("Music is playing"); } else { System.out.println("Music is paused"); } }
parameter and argument
public void greeting(String location){ System.out.println("Hello, " + location); }
public int likePhoto(int currentLikes, String comment, boolean like){ System.out.println("Feedback: "+ comment); if(like){ currentLikes = currentLikes + 1; } System.out.println("Number of likes: " + currentLikes); return currentLikes; }
public double makeChange(double itemCost, double dollarsProvided){ double change = dollarsProvided - itemCost; return change; }
random number
double randomNumber = Math.random(); randomNumber = randomNumber * 10; int randomInt = (int) randomNumber;
public int rollDice(){ double randomNumber = Math.random(); randomNumber = randomNumber * 6 + 1; int randomInt = (int) randomNumber; return randomInt; }
java documentation
https://docs.oracle.com/javase/8/docs/api/java/lang/package-summary.html
Math.random()
https://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#random–