Question

In: Computer Science

ISYS 350, Assignment 2, Part 1: Create a C# Form with a textbox and a button....

ISYS 350, Assignment 2,

Part 1:

Create a C# Form with a textbox and a button. The box is for a user to enter a number

of seconds. And when the user clicks the button, the program displays the equivalent

number of hours, minutes and seconds using a MessageBox. Show method. If the

seconds entered is less than 60, your program should only display the seconds; if the

seconds is a least 60 and less than 3600, your program should display minutes and

seconds; if the second is at least 3600, your program should display hours, minutes

and seconds.

Use the following data to test your program:

47 seconds: 47 seconds (don’t show 0 hour and 0 minute)

645 seconds: 10 minutes, 45 seconds (don’t show 0 hour)

7565 seconds: 2 hours, 6 minutes, 5 seconds

Requirements:

1. Input validation: The number of seconds cannot exceed 86400. You must use

textbox’s Validating event to do the validation.

2. Turn in the form’s screenshot and the code. (Note: You can use the Alt

+ PrintScrn keys to capture only the active window.)

Part 2: An electric company charges to their customers based on Kilowatt-Hours

(Kwh) used. The rules to compute the charge are:

First 100 Kwh, 35 cents per Kwh

Each of the next 100 Kwh (up to 200 Kwh), 45 cents per Kwh

(the first 100 Kwh used is still charged at 35 cents each)

Each of the next 300 Kwh (up to 500 Kwh) 65 cents per Kwh

All Kwh over 500, 80 cents per KH

Create a C# Form with a textbox to enter Kwh used, a read-only textbox to display the

electricity charges, and a button to compute the charges. The Kwh used could be a

number with decimals.

Requirements:

1. Input validation: Use the KWH textbox validating event to ensure the KWH cannot

exceed 2000. Test your program with (1) Kwh=4500, (2) Kwh = 350

2. Turn in the form’s screenshot and the code

Solutions

Expert Solution

Code:-

1)

using System;

using System.Windows.Forms;

namespace ProgramToConvertSecondsToMinutesHours

{

    public partial class CalculteTime : Form

    {

        int mySeconds;

        public CalculteTime()

        {

            InitializeComponent();

        }

        private void btnTime_Click(object sender, EventArgs e)

        {

            mySeconds = System.Convert.ToInt32(txtTime.Text);

            MessageBox.Show(ConvertToTime(mySeconds));

        }

        public string ConvertToTime(int timeInSeconds)

        {

            int myHours = mySeconds / 3600;

            mySeconds %= 3600;

            int myMinutes = mySeconds / 60;

            mySeconds %= 60;

            string mySec = mySeconds.ToString(),

            myMin = myMinutes.ToString(),

            myHou = myHours.ToString();

            if(myHours < 10)

            {

                myHou = myHou.Insert(0, "0");

            }

            if(myMinutes < 10)

            {

                myMin = myMin.Insert(0, "0");

            }

            if(mySeconds < 10)

            {

                mySec = mySec.Insert(0, "0");

            }

            if(myMinutes == 0 && myHours == 0)

            {

                return mySec + " Seconds";

            }

            else if (myHours == 0)

            {

                return myMin + " Minutes" + " ," + mySec + " Seconds";

            }

            else

            {

                return myHou + " Hours" + " , " + myMin + " Minutes" + " , " + mySec + " Seconds";

            }

        }

        private void txtTime_MouseLeave(object sender, EventArgs e)

        {

            mySeconds = System.Convert.ToInt32(txtTime.Text);

            if (mySeconds > 86400)

            {

                MessageBox.Show("Enter valid time in seconds (less than 86400)");

            }

        }

    }

}

Code Screenshots:-

2)

using System;

using System.Windows.Forms;

namespace ProgramToConvertSecondsToMinutesHours

{

    public partial class Electricity_Charge : Form

    {

        public Electricity_Charge()

        {

            InitializeComponent();

        }

        private void Electricity_Charge_Load(object sender, EventArgs e)

        {

        }

        private void txtElectricity_MouseLeave(object sender, EventArgs e)

        {

            double electricityInKwh = double.Parse(txtElectricity.Text);

            if (electricityInKwh > 2000)

            {

                MessageBox.Show("Electricity value can not exceed than 2000");

            }

        }

        private void btnCharge_Click(object sender, EventArgs e)

        {

            double electricityInKwh = double.Parse(txtElectricity.Text);

            txtElectricityCharge.Text=calculateCharge(electricityInKwh);

        }

        public string calculateCharge(double electricityInKwh)

        {

            double amount;

            if (electricityInKwh <= 100)

            {

                amount = electricityInKwh * 35;

            }

            else if (electricityInKwh <= 200)

            {

                amount = 2500 + ((electricityInKwh - 100) * 45);

            }

            else if (electricityInKwh <= 500)

            {

                amount = 6000 + ((electricityInKwh - 200) * 65);

            }

            else

            {

                amount = 16000 + ((electricityInKwh - 500) * 80);

            }

            return amount.ToString();

        }

    }

}

Code Screenshots:-

Please UPVOTE thank you...!!!


Related Solutions

Using Visual Basic 2017, Create a form with two textboxes and one button. A user enters...
Using Visual Basic 2017, Create a form with two textboxes and one button. A user enters the course she is taking in the first text box and then clicks on the button. Then if the user entered "Program Language" in the first text box, the second text box will show "Awesome pick!". If the user entered something else, the text box shows "Ok." Please write the correct code.
Database Application Development Project/Assignment Milestone 1 (part 1) Objective: In this assignment, you create a simple...
Database Application Development Project/Assignment Milestone 1 (part 1) Objective: In this assignment, you create a simple HR application using the C++ programming language and Oracle server. This assignment helps students learn a basic understanding of application development using C++ programming and an Oracle database Submission: This Milestone is a new project that simply uses what was learned in the SETUP. Your submission will be a single text-based .cpp file including your C++ program for the Database Application project/assignment. The file...
Assignment 2: Create a form that collects 5 different pieces of data. Once the user clicks...
Assignment 2: Create a form that collects 5 different pieces of data. Once the user clicks the submit button, the processing PHP file displays the data that was entered thru the form, performs a calculation, and displays the result. To receive full credit, students need to implement the following: Create variables with valid names and assign values to them Use literals and concatenate strings Use $_POST Use echo statements to display data on a page Code string and numeric expressions...
For Part 2 of this assignment, you will use the “Assignment 1 – Linear Kinematics Data”...
For Part 2 of this assignment, you will use the “Assignment 1 – Linear Kinematics Data” excel file. In the data set you are provided with vertical position and time data for a person’s vertical center of mass motion for an unspecified movement task. You will utilize excel in all (well, some…) of its glory to calculate the vertical velocity and vertical acceleration data from the position and time data provided in the excel file. Again you will use the...
FINC 350 – Attribution Assignment 1. What is the purpose of macro-attribution analysis? 2. Identify the...
FINC 350 – Attribution Assignment 1. What is the purpose of macro-attribution analysis? 2. Identify the categories in the attribution analysis and what they represent. 3. The Fund has a 2% policy-weight to emerging market equities – a sub-category within the international equity bucket. The broad category benchmark is MSCI-EAFE and has a 20% policy weight. MSCI-EAFE returned 2.5% and MSCI-EME returned 3.5% during the last month. What is the style-bias impact? Show calculations. 4. Instead of a passive ETF,...
Part 1: answer (a), (b), (c), and (d). Part 2: answer (a), (b), (c), and (d)....
Part 1: answer (a), (b), (c), and (d). Part 2: answer (a), (b), (c), and (d). Godspeed, and good luck!!! CC11 Cookie Creations Natalie and her friend Curtis Lesperance decide that they can benefit from joining Cookie Creations and Curtis’s coffee shop. In the first part of this problem, they come to you with questions about setting up a corporation for their new business. In the second part of the problem, they want your help in preparing financial information following...
JAVA programming - please answer all prompts as apart of 1 java assignment. Part A Create...
JAVA programming - please answer all prompts as apart of 1 java assignment. Part A Create a java class InventoryItem which has a String description a double price an int howMany Provide a copy constructor in addition to other constructors. The copy constructor should copy description and price but not howMany, which defaults to 1 instead. In all inheriting classes, also provide copy constructors which chain to this one. Write a clone method that uses the copy constructor to create...
The cost of NOT performing 2 cycles of photorespiration is 1 C in the form of...
The cost of NOT performing 2 cycles of photorespiration is 1 C in the form of CO2 4 C in the form of 2 molecules of phosphoglycolate 1 C (as CO2), 2 ATP, 2 NADPH equivalents, and one molecule of NH4+ 3 ATP and 2 NADPH 5 ATP and 2 NADPH As temperature increases, the quantum yield of photosynthesis in C3 plants is directly affected by The decreasing ratio of CO2 to O2 in the aqueous phase The increasing ratio...
Please Use JavaScript and P5 1) Greeter Create an page with an input, and a button....
Please Use JavaScript and P5 1) Greeter Create an page with an input, and a button. When the button is clicked, output the phrase "Hello {Name}" to the developer console, with {Name} being the value the user put into the input field. Use a function that takes the name as an argument, and returns the full phrase as its output.
C++ Assignment 1: Make two classes practice For each of the two classes you will create...
C++ Assignment 1: Make two classes practice For each of the two classes you will create for this assignment, create an *.h and *.cpp file that contains the class definition and the member functions. You will also have a main file 'main.cpp' that obviously contains the main() function, and will instantiate the objects and test them. Class #1 Ideas for class one are WebSite, Shoes, Beer, Book, Song, Movie, TVShow, Computer, Bike, VideoGame, Car, etc Take your chosen class from...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT