Create a class Smoothie and do the following: Create a property called Ingredients.…
- User
Create a class Smoothie and do the following:
Create a property called Ingredients. Create a GetCost method which calculates the total cost of the ingredients used to make the smoothie. Create a GetPrice method which returns the number from GetCost plus the number from GetCost multiplied by 1.5. Round to two decimal places. Create a GetName method which gets the ingredients and puts them in alphabetical order into a nice descriptive sentence. If there are multiple ingredients, add the word "Fusion" to the end but otherwise, add "Smoothie". Remember to change "-berries" to "-berry". See the examples below. |Ingredient |Price |Strawberries|£1.50 |Banana |£0.50 |Mango |£2.50 |Blueberries |£1.00 |Raspberries |£1.00 |Apple |£1.75 |Pineapple |£3.50
s1 = Smoothie(new string[] { "Banana" }) s1.Ingredients ➞ { "Banana" } s1.GetCost() ➞ "£0.50" s1.GetPrice() ➞ "£1.25" s1.GetName() ➞ "Banana Smoothie" s2 = Smoothie(new string[] { "Raspberries", "Strawberries", "Blueberries" }) s2.ingredients ➞ { "Raspberries", "Strawberries", "Blueberries" } s2.GetCost() ➞ "£3.50" s2.GetPrice() ➞ "£8.75" s2.GetName() ➞ "Blueberry Raspberry Strawberry Fusion" Please do this with C# code.
- Assistant
class Smoothie { private string[] Ingredients;
public Smoothie(string[] ingredients) { Ingredients = ingredients; } public string GetCost() { double totalCost = 0; Dictionary<string, double> ingredientPrices = new Dictionary<string, double>() { { "Strawberries", 1.50 }, { "Banana", 0.50 }, { "Mango", 2.50 }, { "Blueberries", 1.00 }, { "Raspberries", 1.00 }, { "Apple", 1.75 }, { "Pineapple", 3.50 } }; foreach (string ingredient in Ingredients) { totalCost += ingredientPrices[ingredient]; } return "£" + totalCost.ToString("F2"); } public string GetPrice() { double totalCost = double.Parse(GetCost().Substring(1)); return "£" + (totalCost + totalCost * 1.5).ToString("F2"); } public string GetName() { string[] sortedIngredients = Ingredients; Array.Sort(sortedIngredients); string name = ""; foreach (string ingredient in sortedIngredients) { string formattedIngredient = ingredient.EndsWith("berries") ? ingredient.Replace("berries", "berry") : ingredient; name += formattedIngredient + " "; } if (sortedIngredients.Length > 1) { name += "Fusion"; } else { name += "Smoothie"; } return name.TrimEnd(); } - User
Write a class Date. Write a method that when passed a date as year/month/ day and returns the date's weekday name in the Dutch culture. The culture identifier to use is "nl-NL". Not "nl-BE". You can assume the specified date is valid. Looking at the tests and doing a switch statement or similar is considered cheating. System.Globalization.CultureInfo should be used. The method may be used to get the name of the Dutch weekday of other memorable days too, like in the examples below:
Examples: WeekdayInDutch(1970, 9, 21)) ➞ "maandag" WeekdayInDutch(1945, 9, 2)) ➞ "zondag" WeekdayInDutch(2001, 9, 11)) ➞ "dinsdag" ....Please solve it with C# code
- Assistant
using System; using System.Globalization;
class Date { public static string WeekdayInDutch(int year, int month, int day) { DateTime date = new DateTime(year, month, day); CultureInfo dutchCulture = new CultureInfo("nl-NL"); return date.ToString("dddd", dutchCulture); } }
// Testing the class class Program { static void Main(string[] args) { Console.WriteLine(Date.WeekdayInDutch(1970, 9, 21)); // Output: maandag Console.WriteLine(Date.WeekdayInDutch(1945, 9, 2)); // Output: zondag Console.WriteLine(Date.WeekdayInDutch(2001, 9, 11)); // Output: dinsdag } }
- User
namespace FuelConsumptionCalculator { class CarTest { static void Main(string[] args) { Car car1 = new Car(9000, 10000, 180); Car car2 = new Car(8000, 10000, 50);
- Assistant
To fix the
FinalPrintmethod in theCarclass, you can modify it as follows:public void FinalPrint() { Console.WriteLine("Car is " + (IsGasHog() ? "Gas Hog" : "Economy Car")); }This will properly output whether the car is a Gas Hog or an Economy Car based on the fuel consumption.
You should also remove the
return true;statement from theFinalPrintmethod, as it is not needed. - User
The goal of this optional exercise is to design and implement a simple inventory control system for a small video rental store. Define least two classes: a class Video to model a video and a class VideoStore to model the actual store.
Assume that a Video may have the following state:
A title; a flag to say whether it is checked out or not; and an average user rating. In addition, Video has the following behaviour:
being checked out; being returned; receiving a rating. The VideoStore may have the state of videos in there currently. The VideoStore will have the following behaviour:
add a new video (by title) to the inventory; check out a video (by title); return a video to the store; take a user's rating for a video; list the whole inventory of videos in the store. Finally, create a VideoStoreTest which will test the functionality of your other two classes. It should allow the following:
Add 3 videos: "The Matrix", "Godfather II", "Star Wars Episode IV: A New Hope". Give several ratings to each video. Rent each video out once and return it. List the inventory after "Godfather II" has been rented out out. Summary of design specs:
Store a library of videos identified by title. Allow a video to indicate whether it is currently rented out. Allow users to rate a video and display the percentage of users that liked the video. Print the store's inventory, listing for each video: its title, the average rating, and whether it is checked out or on the shelves. Please write C# code to do this.
- Assistant
- Assistant
- User
Your task is to find the sum of the first N odd natural numbers. Please solve with C# code
- Assistant
You can find the sum of the first N odd natural numbers using the following C# code:
using System; class Program { static void Main(string[] args) { int N = 10; //