Java Usage
class Worldcup { //superclass
int wins = 0;
int losses = 0;
boolean popular = true;
String jersey_color = "blue";
public Worldcup(int wins, int losses, boolean popular, String jersey_color){
this.wins = wins;
this.losses = losses;
this.popular = popular;
this.jersey_color = jersey_color;
}
public String toString(){
return "Wins: " + this.wins + ", Losses: " + this.losses + ", Popular?: " + this.popular + ", Jersey Color: " + this.jersey_color;
}
}
public class Argentina extends Worldcup{
public Argentina(int wins, int losses, boolean popular, String jersey_color){
super(wins, losses, popular, jersey_color); // superclass constructor
}
public static void main(String[] args) {
Argentina argentina_obj = new Argentina(3,1,true,"blue");
System.out.println(argentina_obj);
}
}
public class Brazil extends Worldcup{
public Brazil(int wins, int losses, boolean popular, String jersey_color){
super(wins, losses, popular, jersey_color); // superclass constructor
}
public static void main(String[] args) {
Brazil brazil = new Brazil(7,9,true,"yellow");
System.out.println(brazil);
}
}
public class Morroco extends Worldcup{
public Morroco(int wins, int losses, boolean popular, String jersey_color){
super(wins, losses, popular, jersey_color); // superclass constructor
}
public static void main(String[] args) {
Morroco Morroco = new Morroco(2,0,false,"orange");
System.out.println(Morroco);
}
}
public class France extends Worldcup{
public France(int wins, int losses, boolean popular, String jersey_color){
super(wins, losses, popular, jersey_color); // superclass constructor
}
public static void main(String[] args) {
France France = new France(0,10,true,"red");
System.out.println(France);
}
}
public class Croatia extends Worldcup{
public Croatia(int wins, int losses, boolean popular, String jersey_color){
super(wins, losses, popular, jersey_color); // superclass constructor
}
public static void main(String[] args) {
Croatia Croatia = new Croatia(90,0,false,"dark blue");
System.out.println(Croatia);
}
}
Argentina.main(null);
Brazil.main(null);
Morroco.main(null);
France.main(null);
Croatia.main(null);
public class Person {
public String name;
public int birthday_year;
public Person (String name, int birthday_year){
this.name = name;
this.birthday_year = birthday_year;
}
public String getName(){
return name;
}
public int getAge(){
return (2022 - birthday_year);
}
public String toString(){
return "Name: " + this.name + ", Birth Year: " + this.birthday_year + ", Age: " + this.getAge();
}
}
public class Student extends Person {
private int grade;
private double gpa;
private double hours;
public Student (String name, int birthday_year, int grade, double gpa, double hours) {
super(name, birthday_year);
this.grade = grade;
this.gpa = gpa;
this.hours = hours;
}
public double hours_of_hw(double hours){
return hours;
}
public int getGrade(){
return grade;
}
@Override
public String toString() {
return "Name: " + this.name + ", birthday: " + this.birthday_year + ", grade: " + this.grade +", gpa: " + this.gpa +", hours of hw: " + this.hours;
}
}
public class Aadya extends Student{
public Aadya(String name, int birthday_year, int grade, double gpa, double hours){
super(name, birthday_year, grade, gpa, hours); // superclass constructor
getGrade();
getName();
getAge();
hours_of_hw(hours);
}
public double hours_of_hw(double hours){
return hours;
}
public static void main(String[] args) {
Aadya aadya_obj = new Aadya("Aadya", 2006, 11, 4.3, 6.5);
System.out.println(aadya_obj);
}
}
public class Teacher extends Person {
private String subject;
private int years_of_teaching;
private boolean popular;
private String college;
public Teacher (String name, int birthday_year, String subject, int years_of_teaching, boolean popular, String college) {
super(name, birthday_year);
this.subject = subject;
this.years_of_teaching = years_of_teaching;
this.popular = popular;
this.college = college;
}
public String getSubject() {
return subject;
}
public int years_of_teaching() {
return years_of_teaching;
}
// return degree
public String getCollege_name() {
return college;
}
@Override
public String toString() {
return "Name: " + this.name + ", birth year: " + this.birthday_year + ", subject: " + this.subject + ", Popular? : " + this.popular + ", Years of Teaching :" + this. years_of_teaching + ", College Name :" + this.college;
}
}
public class Liao extends Teacher{
public Liao(String name, int birthday_year, String subject, int years_of_teaching, boolean popular, String college){
super(name, birthday_year, subject, years_of_teaching, popular, college); // superclass constructor
}
public static void main(String[] args){
Liao liao = new Liao("Frank Liao", 1965, "Physics", 30, true, "UCSD");
System.out.println(liao);
}
}
Aadya.main(null);
Liao.main(null);