Question

Practice C# Activity The purpose of this activity is to allow students to become accustomed to...

Practice C# Activity The purpose of this activity is to allow students to become accustomed to the Visual Studio IDE and the differences in C# and Java. In this app, you will get practice working with C# I/O, if statements and loops. 1. Create a C# app for the Hollywood Movie Rating Guide, which can be installed in a kiosk in theaters. Each theater patron enters a value from zero to four indicating the number of stars that the patron awards to the guide’s featured movie of the week. If a user enters a star value that does not fall in the correct range, prompt the user continuously until a correct value is entered. The program executes continuously until the theater manager enters a negative number to quit. At the end of the app, display the average star rating for the movie. 2. Modify the movie-rating program so that a user gets three tries to enter a valid rating. After three incorrect tries entries, the program issues an appropriate message and continues with a new user.

Please write a C# program!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Design

Form1 Hollywood Movie Rating Guide textbox id-txtrating Rating: RatingButton id:btnrating Please Enter Rating Between 0 to 5

Form1.Designer.cs

namespace HollywoodMovie
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.btnrating = new System.Windows.Forms.Button();
            this.label2 = new System.Windows.Forms.Label();
            this.txtrating = new System.Windows.Forms.TextBox();
            this.lblavg = new System.Windows.Forms.Label();
            this.SuspendLayout();
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("Modern No. 20", 16.2F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.Location = new System.Drawing.Point(270, 44);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(401, 30);
            this.label1.TabIndex = 0;
            this.label1.Text = "Hollywood Movie Rating Guide";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(345, 168);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(232, 17);
            this.label3.TabIndex = 3;
            this.label3.Text = "Please Enter Rating Between 0 to 5";
            //
            // btnrating
            //
            this.btnrating.Location = new System.Drawing.Point(536, 108);
            this.btnrating.Name = "btnrating";
            this.btnrating.Size = new System.Drawing.Size(94, 37);
            this.btnrating.TabIndex = 4;
            this.btnrating.Text = "Rating";
            this.btnrating.UseVisualStyleBackColor = true;
            this.btnrating.Click += new System.EventHandler(this.btnrating_Click);
            //
            // label2
            //
            this.label2.AutoSize = true;
            this.label2.Location = new System.Drawing.Point(272, 118);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(53, 17);
            this.label2.TabIndex = 1;
            this.label2.Text = "Rating:";
            //
            // txtrating
            //
            this.txtrating.Location = new System.Drawing.Point(348, 118);
            this.txtrating.Name = "txtrating";
            this.txtrating.Size = new System.Drawing.Size(145, 22);
            this.txtrating.TabIndex = 5;
            //
            // lblavg
            //
            this.lblavg.AutoSize = true;
            this.lblavg.Location = new System.Drawing.Point(360, 234);
            this.lblavg.Name = "lblavg";
            this.lblavg.Size = new System.Drawing.Size(46, 17);
            this.lblavg.TabIndex = 6;
            this.lblavg.Text = "label4";
            //
            // Form1
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1015, 463);
            this.Controls.Add(this.lblavg);
            this.Controls.Add(this.txtrating);
            this.Controls.Add(this.btnrating);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label2);
            this.Controls.Add(this.label1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Button btnrating;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.TextBox txtrating;
        private System.Windows.Forms.Label lblavg;
    }
}

Coding

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HollywoodMovie
{
    public partial class Form1 : Form
    {
        double rating,total=0,count=0,error_count=0;
        double avg;
        public Form1()
        {
            InitializeComponent();
        }

        private void btnrating_Click(object sender, EventArgs e)
        {
            rating = Convert.ToDouble(txtrating.Text);//here rating value in variable
            if (rating > 0 && rating <= 5)//check if it is between 0 to 5
            {
                total += rating;//total calculate
                count++;//count increment
                txtrating.Text = "";//here is textbox blank
            }
            else if (rating < 0)//if value is negative then manager then average display
            {
                avg = total / count;
                lblavg.Text = "Average is here ="+Convert.ToString(avg);//display here
                txtrating.Text = "";//here is textbox blank
            }
            else
            {
                error_count++;
                if (error_count == 3)//check if three time
                {
                MessageBox.Show("Continues with a new user");//message for new message here
                error_count = 0;
                }
                txtrating.Text = "";//here is textbox blank
            }
          }

        private void Form1_Load(object sender, EventArgs e)
        {
            lblavg.Text = "";//null value in load time
        }
    }
}

output:

Forml.cs a ㄨ Form1.cs [Design] HollywoodMovie·Form 1 btnrating_Click(object sender, EventArgs e) Formi ble . Drag xt to ox. oForml.csa ·。 × Form1.cs [Design] box ρ , HollywoodMovie-Form 1 btnrating_Click(object sender, EventArgs e) Form 1 re no usablForml.cs a Form1.cs [Design] a ▼ | btnra ting-Click(object sender, EventArgs e) HollywoodMovieFormi Form1 Drag t to HollywoodHollywoodMovie.Form1 btnrating_Click(object sender, EventArgs e) Form 1 able up. Drag text to lbox. Hollywood Movie Rating GuForm 1-Load (object sender, EventArgs e) ▼ HollywoodMovie.Form1 Formi Hollywood Movie Rating Guide Rating Rating: Please Ente

Add a comment
Know the answer?
Add Answer to:
Practice C# Activity The purpose of this activity is to allow students to become accustomed to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT