|
its the one I have done, so far; I mean part one and two
=========================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace assignmnet1
{
public abstract class Fish
{
protected int weight; //fields definition
/* definition of class property in general
get { return fish_name};
set {fish_name = value}; */
// Abstract read-only properties
public abstract string Name
{
get;
}
public abstract string ScientificName
{
get;
}
public abstract string Acceptable
{
get;
}
//method - public override string ToString().
public override string ToString()
{
return base.ToString();
}
public class AustralianBass : Fish
{
public AustralianBass()
{
Random random = new Random();
weight = random.Next(0, Max_Weight);
}
public const int Max_Weight = 4000;
public override string Name
{
get { throw new NotImplementedException(); }
}
public override string ScientificName
{
get { throw new NotImplementedException(); }
}
public override string Acceptable
{
get { throw new NotImplementedException(); }
}
}
public class ShortFinnedEel : Fish
{
public const int Max_Weight = 3000;
public override string Name
{
get { throw new NotImplementedException(); }
}
public override string ScientificName
{
get { throw new NotImplementedException(); }
}
public override string Acceptable
{
get { throw new NotImplementedException(); }
}
}
public class EelTailedCatfish : Fish
{
public const int Max_Weight = 6800;
public override string Name
{
get { throw new NotImplementedException(); }
}
public override string ScientificName
{
get { throw new NotImplementedException(); }
}
public override string Acceptable
{
get { throw new NotImplementedException(); }
}
}
public class GippslandPerch : Fish
{
public const int Max_Weight = 10000;
public override string Name
{
get { throw new NotImplementedException(); }
}
public override string ScientificName
{
get { throw new NotImplementedException(); }
}
public override string Acceptable
{
get { throw new NotImplementedException(); }
}
}
==================================================================================================
the next part is
Class Fishing. The class should have three methods:
· public static void Fishing() – The method imitates a fishing process. It randomly creates
fishes of different species with random weights, and if a fish is acceptable (i.e. is heavier
than 500 g and still edible) adds the fish in the basket, i.e. writes the fish object to the
basket.dat file . The process continues while the total weight of the fishes in the basket is
less than 15000 g. (15 Kg). To write fish objects to the file you should use Serialize()
method of the BinaryFormatter class (notice, that the Fish class should have [Serializable]
attribute).
public static void ReadBasket() – the method opens the basket.dat file, reads the objects
from the file and prints them in the terminal window.
its the problem, I don't know who to impelement it.
|
|
|
|
|
hello,
I need your help. is any one can help me,please?
|
|
|
|
|
<click>
I'm sorry, but the Western World is closed for the weekend, and will not be available to help you with your homework until tomorrow.
Please leave your name, number and a message describing the actual problem you are having after the tone, and we will try to get back to you when we return to the office on Monday.
<BEEP>
You should never use standby on an elephant. It always crashes when you lift the ears. - Mark Wallace
C/C++ (I dont see a huge difference between them, and the 'benefits' of C++ are questionable, who needs inheritance when you have copy and paste) - fat_boy
|
|
|
|
|
As far as I can ascertain, Name and ScientificName need to return a hardcoded string in implementing classes.
In your abstract Fish class, Acceptable should be a bool . To implement it you need to test the values you've been given for this species against the weight.
namespace Assignment1
{
public abstract class Fish
{
protected int weight;
public abstract bool Acceptable { get; }
public abstract string Name { get; }
public abstract string ScientificName { get; }
public int Weight
{
get { return weight; }
}
public override string ToString()
{
return Name;
}
}
}
using System;
namespace Assignment1
{
public class AustralianBass : Fish
{
public const int MAX_WEGHT = 4000;
public AustralianBass()
{
Random random = new Random();
weight = random.Next(0, MAX_WEGHT);
}
public override bool Acceptable
{
get { return weight >= 500 && weight < 2500; }
}
public override string Name
{
get { return "Australian Bass"; }
}
public override string ScientificName
{
get { return "Macquaria novemaculeata"; }
}
}
}
Do similar for the other classes and you will be good to go for the next parts.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier. (Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
Member 4674360 wrote: its the problem, I don't know who how to impelement it.
There's an example on MSDN that shows how to read a file[^].
Looks something like this;
using (StreamReader sr = File.OpenText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
Console.WriteLine(s);
}
}
I are Troll
|
|
|
|
|
thanks a lot for your help.
I implement the 3rd part but I faced with a problem. in part 3, I create a random number and random weight. I check them with mentioend values but the problem is how I should access to the properties of the class.
this is part3,
================================================
fishes of different species with random weights, and if a fish is acceptable (i.e. is heavier
than 500 g and still edible) adds the fish in the basket, i.e. writes the fish object to the
basket.dat file . The process continues while the total weight of the fishes in the basket is
less than 15000 g. (15 Kg). To write fish objects to the file you should use Serialize()
method of the BinaryFormatter class (notice, that the Fish class should have [Serializable]
attribute).
==================================================
this is my code
public class fisshing
{
public static void fishing()
{
int basket = 0;
Random rand = new Random(0,4);
Random weight = new Random.next(0,10000);
do
{
switch (rand)
{
case 1:
if (weight > 500 && weight < 2500)
{
basket = basket + weight;
}
case 2:
if (weight > 500 && weight < 3000)
{
basket = basket + weight;
}
case 3:
if (weight > 500 && weight < 4000)
{
basket = basket + weight;
}
case 4:
if (weight > 500 && weight < 6000)
{
basket = basket + weight;
}
}
} while basket => 15000;
}
}
|
|
|
|
|
hello,
is my code right regarding the requirement?
|
|
|
|
|
Member 4674360 wrote: is my code right regarding the requirement?
You're going in the right direction, just keep working at it
For starters, I modified your code so that it compiles;
int basket = 0;
Int32 rand = new Random().Next(0,4);
Int32 weight = new Random().Next(0,10000);
do
{
switch (rand)
{
case 1:
if (weight > 500 && weight < 2500)
basket = basket + weight;
break;
case 2:
if (weight > 500 && weight < 3000)
basket = basket + weight;
break;
case 3:
if (weight > 500 && weight < 4000)
basket = basket + weight;
break;
case 4:
if (weight > 500 && weight < 6000)
basket = basket + weight;
break;
}
} while (basket >= 15000);
- There's a
break statement at the end of each case
- Changed "rand" and "weight" to
int , assuming you want to work with the numbers
- Changed the order of the operators in the
while loop; >= works, => doesn't compile (would be interpreted as a lambda-statement).
As your requirements go; I don't see a fish-class, nor a BinaryFormatter[^]. How about something like this;
using System.Runtime.Serialization.Formatters.Binary;
[Serializable()]
public class MyFish
{
public int Weight { get; set; }
public MyFish()
{
Weight = new Random().Next(0,10000);
}
}
I are Troll
|
|
|
|
|
But why have four different case 's? They all do the same thing as long as the weight is more than 500 and less than 6000 (and that is - adds the weight to the basket ). Maybe I've missed something in the instruction, but I would write:
while (basket <= 15000)
{
basket += weight;
}
|
|
|
|
|
Calla wrote: But why have four different case's?
Dunno, it was in the original code - but you're right
I are Troll
|
|
|
|
|
I reckon there i a problem in part3, cause the condition include all. for instance if a fish is 1000g, it can be all four condition.
please read part3,
=======================
Part3:
The method imitates a fishing process. It randomly creates
fishes of different species with random weights, and if a fish is acceptable (i.e. is heavier
than 500 g and still edible) adds the fish in the basket, i.e. writes the fish object to the
basket.dat file . The process continues while the total weight of the fishes in the basket is
less than 15000 g. (15 Kg). To write fish objects to the file you should use Serialize()
method of the BinaryFormatter class (notice, that the Fish class should have [Serializable]
attribute).
|
|
|
|
|
Hi
i'm looking for good library or source code which implement send/receive sms via gsm modem. i found this article[^] and it's good, but unfortunately it does not support delivery event handler when sms deilvered. can anybody help me and provide better library or source code which support more events ?
thanks in advance
|
|
|
|
|
Do you want to use any thirdparty api / write your own?
Thanks
Md. Marufuzzaman
I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
|
|
|
|
|
Hi
no, i don't want to use any third party controls, i want to create my own.
can u help me ?
|
|
|
|
|
Hi Friends,
I am working on a ERP windows Project c#, that should support both Oracle & Sql Server. Now I suppose to write procedures for both the databases. because we don't want inline queries in our codes. I feel this will cause maintanance issue in future as software size grows.
I heard, Entity Framework & Linq to DB will affect application performance when compare to stored Procedures.
Please advise me, what is the best solution. That should solve performance as well as SQL & Oracle support.
Thanks in Advance
Anand
|
|
|
|
|
The application should neither know nor care what database is in use. This is where the Data Access Layer shines -- it separates the application from the database. I prefer to have a database-agnostic framework (such as my DatabaseAccessor[^]) upon which to build the DAL. You can then build flexibility into your DAL to deal with the various flavors of SQL (which is a step I haven't bothered to take yet myself).
Given a proper DAL, the application developers won't know whether you are using stored procedures or not.
anand kumar m wrote: Now I suppose to write procedures for both the databases. ... I feel this will cause maintanance issue in future as software size grows.
Yes, it will. The queries have to go somewhere, and there are differences in how SQL is implemented by various vendors. For ease of maintenance, the multiple versions of a particular query should be kept close together, in one file if possible. This tends not to be the case when using stored procedures. It's one of the things I like least about stored procedures (I don't use stored procedures anymore).
anand kumar m wrote: Entity Framework & Linq to DB
Don't those only work with SQL Server? Either way, I avoid them.
The old ways are the best ways.
P.S. As to performance -- you still need to write good SQL and use Connections, Commands, and Parameters effectively.
Most "performance" problems are caused by poor understanding of the tools being used.
modified on Saturday, April 24, 2010 1:18 PM
|
|
|
|
|
hi bloggers,
I have been trying to visualize my gestures through MS chart graph, for instance using wiimote accelerometer to draw a shape of the number(0-9), when I try to make 0,6,8,9 the shape is not drawn completely rather the coordinates spreads on the other side.... currently Im calculating velocity and distance from the accelerometer values(x,y,z) and then plot distance values to MSCHART spline graph....
give me some suggestions or solutions how can I correct my code...
this is the snippet of the code which Im trying to plot on the graph
private void show()
{
for (int i=1; i<=size-1; i++)
{
VX[i] = VX[i - 1] + (XA[i] * RecordTimer.Interval * 10.0);
VY[i] = VY[i - 1] + (YA[i] * RecordTimer.Interval * 10.0);
VZ[i] = VZ[i - 1] + (ZA[i] * RecordTimer.Interval * 10.0);
}
for (int i=0; i< size-1; i++){
DX[i] = VX[i] * RecordTimer.Interval;
DY[i] = VY[i] * RecordTimer.Interval;
DZ[i] = VZ[i] * RecordTimer.Interval;
}
for (int i=1; i<=size-1; i++)
{
DisX.Text += string.Format("{0: 0.00000000}\n", Convert.ToInt32(DX[i]).ToString());
DisY.Text += string.Format("{0: 0.00000000}\n", Convert.ToInt32(DY[i]).ToString());
DisZ.Text += string.Format("{0: 0.00000000}\n", Convert.ToInt32(DZ[i]).ToString());
}
for (int i=1; i<=size-1; i++) {
double x = DX[i];
double y = DY[i];
double z = DZ[i];
CXZ.Series["XZ"].Points.AddXY(x, -z);
CXY.Series["XY"].Points.AddXY(x, -y);
CYZ.Series["YZ"].Points.AddXY(y,-z);
}
}
suggestions are anxiously required.....
modified on Saturday, April 24, 2010 9:42 AM
|
|
|
|
|
Hi,
if RecordTimer happens to be a System.Windows.Forms.Timer you are overly optimistic about its accuracy; I suggest you read Timer surprises, and how to avoid them[^] and switch to another timing mechanism (Multimedia timer, or Stopwatch).
PS: check the code snippet shown, it is unreadable, lacking formatting and the necessary HTML and smiley escaping.
|
|
|
|
|
sorry for the formatting of the query...
well im not concerned with the timer here.. but I want to plot my distance array values into the graph rather a spline graph that makes a rough shape of a NUMERIC digit (0-9)
P.s : I am using a WIIMOTE to get acceleration
modified on Saturday, April 24, 2010 9:52 AM
|
|
|
|
|
As your timing is wrong, so are all accelerations, velocities and distances.
Furthermore, you're doing some "forward integration", which is a rude approximation, and a worse one for larger time steps; which is what you are getting.
|
|
|
|
|
so tell me what should I be doing to calculate the time of acceleration values from the wiimote?
|
|
|
|
|
further more.. I had fixed my time for the acceleration that is 10ms each time ...
I dont kno if it is correct or not .. but for estimation..
|
|
|
|
|
1.
you would have to tell a lot more about the system. Are you getting the acceleration values in real-time? or just post-processing them? what is the interface? what is the fastest you could get them?
2.
you should use actual time, not estimated time; your code implies time moves linearly from one sample to the next; there will be deviations that may throw you off. So measure and store Windows time for each sample you get, and use the time deltas in your math.
3.
numeric integration is a research topic, far beyond the scope of a forum like this one. when you have a sufficient number of samples (i.e. when the first and second derivative of your inputs are small) then all is fine whatever you do; when values change rapidly, forward integration is the worst you can do. You might apply the average of current acceleration and previous acc as a first-order improvement.
|
|
|
|
|
ok here is the full description for my project!
well Im getting real time values from the wiimote accelerometer in instance wiimote generate 100 (x,y and z) values per second.
now thats I store my values in a array , I calculate the velocity through the formula
Vi+1= Vi + ( Acceleration * time * gravity);
then from the velocity values I calculate the distance
DistanceX= Velocity * time
in the last Im tryin to plot the DistanceX and DistanceY on the spline graph but the shapes that include a little bit of circular motion doesnot plot on the graph but the line gets straight below the graph ...
for example if I try to make a gesture of a number "0" .. the graph shows an ARC shape on the graph.
all other gestures... (1,2,3,4,5,7) are plotted as it is... but (0,6,8,9) doesnt...
now what do u say for this...
waiting for your response...
modified on Saturday, April 24, 2010 10:35 AM
|
|
|
|
|
OK, some comments:
alibaba88s wrote: wiimote generate 100 (x,y and z) values per second.
so, you haven't convinced me yet you are getting the right values with the associated time value.
alibaba88s wrote: Vi+1= Vi + ( Acceleration * time * gravity);
1. gravity is not involved.
2. this is known as forward integration: you assume acceleration is constant from time point i to time point i+1 which it probably isn't
alibaba88s wrote: if I try to make a gesture of a number "0"
I don't know about MSChart; can it handle arbitrary shapes, or does it only work well for functions, i.e. where one position (x,y) only has one value (z)?
alibaba88s wrote: add me on the messenger
no thanks. I don't do chats and tweets.
I'm afraid you'll need to stretch a lot to get this working properly. Good luck.
|
|
|
|
|