
First to clarify that I'm an apsolute beginner when dealing with programming. I took a class that involves programming in SQL and MVS 2010. Unfortunately i wasn't present when we started working in C# and now the teacher gave us an assignment with a nearby deadline and sorry to say, i don't have the time for reading ebooks about C#. I would appreciate any help on this matter. Thanks in advance.
this is the assignment:
CLASS ITEM
Class represents an entry on account. It's possibble to register/log the name/expression and the price of an item.
FIELDS
1. expression (string)
item's name
2. price (string)
item's price
3. amount (int)
items's ammount
4. description (string)
item's description
CONSTRUCTORS
1. gets expression and price of an item and sets FIELDS expression and price. FIELD amount sets on 1, FIELD description sets on 'Unknown'
2. gets the expression, price and the amount of an item and sets FIELDS expression, price and amount. FIELD description sets on 'Unknown'
PROPERTIES
1. Expression (read only)
2. Price (read only)
3. Amount (read)
4. Description (read/write)
5. TotalPrice (read)
brings back the product of amount and price
METHODS
1. void ChangeAmount (int NewAmount)
method sets theitem's amount on parameter's value NewAmount in case tehe value is >=1
2. string GetDescription ()
3. method returns the description of an item (expression, price and amount)
EX:
public class Item{
private String name;
private String price;
private int amount;
private String description;
public Item(name,price){
this.name = name;
this.price = price;
this.amount = 1;
this.description = "UnKnown";
}
public Item(name,price,amount){
this.name = name;
this.price = price;
this.amount = amount;
this.description = "UnKnown";
}
public void changeAmount(int newAmount){
this.amount = newAmount;
}
public String getDescription(){
return this.description + this.price + this.amount + this.name;
}
public String getPrice(){
return this.price;
}
public int getAmount(){
return this.amount
}
public double getTotalprice(){
double total = Double.Parse(price) * amount;
return total;
}
}






0 comments:
Post a Comment