עזרה בתרגיל ב-C# - תכנות - HWzone פורומים
עבור לתוכן
  • צור חשבון

עזרה בתרגיל ב-C#


moskitos

Recommended Posts

התרגיל שלי הוא:

Account class: Write a class for "Account". The class will contain the following fields:

The first account number will be 1000, and every new account will get the next number.

For this add a static field to Account class that will hold the last account number so far. Also add a static method that will initialize the field to 1000.

התחלתי לרשום משהו ונתקעתי במתודה שאמורה להחזיק את החשבון האחרון שנפתח ולא ממש בהנתי מה רוצים ממני במתודה האחרונה בתרגיל:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace T295
{
public class Account
{
public int AccountNumber;


//set new account
public void setAccount(int accountNumber)
{
this.AccountNumber = accountNumber;
}


//chech if account number leagal
public bool ifLegal(int accountNumber)
{
if (accountNumber < 1000)
{
return false;
}
else
{
return true;
}
}


//hold the last account number so far
public int LastAccountNumber()
{





}
}


class Program
{
static void Main(string[] args)
{








}
}
}

קישור לתוכן
שתף באתרים אחרים

כל הקלאס שלך רחוק מהלהיות מה שהם רוצים.

הם רוצים ככה:

תיצור מחלקה בשם account עם מספר חשבון עוקב.

כדי לעשות את זה הם מבקשים שתיצור שדה סטטי! (static, ככה שהוא לא משתנה בכל יצירה של קלאס->ובכלל בכל התוכנית)

גם כן, מבקשים שתיצור מטודה סטטית שמאתחלת את המשתנה הסטטי ל1000.

וגם מבקשים שכל מחלקה חדשה תהיה עם מספר עוקב ותשתמש במשתנה הסטטי כדי לעקוב(הרי אמרנו שהוא תקף לכל אורך התוכנית ולא מתאפס) (בכל יציאת מחלקה תעשה accountnumber=StaticAccountnumer++;)

אף אחד לא ביקש ממך לבדוק אם מזהה הaccount נכון או לא, אל תוסיף דברים שאין להם סיבת קיום.

קישור לתוכן
שתף באתרים אחרים

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

×
  • צור חדש...