Question: * code for a class of Monopoly squares class Square { private String name; / / the name of the square private String type; /

* code for a class of Monopoly squares
class Square {
private String name; // the name of the square
private String type; // property, railroad, utility, plain, tax, or toJail
private int price; // cost to buy the square; zero means not for sale
private int rent; // rent paid by a player who lands on the square
private String color; // many are null; this is not the Java Color class
// constructors
public BoardSquare()
{
name ="";
type ="";
price =0;
rent =0;
color ="";
}// end BoardSquare()
public BoardSquare(String name, String type, int price, int rent, String color)
{
this.name = name;
this.type = type;
this.price = price;
this.rent = rent;
this.color = color;
}// end BoardSquare(String name, String type, int price, int rent, String color)
// accesors for each property
public String getName()
{
return name;
}//end getName()
public String getType()
{
return type;
}//end getType()
public int getPrice()
{
return price;
}//end getPrice()
public int getRent()
{
return rent;
}//end getRent()
public String getColor()
{
return color;
}//end getColor()
// a method to return the BoardSquare's data as a String
public String toString()
{
String info =(name +","+type+","+price +","+ rent+","+color);
return info;
}//end toString()
}// end class BoardSquare
/* This code creates an array named square[] of 40 BoardSquare objects
* for a Monopoly game, then reads data from a file into the properties
* of each object in the array.
*
* The code can be added to an appropriate method.
*/
BoardSquare[] square = new BoardSquare[40]; // array of 40 monopoly squares
int i; // a loop counter
// declare temporary variables to hold BoardSquare properties read from a file
String inName;
String inType;
int inPrice;
int inRent;
String inColor;
// Create a File class object linked to the name of the file to be read
java.io.File squareFile = new java.io.File("squares.txt");
// Create a Scanner named infile to read the input stream from the file
Scanner infile = new Scanner(squareFile);
/* This loop reads data into the square array.
* Each item of data is a separate line in the file.
* There are 40 sets of data for the 40 squares.
*/
for( i=0; i<40; i++)
{
// read data from the file into temporary variables
// read Strings directly; parse integers
inName = infile.nextLine();
inType = infile.nextLine();
inPrice = Integer.parseInt( infile.nextLine());
inRent = Integer.parseInt( infile.nextLine());;
inColor = infile.nextLine();
// intialze each square using the BoardSquare constructor
square[i]= new BoardSquare(inName, inType, inPrice, inRent, inColor);
}// end for
infile.close();
}// main()
Section 4 of chapter 9 of the supplement textbook describes the BoardSquare class, a class representing a collection of objects for squares on a monopoly board. The Intellij project Monopoly included with the files for this chapter, has that class and a public class named Monopoly with an executable main method.
Your task ultimately will be to complete the programming exercise at the end of chapter 9 by adding a player class object to the program. Integrating the Player Class into the starter code for a Monopoly Game will be a requirement in a later assignment.
1. The first stage is to first create an Abstract Class named Person. The Person Class should have some basic properties such as person's name and person's age.
2. The second stage is to derive the Player Class from the Abstract Class Person. Create a user defined class named player that at a minimum contains all of the properties and methods described in the included class diagram. You may expand or modify the design provided to your version of what a player class is and what a player can do. The Player Class should have some basic properties for a player in a game such as players character name, players score or monetary balance, and players current position or location in the game.
3. The Third Stage is to create an Interface Class for the Player Class. The Interface Class should have at least one abstract method. This abstract method should be an action such as Role Dice, Take Turn, or Traverse Terrain. The Player Class must implement at least one User Defined Interface.
4. Use the main method of the project to instantiate two instances of the Player Class.
5. Use local variables or data literals in your main method to test the two instances of the Player class. Use them to instantiated the instances and to invoke and test the methods of your Player class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!