Popcorn Hack
class Book {
String title;
int pages;
Book(String title, int pages) {
this.title = title;
this.pages = pages;
}
void printInfo() {
System.out.printf("The book is %s and it is %d pages long", title, pages);
}
}
Book book = new Book("The Return of the King", 452);
book.printInfo();
The book is The Return of the King and it is 452 pages long
Homework Hack
class Student {
String name;
int pets;
int siblings;
char sex;
String race;
Student(String name, int pets, int siblings, char sex, String race) {
this.name = name;
this.pets = pets;
this.siblings = siblings;
this.sex = sex;
this.race = race;
}
}
public class Main {
public static void main(String[] args) {
Student student1 = new Student("Joseph", 1, 2, 'm', "Irish");
Student student2 = new Student("Jill", 0, 1, 'f', "Irish");
Student student3 = new Student("Sam", 0, 0, 'm', "African");
System.out.println(student1.name);
System.out.println(student2.name);
System.out.println(student3.name);
}
}
Main.main(null);