In: Physics
This week, you will create and implement an object-oriented programming design for your project. You will learn to identify and describe the classes, their attributes and operations, as well as the relations between the classes. Create class diagrams using Visual Studio. Review the How to: Add class diagrams to projects (Links to an external site.) page from Microsoft’s website; it will tell you how to install it.
Submit a screen shot from Visual Studio with your explanation into a Word document, save as a .docx, before submitting it.
Below is the code I am trying to add class diagrams to:
using System;
namespace ConsoleApp8
{
class Program
{
static void Main(string[] args)
{
// display the current date
DateTime d = DateTime.Now;
Console.WriteLine("{0:dd/MM/yyyy HH:mm:ss}", d);
Console.WriteLine("Quiz");
string[] questions = LoadQuestions();
Boolean[] status = { false, false, false, false, false, false, false, false, false };
string[] options = LoadOptions();
string[] key = { "A", "B", "C", "D", "B", "C", "A", "A", "A" };
int noCorrectAnswer = 0;
// iterate through questions
for (int i = 0; i < 9; i++)
{
string choice = DisplayQA(questions, options, i);
// record correct answers
if (choice == key[i])
{
status[i] = true;
noCorrectAnswer++;
}
}
// if all answers are not correct, restart the quiz for wrong
answers
if (noCorrectAnswer < 9)
{
Console.WriteLine("Re-Start
Quiz================================");
Console.WriteLine("Repeat the quiz for wrong answered
questions!");
for (int i = 0; i < 9; i++)
{
if (status[i] == false)
{
string choice = DisplayQA(questions, options, i);
if (choice.Equals(key[i],
StringComparison.OrdinalIgnoreCase))
{
noCorrectAnswer++;
status[i] = true;
}
}
}
}
// display correct answers
Console.WriteLine("Number of correct Answers: " +
noCorrectAnswer);
Console.ReadLine();
}
///
/// display question with answer choices
///
///
///
///
///
private static string DisplayQA(string[] questions, string[]
options, int i)
{
string choice = "";
Console.WriteLine(questions[i]);
Console.WriteLine(options[i]);
Console.Write("Enter the answer: ");
choice = Console.ReadLine();
// keep asking until user enters valid option
while (!(choice.ToUpper().Equals("A") ||
choice.ToUpper().Equals("B") || choice.ToUpper().Equals("C") ||
choice.ToUpper().Equals("D")))
{
Console.WriteLine("\nInvalid value. Please choose valid
option!");
Console.Write("Enter the answer: ");
choice = Console.ReadLine();
}
return choice;
}
///
/// Load question options
///
///
private static string[] LoadOptions()
{
return new string[] { "A. 5\nB. 5\nC. 6\nD. 9",
"A. 2\nB. 7\nC. 6\nD. 9"
,"A. 2\nB. 5\nC. 7\nD. 9"
,"A. 2\nB. 5\nC. 6\nD. 24"
,"A. 2\nB. 1440\nC. 6\nD. 9"
,"A. 2\nB. 5\nC. 12\nD. 9"
,"A. 86400\nB. 5\nC. 6\nD. 9"
,"A. 60\nB. 5\nC. 6\nD. 9"
,"A. 60\nB. 5\nC. 6\nD. 9"};
}
///
/// Load Questions
///
///
private static string[] LoadQuestions()
{
string[] questions ={"How many working days are there in a
week?"
,"How many systems make up the human body?"
,"How many days are there in a week?"
,"How many hours make up one day?"
,"How many minutes make up one day?"
,"How many months are there in a year?"
,"How many seconds make up one day?"
,"How many seconds make up one hour?"
,"How many minutes make up one hour?"};
return questions;
}
}
}
The prgramming language is C# through Visual Studio. Thanks.
namespace ConsoleApp8
{
class Program
{
static void Main(string[] args)
{
// display the current date
DateTime d = DateTime.Now;
Console.WriteLine("{0:dd/MM/yyyy HH:mm:ss}", d);
Console.WriteLine("Quiz");
string[] questions = LoadQuestions();
Boolean[] status = { false, false, false, false, false, false, false, false, false };
string[] options = LoadOptions();
string[] key = { "A", "B", "C", "D", "B", "C", "A", "A", "A" };
int noCorrectAnswer = 0;
// iterate through questions
for (int i = 0; i < 9; i++)
{
string choice = DisplayQA(questions, options, i);
// record correct answers
if (choice == key[i])
{
status[i] = true;
noCorrectAnswer++;
}
}
// if all answers are not correct, restart the quiz for wrong
answers
if (noCorrectAnswer < 9)
{
Console.WriteLine("Re-Start
Quiz================================");
Console.WriteLine("Repeat the quiz for wrong answered
questions!");
for (int i = 0; i < 9; i++)
{
if (status[i] == false)
{
string choice = DisplayQA(questions, options, i);
if (choice.Equals(key[i],
StringComparison.OrdinalIgnoreCase))
{
noCorrectAnswer++;
status[i] = true;
}
}
}
}
// display correct answers
Console.WriteLine("Number of correct Answers: " +
noCorrectAnswer);
Console.ReadLine();
}
///
/// display question with answer choices
///
///
///
///
///
private static string DisplayQA(string[] questions, string[]
options, int i)
{
string choice = "";
Console.WriteLine(questions[i]);
Console.WriteLine(options[i]);
Console.Write("Enter the answer: ");
choice = Console.ReadLine();
// keep asking until user enters valid option
while (!(choice.ToUpper().Equals("A") ||
choice.ToUpper().Equals("B") || choice.ToUpper().Equals("C") ||
choice.ToUpper().Equals("D")))
{
Console.WriteLine("\nInvalid value. Please choose valid
option!");
Console.Write("Enter the answer: ");
choice = Console.ReadLine();
}
return choice;
}
///
/// Load question options
///
///
private static string[] LoadOptions()
{
return new string[] { "A. 5\nB. 5\nC. 6\nD. 9",
"A. 2\nB. 7\nC. 6\nD. 9"
,"A. 2\nB. 5\nC. 7\nD. 9"
,"A. 2\nB. 5\nC. 6\nD. 24"
,"A. 2\nB. 1440\nC. 6\nD. 9"
,"A. 2\nB. 5\nC. 12\nD. 9"
,"A. 86400\nB. 5\nC. 6\nD. 9"
,"A. 60\nB. 5\nC. 6\nD. 9"
,"A. 60\nB. 5\nC. 6\nD. 9"};
}
///
/// Load Questions
///
///
private static string[] LoadQuestions()
{
string[] questions ={"How many working days are there in a
week?"
,"How many systems make up the human body?"
,"How many days are there in a week?"
,"How many hours make up one day?"
,"How many minutes make up one day?"
,"How many months are there in a year?"
,"How many seconds make up one day?"
,"How many seconds make up one hour?"
,"How many minutes make up one hour?"};
return questions;
}
}
}