• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 1 out of 3 pages
Exam (elaborations)

ISTM 250 Exam 2 — Coding Practical Preparation

Document preview thumbnail
Preview 1 out of 3 pages

ISTM 250 Exam 2 — Coding Practical Preparation. This document contains exam-style multiple choice questions with the correct answers clearly marked, covering the key topics tested in ISTM 250. Ideal for exam preparation, self-assessment and quick revision before your test.

Content preview

ISTM 250 Exam 2 — Coding Practical Preparation
1. Create a method that calculates the average of an array of integer quiz scores.

Requirements: Handle an empty array and return a decimal average for nonempty arrays.
Reference solution:

private decimal Average(int[] scores)
{
if (scores == null || scores.Length == 0)
throw new ArgumentException("At least one score is required.");
int sum = 0;
foreach (int score in scores) sum += score;
return (decimal)sum / scores.Length;
}

Rationale: The guard prevents division by zero; casting before division preserves fractional results.

2. Write a safe method that parses a date entered as MM/dd/yyyy.

Requirements: Use DateTime.TryParseExact with an explicit format and invariant culture.
Reference solution:

private bool TryReadDate(string text, out DateTime date)
{
return DateTime.TryParseExact(
text, "MM/dd/yyyy",
CultureInfo.InvariantCulture,
DateTimeStyles.None, out date);
}

Rationale: Exact parsing avoids ambiguous culture-dependent interpretation.

3. Create a class named Product with a name and unit price, ensuring price cannot be negative.

Requirements: Use private state or a property setter that enforces the invariant.
Reference solution:

public class Product
{
public string Name { get; set; }
private decimal unitPrice;
public decimal UnitPrice
{
get => unitPrice;
set
{
if (value < 0m) throw new ArgumentOutOfRangeException(nameof(value));
unitPrice = value;
}
}
}

Rationale: Encapsulation protects the object's valid state through a controlled property setter.

Document information

Uploaded on
November 18, 2026
Number of pages
3
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$9.98

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
EmilyRhodes
4.4
(15)
Sold
87
Followers
1
Items
10884
Last sold
1 week ago




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions