serializing an object in C# - c#

I have a serializable class named DataSource:
namespace GraphLib
{
public struct cPoint
{
public float x;
public float y;
}
[Serializable]
public class DataSource
{
public delegate String OnDrawXAxisLabelEvent(DataSource src, int idx);
public delegate String OnDrawYAxisLabelEvent(DataSource src, float value);
public OnDrawXAxisLabelEvent OnRenderXAxisLabel = null;
public OnDrawYAxisLabelEvent OnRenderYAxisLabel = null;
private cPoint[] samples = null;
private int length = 0;
private String name = String.Empty;
private int downSample = 1;
private Color color = Color.Black;
public float VisibleDataRange_X = 0;
public float DY = 0;
public float YD0 = -200;
public float YD1 = 200;
public float Cur_YD0 = -200;
public float Cur_YD1 = 200;
public float grid_distance_y = 200; // grid distance in units ( draw a horizontal line every 200 units )
public float off_Y = 0;
public float grid_off_y = 0;
public bool yFlip = true;
public bool Active = true;
private bool YAutoScaleGraph = false;
private bool XAutoScaleGraph = false;
public float XAutoScaleOffset = 100;
public float CurGraphHeight = 1.0f;
public float CurGraphWidth = 1.0f;
public float InitialGraphHeight = 0;
public float InitialGraphWidth = 0;
public bool AutoScaleY
{
get
{
return YAutoScaleGraph;
}
set
{
YAutoScaleGraph = value;
}
}
public bool AutoScaleX
{
get
{
return XAutoScaleGraph;
}
set
{
XAutoScaleGraph = value;
}
}
public cPoint[] Samples
{
get
{
return samples;
}
set
{
samples = value;
length = samples.Length;
}
}
public float XMin
{
get
{
float x_min = float.MaxValue;
if (samples.Length > 0)
{
foreach (cPoint p in samples)
{
if (p.x < x_min) x_min=p.x;
}
}
return x_min;
}
}
public float XMax
{
get
{
float x_max = float.MinValue;
if (samples.Length > 0)
{
foreach (cPoint p in samples)
{
if (p.x > x_max) x_max = p.x;
}
}
return x_max;
}
}
public float YMin
{
get
{
float y_min = float.MaxValue;
if (samples.Length > 0)
{
foreach (cPoint p in samples)
{
if (p.y < y_min) y_min = p.y;
}
}
return y_min;
}
}
public float YMax
{
get
{
float y_max = float.MinValue;
if (samples.Length > 0)
{
foreach (cPoint p in samples)
{
if (p.y > y_max) y_max = p.y;
}
}
return y_max;
}
}
public void SetDisplayRangeY(float y_start, float y_end)
{
YD0 = y_start;
YD1 = y_end;
}
public void SetGridDistanceY( float grid_dist_y_units)
{
grid_distance_y = grid_dist_y_units;
}
public void SetGridOriginY( float off_y)
{
grid_off_y = off_y;
}
[Category("Properties")] // Take this out, and you will soon have problems with serialization;
[DefaultValue(typeof(string), "")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public String Name
{
get { return name; }
set { name = value; }
}
[Category("Properties")] // Take this out, and you will soon have problems with serialization;
[DefaultValue(typeof(Color), "")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public Color GraphColor
{
get { return color; }
set { color = value; }
}
[Category("Properties")] // Take this out, and you will soon have problems with serialization;
[DefaultValue(typeof(int), "0")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int Length
{
get { return length; }
set
{
length = value;
if (length != 0)
{
samples = new cPoint[length];
}
else
{
// length is 0
if (samples != null)
{
samples = null;
}
}
}
}
[Category("Properties")] // Take this out, and you will soon have problems with serialization;
[DefaultValue(typeof(int), "1")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public int Downsampling
{
get { return downSample; }
set { downSample = value; }
}
}
}
and i want to serialize it in a form like this:
public partial class Form1 : Form
{
public GraphLib.PlotterDisplayEx display;
private void serialize()
{
System.IO.Stream TestFileStream = System.IO.File.Create(#"C:\Users\Public\Documents\test.txt");
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter serializer = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
serializer.Serialize(TestFileStream, display.DataSources[0]);
TestFileStream.Close();
}
not that DataSource class that i want to serialize in Form1, is one of the attributes in GraphLib.PlotterDisplayEx class
but when i run the program it gives me the following error:
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: Type 'KTK.Form1' in Assembly 'KTK, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
UPDATE
I updated the code for DataSource class.now it's complete code guys.

You probably didn't show the complete code of the DataSource class. It directly or indirectly holds a reference to an object of type KTK.Form1.
This might be through an event to which the form is subscribed.
In this case you probably don't want to serialize it an should mark it as NonSerialized:
[field:NonSerialized]
public event ...;
Now that you updated the question. Change
public OnDrawXAxisLabelEvent OnRenderXAxisLabel = null;
public OnDrawYAxisLabelEvent OnRenderYAxisLabel = null;
to
[NonSerialized]
public OnDrawXAxisLabelEvent OnRenderXAxisLabel;
[NonSerialized]
public OnDrawYAxisLabelEvent OnRenderYAxisLabel;
The delegates may hold references to non-serializable classes.

Related

Farming game in C# cant fix level system

I am making a Farming game in Unity and I tried to implement an EXP System. I can not implement a function where you can plant a crop from an X player level.
This Code manages the whole farm
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FarmManager : MonoBehaviour
{
[Header("Money Settings")]
public PlantItem selectPlant;
public bool isPlanting = false;
public int money = 100;
public Text moneyTxt;
[Header("Button Color Settings")]
public Color buyColor = Color.green;
public Color cancelColor = Color.red;
public Color lockedColor = Color.grey;
[Header("Button Audio Settings")]
public AudioSource clickSound;
[Header("Cursor Settings")]
public Texture2D cursorArrow;
public Texture2D cursorPickaxe;
[Header("XP Settings")]
public int maxExp;
public float updatedExp;
public float plusXp;
public Image ExpBar;
public float expIncreasedPerSecond;
public int playerLevel;
public Text levelText;
public Text xpLevel;
// Start is called before the first frame update
void Start()
{
Cursor.SetCursor(cursorArrow, Vector2.zero, CursorMode.ForceSoftware);
moneyTxt.text = "$"+money;
playerLevel =1;
expIncreasedPerSecond =5f;
maxExp = 25;
updatedExp = 0;
plusXp = 0;
}
void Update () {
//updatedExp += expIncreasedPerSecond * Time.deltaTime;
ExpBar.fillAmount = updatedExp / maxExp;
levelText.text = playerLevel + "";
xpLevel.text = updatedExp + "/" + maxExp;
if (updatedExp >= maxExp)
{
plusXp = updatedExp-maxExp;
playerLevel++;
updatedExp=0+plusXp;
maxExp+=maxExp;
}
}
public void SelectPlant(PlantItem newPlant)
{
if(selectPlant == newPlant)
{
Debug.Log("Deselected" + selectPlant.plant.plantName);
selectPlant.btnImage.color = buyColor;
selectPlant.btnTxt.text = "Buy";
selectPlant = null;
isPlanting = false;
clickSound.Play();
}
else
{
if(selectPlant!=null)
{
selectPlant.btnImage.color = buyColor;
selectPlant.btnTxt.text = "Buy";
}
selectPlant = newPlant;
selectPlant.btnImage.color = cancelColor;
selectPlant.btnTxt.text = "Cancel";
Debug.Log("Selected" + selectPlant.plant.plantName);
isPlanting = true;
clickSound.Play();
}
}
public void Transaction(int value)
{
money+=value;
moneyTxt.text = "$"+money;
}
public void GiveXP (float value)
{
updatedExp += value;
}
}
And this is the code where I import the information from
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New Plant", menuName ="Plant")]
public class PlantObject : ScriptableObject
{
[Header("Plant settings")]
public string plantName;
public Sprite[] plantStages;
public float timeBtwStages;
[Header("Money Settings")]
public int buyPrice;
public int sellPrice;
[Header("XP Settings")]
public int xpAmount;
public int levelNeeded;
[Header("Plant Icon")]
public Sprite icon;
}
I tried doing it this way, but it would not fix my issue and would not disable the crop until the needed level was reached and it gave me a ton of errors.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FarmManager : MonoBehaviour
{
[Header("Money Settings")]
public PlantItem selectPlant;
public bool isPlanting = false;
public int money = 100;
public Text moneyTxt;
[Header("Button Color Settings")]
public Color buyColor = Color.green;
public Color cancelColor = Color.red;
public Color lockedColor = Color.grey;
[Header("Button Audio Settings")]
public AudioSource clickSound;
[Header("Cursor Settings")]
public Texture2D cursorArrow;
public Texture2D cursorPickaxe;
[Header("XP Settings")]
public int maxExp;
public float updatedExp;
public float plusXp;
public Image ExpBar;
public float expIncreasedPerSecond;
public int playerLevel;
public Text levelText;
public Text xpLevel;
// Start is called before the first frame update
void Start()
{
Cursor.SetCursor(cursorArrow, Vector2.zero, CursorMode.ForceSoftware);
moneyTxt.text = "$"+money;
playerLevel =1;
expIncreasedPerSecond =5f;
maxExp = 25;
updatedExp = 0;
plusXp = 0;
}
void Update () {
//updatedExp += expIncreasedPerSecond * Time.deltaTime;
ExpBar.fillAmount = updatedExp / maxExp;
levelText.text = playerLevel + "";
xpLevel.text = updatedExp + "/" + maxExp;
if (updatedExp >= maxExp)
{
plusXp = updatedExp-maxExp;
playerLevel++;
updatedExp=0+plusXp;
maxExp+=maxExp;
}
}
public void SelectPlant(PlantItem newPlant)
{
if(selectPlant == newPlant)
{
Debug.Log("Deselected" + selectPlant.plant.plantName);
selectPlant.btnImage.color = buyColor;
selectPlant.btnTxt.text = "Buy";
selectPlant = null;
isPlanting = false;
clickSound.Play();
}
else
{
if(selectPlant!=null)
{
selectPlant.btnImage.color = buyColor;
selectPlant.btnTxt.text = "Buy";
}
selectPlant = newPlant;
selectPlant.btnImage.color = cancelColor;
selectPlant.btnTxt.text = "Cancel";
Debug.Log("Selected" + selectPlant.plant.plantName);
isPlanting = true;
clickSound.Play();
}
if (selectPlant.plant.levelNeeded > playerLevel)
{
selectPlant.btnImage.color = lockedColor;
}
}
public void Transaction(int value)
{
money+=value;
moneyTxt.text = "$"+money;
}
public void GiveXP (float value)
{
updatedExp += value;
}
}
I have been stuck on this for weeks now any ideas?

how do i change the value of an object

here is my main method:
string input = Console.ReadLine(); // 2006 2000 false 1000 500 Windows
List<string> inputs = input.Split(" ").ToList();
Computer one = new Computer(int.Parse(inputs[0]), int.Parse(inputs[1]), bool.Parse(inputs[2]), double.Parse(inputs[3]), double.Parse(inputs[4]), inputs[5]);
one.Print(); // 2006, 2000, false, 1000, 500, Windows
input = Console.ReadLine(); //changeOperatingSystem
if (input == "changeOperatingSystem")
{
string newOperationSystem = Console.ReadLine(); //Linux
Computer two = new Computer(newOperationSystem);
}
one.Print(); //2006, 2000, false, 1000, 500, Linux
the "//" marks what the input and the output look like.
This is my Computer.cs:
private int years;
private int price;
private bool isNotebook;
private double hardDiskMemory;
private double freeMemory;
private string operationSystem;
private string newOperationSystem;
public Computer(int years, int price, bool isNotebook, double hardDiskMemory, double freeMemory, string operationSystem)
{
Years = years;
Price = price;
IsNotebook = isNotebook;
HardDiskMemory = hardDiskMemory;
FreeMemory = freeMemory;
OperationSystem = operationSystem;
}
public Computer(string newOperationSystem)
{
OperationSystem = newOperationSystem;
}
public int Years
{
get { return years; }
set
{
years = value;
}
}
public int Price
{
get { return price; }
set
{
price = value;
}
}
public bool IsNotebook
{
get { return isNotebook; }
set
{
isNotebook = value;
}
}
public double HardDiskMemory
{
get { return hardDiskMemory; }
set
{
hardDiskMemory = value;
}
}
public double FreeMemory
{
get { return freeMemory; }
set
{
freeMemory = value;
}
}
public string OperationSystem
{
get { return operationSystem; }
set
{
operationSystem = value;
}
}
public string NewOperationSystem
{
get { return NewOperationSystem; }
set
{
newOperationSystem = value;
}
}
public void Print()
{
Console.WriteLine($"{years}, {price}, {isNotebook}, {hardDiskMemory}, {FreeMemory}, {operationSystem}");
}
what I want this program to do is whenever the input submitted by the user is "changeOperationSystem" the program gives the user another input where they submit the new Operation system for the pc. Then with the constructor, the Computer.Cs receives the string newOperationSystem, which then should replace the value operationSystem as I tried to do in the constructor: OperationSystem = newOperationSystem, but it doesn't work. I am stil learning classes so don't go hard on me.
It seems to me you are trying to change one property of a class. All you have to do is use the property set method
one.OperationSystem = newOperationSystem;
and remove the property NewOperationSystem altogether.
Here is a bare bones skeleton code of instantiating a class with a constructor and then changing one of the properties
public class Foo
{
private int _a;
private string _b;
private readonly float _c;
public Foo(int a, string b, float c)
{
_a = a;
_b = b;
_c = c;
}
public int A { get => _a; set => _a = value; }
public string B { get => _b; set => _b = value; }
public float C => _c;
public override string ToString()
{
return $"{_a}, {_b}, {_c}";
}
}
class Program
{
static void Main(string[] args)
{
Foo one = new Foo(100, "Philip", 0.75f);
Console.WriteLine(one);
//100, Philip, 0.75
one.B = "Spencer";
Console.WriteLine(one);
//100, Spencer, 0.75
}
}
Another feature of the code above is that there is no need to create a .Print() method, if you can take advantage of the built-in .ToString() which gets called automatically during a Console.WriteLine() or any other operations that require a string input from my class.
Finally, I added a read-only property C to demonstrate that this design is possible. You will not be able to write one.C = 0.25f; since the property is read-only.

Stack overflow exception with no recursion

I'm having trouble with a stack overflow exception but I can't tell what's causing the exception to be thrown. I'm using a class library that contains all the methods and objects I need and running it from a console application.
Any help would be greatly appreciated as this is part of an assignment that is due in a couple of hours.
Here is my code:
TrafficIncidentNotificationRadiusCalculator class
namespace TrafficIncident
{
public class TrafficIncidentNotificationRadiusCalculator
{
public double meters;
public double CONFIGURED_NOTIFICATION_RADIUS
{
get { return CONFIGURED_NOTIFICATION_RADIUS; }
set { CONFIGURED_NOTIFICATION_RADIUS = meters; }
}
public List<string> GetNotificationRecipientsList(List<User> users, List<UserLocationUpdate> userLocation, TrafficIncidentReport report)
{
int i = 0;
List<string> userNotificationIds = new List<string>();
while (i < userLocation.Count)
{
UserLocationUpdate userLoc = userLocation.ElementAt(i);
userNotificationIds.Add(userLoc.userNotificationId);
Console.WriteLine(userNotificationIds.ElementAt(i));
i++;
}
return userNotificationIds;
}
}
}
TrafficIncidentReport class
namespace TrafficIncident
{
public class TrafficIncidentReport
{
public double[] incidentLocation;
public double latitude
{
get { return latitude; }
set { latitude = value; }
}
public double longitude
{
get { return longitude; }
set { longitude = value; }
}
public void SetIncidentLocation()
{
incidentLocation = new double[] { latitude, longitude };
}
public double[] GetIncidentLocation()
{
return incidentLocation;
}
}
}
User class
namespace TrafficIncident
{
public class User
{
public string userFName
{
get { return userFName; }
set { userFName = value; }
}
public string userLName
{
get { return userLName; }
set { userLName = value; }
}
}
}
UserLocationUpdate class
namespace TrafficIncident
{
public class UserLocationUpdate
{
public string userNotificationId
{
get { return userNotificationId; }
set { userNotificationId = value; }
}
public double lastKnownLatitude
{
get { return lastKnownLatitude; }
set { lastKnownLatitude = value; }
}
public double lastKnownLongitude
{
get { return lastKnownLongitude; }
set { lastKnownLongitude = value; }
}
}
}
And then this is the console application that the class library is running from:
namespace ClassLibraryTestApp
{
class Program
{
static void Main(string[] args)
{
List<User> users = new List<User>();
List<UserLocationUpdate> userLocation = new List<UserLocationUpdate>();
User user1 = new User();
user1.userFName = "Scott";
user1.userFName = "Gersbank";
users.Add(user1);
User user2 = new User();
user2.userFName = "John";
user2.userFName = "Smith";
users.Add(user2);
User user3 = new User();
user3.userFName = "James";
user3.userFName = "Moore";
users.Add(user3);
UserLocationUpdate user1Location = new UserLocationUpdate();
user1Location.lastKnownLatitude = 0;
user1Location.lastKnownLongitude = 0;
user1Location.userNotificationId = "user1";
userLocation.Add(user1Location);
UserLocationUpdate user2Location = new UserLocationUpdate();
user1Location.lastKnownLatitude = 1;
user1Location.lastKnownLongitude = 1;
user1Location.userNotificationId = "user2";
userLocation.Add(user2Location);
UserLocationUpdate user3Location = new UserLocationUpdate();
user1Location.lastKnownLatitude = 2;
user1Location.lastKnownLongitude = 2;
user1Location.userNotificationId = "user3";
userLocation.Add(user3Location);
TrafficIncidentReport trafficReport = new TrafficIncidentReport();
trafficReport.latitude = 1;
trafficReport.longitude = 1;
trafficReport.SetIncidentLocation();
TrafficIncidentNotificationRadiusCalculator TINRC = new TrafficIncidentNotificationRadiusCalculator();
TINRC.meters = 20000;
TINRC.GetNotificationRecipientsList(users, userLocation, trafficReport);
}
}
}
This is not a right way to create properties, define a private field, then the property itself: In your case it will call recursively the set_latitude() method and cause a stack overflow exception.
Wrong:
public double latitude
{
get { return latitude; }
set { latitude = value; }
}
Right:
private double latitude
public double Latitude
{
get { return latitude; }
set { latitude = value; }
}
Or use Auto-Implemented Properties:
public double Latitude { get; set; }
Your code starts with a recursive assignment, The first recursion is here :
public double meters;
public double CONFIGURED_NOTIFICATION_RADIUS
{
get { return CONFIGURED_NOTIFICATION_RADIUS; }
set { CONFIGURED_NOTIFICATION_RADIUS = meters; }
}
What's wrong:
Whenever you set some value to a property it's setter will trigger,
and whenever you access the value of a property the setter will
trigger. in the above mentioned case, you are assigning the property
value in it's setter which will repeatedly trigger the setter and
hance you get the exception
See all of your getter and setter are wrong, You should use a backup variable or else use them as {get;set}. In the case of userNotificationId you should define the property as like the following:
private _UserNotificationId
public string UserNotificationId
{
get { return _UserNotificationId; }
set { _UserNotificationId= value; }
}
Or simply
public string UserNotificationId { get; set; }

Utilizing C# inheritance correctly

I have written the code below, but i see that for to access the width and the length for the last child which is badRectangle is by overriding everything inhrerited from the Rectangle and shape class, which means i have to duplicate the input and i i had 6 or more levels of inheritance the code would kind of confuse and repeat a lot of things.
This code works correctly but is the correct way of dealing with inheritance in C#.
class Program
{
static void Main(string[] args)
{
badRectangle myRect = new badRectangle(true,"Rectangle",23.0,23);
Console.WriteLine("The Area of your Rectangle = " + myRect.getArea().ToString()
+ "\nAnd " + myRect.getStatus());
Console.ReadLine();
}
public abstract class shape
{
string type;
public abstract double getArea();
public shape(string type)
{
this.type = type;
}
}
public class rectangle : shape
{
double width, length;
public rectangle(string type, double width, double length):base(type)
{
this.width = width;
this.length = length;
}
public override double getArea()
{
return width * length;
}
}
public class badRectangle : rectangle
{
double width, length;
bool badOrNot = false;
public badRectangle(bool badOrNot,string type, double width, double length):base(type,width,length)
{
this.badOrNot = badOrNot;
this.width = width;
this.length = length;
}
public string getStatus()
{
string answer = "No, Rectangle is not bad";
if (badOrNot == true)
{
answer = "Yes, Rectangle is bad";
}
return answer;
}
public override double getArea()
{
return width * length;
}
}
}
This would be the "correct" or conventional way to do this in C#:
public abstract class Shape
{
public string Type { get; private set; }
public abstract double Area { get; }
public Shape(string type)
{
this.Type = type;
}
}
public class Rectangle : Shape
{
public double Length { get; private set; }
public double Width { get; private set; }
public Rectangle(string type, double width, double length)
: base(type)
{
this.Width = width;
this.Length = length;
}
public override double Area { get { return this.Width * this.Length; } }
}
public class BadRectangle : Rectangle
{
public bool BadOrNot { get; private set; } = false;
public BadRectangle(string type, double width, double length, bool badOrNot)
: base(type, width, length)
{
this.BadOrNot = badOrNot;
}
public string Status
{
get
{
string answer = "No, Rectangle is not bad";
if (this.BadOrNot == true)
{
answer = "Yes, Rectangle is bad";
}
return answer;
}
}
}
You don't need to set width and length in the derived classes again, just pass them to the constructor of the base class. If you need to access them in the derived class, make them protected. The getArea() doesn't have to be overridden if it does the same thing.

How do I solve this error "not all code paths return a value"

The setSpeedX was underlined for the error "not all code paths return a value". May I know how do I solve it? The codes are as below:
class Ball
{
public int speedX { get; private set; }
public int speedY { get; private set; }
public int positionX { get; private set; }
public int positionY { get; private set; }
public Ball(int speedX, int speedY, int positionX, int positionY)
{
this.speedX = speedX;
this.speedY = speedY;
this.positionX = positionX;
this.positionY = positionY;
}
public int setSpeedX(int newSpeedX)
{
speedX = newSpeedX;
}
public int setSpeedY(int newSpeedY)
{
speedY = newSpeedY;
}
public int setPositionX(int newPositionX)
{
positionX = newPositionX;
}
public int setPositionY(int newPositionY)
{
positionY = newPositionY;
}
}
Thank you.
Add return to your methods that should return value like:
public int setPositionY(int newPositionY)
{
positionY = newPositionY;
return positionY;
}
or change them to return void:
public void setPositionY(int newPositionY)
{
positionY = newPositionY;
}
You never put a return statement, so no value is returned, even though you declare the method that it should.
There are two ways to fix this:
make the method void:
public void setSpeedX(int newSpeedX)
{
speedX = newSpeedX;
}
or return a value:
public int setSpeedX(int newSpeedX)
{
speedX = newSpeedX;
return speedX;
}
This goes for all methods by the way, not just setSpeedX.
You are setting a value in your methods (setSpeedX, setSpeedY, setPositionX, setPositionY ), but not returning anything. But the signature of the methods have a return type int.
So... replace the return type int with void, like this:
public void setSpeedX(int newSpeedX)
{
speedX = newSpeedX;
}
public void setSpeedY(int newSpeedY)
{
speedY = newSpeedY;
}
public void setPositionX(int newPositionX)
{
positionX = newPositionX;
}
public void setPositionY(int newPositionY)
{
positionY = newPositionY;
}
or return a value of type int, like this:
public int setSpeedX(int newSpeedX)
{
speedX = newSpeedX;
return speedX;
}
public int setSpeedY(int newSpeedY)
{
speedY = newSpeedY;
return speedY;
}
public int setPositionX(int newPositionX)
{
positionX = newPositionX;
return positionX;
}
public int setPositionY(int newPositionY)
{
positionY = newPositionY;
return positionY;
}
Either return a value
public int setSpeedX(int newSpeedX)
{
speedX = newSpeedX;
return(speedX);
}
Or change the method to void
public void setSpeedX(int newSpeedX)
{
speedX = newSpeedX;
}
There doesn't seem to be much value in returning a value

Categories