Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Team Constructor | Classes
Java Extended

book
Challenge: Team Constructor

Tarea
test

Swipe to show code editor

Here is a class called Team written for you. Your task is to write a constructor that takes all 4 parameters and initializes all 4 fields. Please do not modify the Main class and its methods.

  1. Write a constructor with 4 parameters: name, sport, yearFounded, and city.
  2. Initialize the name field with the value of the name parameter.
  3. Initialize the sport field with the value of the sport parameter.
  4. Initialize the yearFounded field with the value of the yearFounded parameter.
  5. Initialize the city field with the value of the city parameter.

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 4. Capítulo 7
package com.example;

class Team {
String name;
String sport;
int yearFounded;
String city;

public ___(___, ___, ___, ___) {
___ = ___;
___ = ___;
___ = ___;
___ = ___;
}

public void displayTeamInfo() {
System.out.println("Team: " + name);
System.out.println("Sport: " + sport);
System.out.println("Year Founded: " + yearFounded);
System.out.println("City: " + city);
}
}

public class Main {
public static void main(String[] args) {
Team team = new Team("Lakers", "Basketball", 1947, "Los Angeles");
team.displayTeamInfo();
toggle bottom row
We use cookies to make your experience better!
some-alt