Explanation of Solution
Program:
File name: “Team.java”
//Define a class named Team
public class Team
{
//Declare the private variables
private String name;
private String sport;
private String mascot;
//Initialize a final static variable
public final static String MOTTO = "Sportsmanship!";
//Define a Team method
public Team(String name, String sport, String mascot)
{
//Refers to the instance variables
this.name = name;
this.sport = sport;
this.mascot = mascot;
}
//Define a get method to display the name
public String getName()
{
//Return the value
return name;
}
//Define a get method to display the sport
public String getSport()
{
//Return the value
return sport;
}
//Define a get method to display the mascot
public String getMascot()
{
//Return the value
return mascot;
}
}
File name: “Game.java”
//Define a class named Game
public class Game
{
//Declare the private variables
private Team team1;
private Team team2;
private String time;
//Define a Game method
public Game(Team t1, Team t2, String time)
{
team1 = t1;
team2 = t2;
/*If the two teams in a game have the same value for the sport*/
if(t1.getSport().equals(team2.getSport()))
//Refers to the instance variables
this.time = time;
/*Else if the two teams in a game do not
have the same value for the sport*/
else
//Refers to the instance variables
this...
Trending nowThis is a popular solution!
- This is the question: In Chapter 4, you created a class named Game that included two Team objects that held data about teams participating in a game. Modify the Game class to set the game time to the message Game cancelled! if the two teams in a game do not have the same value for the sport. (In other words, a girls’ basketball team should not have a game scheduled with a boys’ tennis team.) Write a program to demonstrate a valid and an invalid game. This is the code given: public class Game { private Team team1; private Team team2; private String time; public Game(Team t1, Team t2, String time) { // your code here } public Team getTeam1() { // your code here } public Team getTeam2() { // your code here } public String getTime() { // your code here } }arrow_forwardDescriptionIn this assignment, you are required to implement an electronic programming quiz system. User can createquestions and preview the quiz.Your TaskYou are asked to write a Java program for the programming quiz system. There are two types of questions:Multiple Choice Question and Ture/False Question. User can create questions using the system; andpreview the quiz, which display all questions in the system one by one. During the preview, the user canattempt the quiz by entering his/her answers to questions. The system will then immediately check theanswer and calculate. After attempting all questions, the total score will be displayed. A sample run of theprogram is shown as below (Green text refers to user input): Please choose (c)reate a question, (p)review or (e)xit >> cEnter the type of question (MC or TF) >> MCEnter the question text >> Each primitive type in Java has a correspondingclass contained in the java.lang package. These classes are called…arrow_forwardFor your homework assignment, build a simple application for use by a local retail store. Your program should have the following classes: Item: Represents an item a customer might buy at the store. It should have two attributes: a String for the item description and a float for the price. This class should also override the __str__ method in a nicely formatted way. Customer: Represents a customer at the store. It should have three attributes: a String for the customer's name, a Boolean for the customer's preferred status, and a list of 5 indexes to hold Item objects. Include the following methods: make_purchase: accepts a String and a double as parameters to represent the name and price of an item this customer is purchasing. Create a new Item object with this info and append it to the internal list. If the customer is a preferred customer based on the Boolean attribute's value, take 10% off the total sale price. __str__: Override this method to print the customer's name and every…arrow_forward
- Instructor note: This lab is part of the assignment for this chapter. This lab uses two Java files, LabProgram.java and SimpleCar.java. The SimpleCar class has been developed and provided to you already. You don't need to change anything in that class. Your job is to use the SimpleCar class to complete the specified tasks in the main() method of LabProgram.java Given two integers that represent the miles to drive forward and the miles to drive in reverse as user inputs, create a SimpleCar object that performs the following operations: Drives input number of miles forward Drives input number of miles in reverse Honks the horn Reports car status The SimpleCar class is found in the file SimpleCar.java. Ex: If the input is: 100 4 the output is: beep beep Car has driven: 96 milesarrow_forwardI need help writing a program for this on pythonarrow_forwardApologize for the miscommunication, The language is in Python Create a simple empty Vehicle class. Update the Vehicle class with two instance variables maximum speed and mileage of the car. Create a class variable of the manufacturer and initialize all class and instance variables. different objects among them two are from one manufacturer and the remaining two are from another manufacturer. Write two methods in the class Vehicle, one for displaying the seating capacity of the vehicle and another one is for calculating fuel used by the car by the equation: Maximum Distance Covered / Mileage of the car. and Display the result from the method. Create two children from the Vehicle class: Bus and Car. Both the child classes will inherit all the variables and methods of the Vehicle class. The car class will modify the members of the parent class in their own way and display it from its class object. Bus will be inherited to another class called MiniBus. Create a new method in…arrow_forward
- Design a class named CustomerRecord that holds a customer number, name, and address. Include separate methods to 'set' the value for each data field using the parameter being passed. Include separate methods to 'get' the value for each data field, i.e. "return" the field's value. Pseudocode:arrow_forwardThis code is in java. Transportation Program Main file called transportation. It will create the sedan and coupe objects. You will pass in parameters for the number of exterior and interior color options. It will print a message from the car class that prints All cars have Wheels: #of wheels. ; Interior Color Options: # of interior colors ; Exterior Color Options: # of colors. A message from the sedan and the coupe classes that print the number of doors and cylinders. The car class is the parent class. It will have a constructor for the number of wheels (4), exterior colors (5), and interior colors (2). It will also have a method that prints the text. The sedan and coupe classes will be children classes to the car class. They will have a constructor that calls the car’s constructor and adds in variables for the number of doors and number of cylinders. sedans have 4 doors and 6 cylinder engines. coupes have 2 doors and 4 cylinder engines. The sedan and coupe classes will…arrow_forward3- Create a class named Player with a default name as "player", a default level as 0, and a default class type of "fighter". Feel free to add any other attributes you wish! Create an instance method in the Player class called attack that takes another player as a parameter. This function should compare the level of the two players, and return whether the player won, lost, or tied. Finally create a loop that allows the user to input a name and a class type for two players; the level of both players should be determined at random (between 1 and 99). Print out the name and attributes of each player, and have the first player attack the second. Print whether the player won, lost, or tied. Ask if the user wants to try again. (Python code)arrow_forward
- Create a class Rectangle. The class has attribute length and width, each of which defaults to 1. It has methods that calculate the perimeter and area of the rectangle. It has set and get methods for both length and width. The set method should verify that length and width are each floating-point numbers larger than 0.0 and less than 20.0. Write a program to test class Rectanglearrow_forwardCreate a class called Distance that has two data member feet as int type and inches as float type. Provide multiple constructors for the Distance class. One constructor should initialize this data to 0, and another should initialize it to fixed values. Also provide copy constructor to initialize Distance object with another object. Also provide get and set method for the class.arrow_forwardCreate a class called Name that represents a person's name. The class should have fields representing the person's first name, last name, and middle initial. (Your class should contain only fields for now.)arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage