package prisoner_student_7_4;
/**
*
* @author Almer
*/
public class Prisoner_Student_7_4 {
String name;
double height;
int sentence;
public Prisoner_Student_7_4(String name, double height, int sentence) {
this.name = name;
this.height = height;
this.sentence = sentence;
}
// Zero-argument method to print all fields
public void printInfo() {
printBasicInfo();
}
// Overloaded method with a boolean argument
public void printInfo(boolean think) {
printBasicInfo();
if (think) {
think();
}
}
// Private method to print basic information
private void printBasicInfo() {
System.out.println("Name: " + name);
System.out.println("Height: " + height);
System.out.println("Sentence: " + sentence);
}
// Method to simulate thinking (placeholder)
public void think() {
System.out.println(name + " is thinking...");
}
}
package prisoner_student_7_4;
public class PrisonTest_Student_7_4 {
public static void main(String[] args){
Prisoner_Student_7_4 p01 = new Prisoner_Student_7_4("Bubba", 2.08, 4);
// Call the first version of the print method
p01.printInfo();
// Call the second version of the print method with boolean argument
p01.printInfo(true);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter