0% found this document useful (0 votes)
3 views

sdf104

The document contains C# code for two main applications: one for handling photo orders with options for regular, matted, and framed photos, and another for special cookie orders. It includes classes for different photo types and geometric figures, allowing for calculations of areas and prices based on user input. The code demonstrates object-oriented programming principles such as inheritance and encapsulation.

Uploaded by

Angel Monares
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

sdf104

The document contains C# code for two main applications: one for handling photo orders with options for regular, matted, and framed photos, and another for special cookie orders. It includes classes for different photo types and geometric figures, allowing for calculations of areas and prices based on user input. The code demonstrates object-oriented programming principles such as inheritance and encapsulation.

Uploaded by

Angel Monares
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

using System;

class MonaresPhotoDemo
{
static void Main(string[] args)
{
Console.WriteLine("Enter the width of the photo in inches:");
double width = double.Parse(Console.ReadLine());

Console.WriteLine("Enter the height of the photo in inches:");


double height = double.Parse(Console.ReadLine());

Console.WriteLine("Enter the type of photo (1 for regular, 2 for matted, 3 for framed):");
int type = int.Parse(Console.ReadLine());

if (type == 1)
{
Photo photo = new Photo(width, height);
Console.WriteLine(photo);
}
else if (type == 2)
{
Console.WriteLine("Enter the color of the mat:");
string color = Console.ReadLine();

MattedPhoto mattedPhoto = new MattedPhoto(width, height, color);


Console.WriteLine(mattedPhoto);
}
else if (type == 3)
{
Console.WriteLine("Enter the material of the frame:");
string material = Console.ReadLine();

Console.WriteLine("Enter the style of the frame:");


string style = Console.ReadLine();

FramedPhoto framedPhoto = new FramedPhoto(width, height, material, style);


Console.WriteLine(framedPhoto);
}
}
}

class Photo
{
public double height { get; set; }
public double width { get; set; }
protected double price;

public Photo(double width, double height)


{
this.width = width;
this.height = height;

if (width == 8 && height == 10)


{
price = 3.99;
}
else if (width == 10 && height == 12)
{
price = 5.99;
}
else
{
price = 9.99;
}
}

public override string ToString()


{
return GetType() + " - Width: " + width + " inches, Height: " + height + " inches, Price: $" +
price;
}
}

class MattedPhoto : Photo


{
private string color;

public MattedPhoto(double width, double height, string color) : base(width, height)


{
this.color = color;
price += 10;
}

public override string ToString()


{
return base.ToString() + ", Color: " + color;
}
}

class FramedPhoto : Photo


{
private string material;
private string style;

public FramedPhoto(double width, double height, string material, string style) : base(width,
height)
{
this.material = material;
this.style = style;
price += 25;
}

public override string ToString()


{
return base.ToString() + ", Material: " + material + ", Style: " + style;
}
}

abstract class GeometricFigure


{
public double Height { get; set; }
public double Width { get; set; }
public double Area;
public abstract double ComputeArea();
}
class Rectangle : GeometricFigure
{
public Rectangle(double height, double width)
{
Height = height;
Width = width;
}

public Rectangle(double side)


{
Height = side;
Width = side;
}

public override double ComputeArea()


{
return Height * Width;
}
}

class Square : Rectangle


{
public Square(double side) : base(side)
{
}

public Square(double height, double width) : base(height, width)


{
if (height != width)
{
Height = width;
}
}
}

class Triangle : GeometricFigure


{
public Triangle(double height, double width)
{
Height = height;
Width = width;
}

public override double ComputeArea()


{
return 0.5 * Height * Width;
}
}
class ShapesDemo
{
static void Main(string[] args)
{
Rectangle rectangle = new Rectangle(5, 10);
DisplayFigure(rectangle);

Square square = new Square(5);


DisplayFigure(square);

Triangle triangle = new Triangle(5, 10);


DisplayFigure(triangle);

rectangle.Height = 7;
rectangle.Width = 14;
DisplayFigure(rectangle);

square.Height = 7;
square.Width = 14;
DisplayFigure(square);

triangle.Height = 7;
triangle.Width = 14;
DisplayFigure(triangle);
}

static void DisplayFigure(GeometricFigure figure)


{
Console.WriteLine($"Height: {figure.Height}");
Console.WriteLine($"Width: {figure.Width}");
Console.WriteLine($"Area: {figure.Area}");
Console.WriteLine();
}
}

using System;

class MonaresSpecialCookie
{
static void Main(string[] args)
{
SpecialCookieOrder order1 = new SpecialCookieOrder();
Console.WriteLine("Enter Order Number:");
order1.OrderNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Recipient Name:");
order1.RecipientName = Console.ReadLine();
Console.WriteLine("Enter Cookie Type:");
order1.CookieType = Console.ReadLine();
Console.WriteLine("Enter Dozens Ordered:");
order1.DozensOrdered = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter Description:");
order1.SpecialReason = Console.ReadLine();
Console.WriteLine("");

// Calculate prices
order1.SetPrice();

Console.WriteLine("Order 1:");
Console.WriteLine("Order Number: " + order1.OrderNumber);
Console.WriteLine("Recipient Name: " + order1.RecipientName);
Console.WriteLine("Cookie Type: " + order1.CookieType);
Console.WriteLine("Dozens Ordered: " + order1.DozensOrdered);
Console.WriteLine("Description: " + order1.SpecialReason);
Console.WriteLine("Price: $" + order1.Price);

}
}

class CookieOrder
{
public int OrderNumber { get; set; }
public string RecipientName { get; set; }
public string CookieType { get; set; }
private int dozensOrdered;
protected double price;

public int DozensOrdered


{
get { return dozensOrdered; }
set
{
dozensOrdered = value;
SetPrice(); // Recalculate the price
}
}

public virtual double Price { get; }

public void SetPrice()


{
if (dozensOrdered <= 2)
{
price = dozensOrdered * 15;
}
else
{
price = 30 + (dozensOrdered - 2) * 13;
}
}

public override string ToString()


{
return $"Order Number: {OrderNumber}, Recipient Name: {RecipientName}, Cookie Type:
{CookieType}, Dozens Ordered: {dozensOrdered}, Price: ${price:F2}";
}
}

class SpecialCookieOrder : CookieOrder


{
public string SpecialReason { get; set; }

public override double Price


{
get
{
double Price = price;
if (price <= 40)
{
return price + 10;
}
else
{
return price + 8;
}
}
}

public override string ToString()


{
return $"{base.ToString()}, Special Reason: {SpecialReason}";
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy