Question

In: Computer Science

C# programming This application will calculate the speed of an interstellar spacecraft as it accelerates though...

C# programming

This application will calculate the speed of an interstellar spacecraft as it accelerates though our galaxy to explore the stars. The spacecraft is using a new engine technology that continues to accelerate over time with no limit, allowing the spacecraft to reach distant areas of the galaxy at record speed. The spacecraft starts out slowly, but for each day it accelerates, it will double the speed it has attained prior to that point. The spacecraft will accelerate from 0 MPD (Miles Per Day) at launch to 1000 MPD by the end of the first day, and will have covered 500 miles (average speed of (0 + 1000)/2= 500). At the end of day two, it will be up to 2000 MPD (double day one's speed), and will have covered 2000 miles total (the previous day’s 500 miles plus the new day’s average of (1000+2000)/2)). Create an app that allows the user to enter the number of days the spacecraft has been traveling and your app will use the formulae given, plus some looping code, to tell the user what the speed of the spacecraft is (in MPD) at the end of that day. Your app will also calculate the total distance traveled by the spacecraft to the end of that day (also done with the fomulae and some looping code). Create a form with the appropriate controls to get the user input and display the answers correctly. Ensure you do proper data validation so that any mistakes the user makes entering data do not crash the program or create/allow strange results

Solutions

Expert Solution

Code:

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 InterstellarSpaceCraftForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{


try
{
int days = Convert.ToInt16(textBox1.Text);
double speed = 1000;
double miles = 1000;
double totalKm = 0;

for (int i = 1; i <= days; i++)
{

miles = miles * i;
speed = miles / 2;
totalKm += miles;
listBox1.Items.Add(speed + " " + totalKm);
}

}
catch(Exception ex)
{
MessageBox.Show("Enter valid input");
textBox1.Text = "";
}
  
  

}
}
}

Designer:

namespace InterstellarSpaceCraftForm
{
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.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F);
this.label1.Location = new System.Drawing.Point(9, 129);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(272, 31);
this.label1.TabIndex = 0;
this.label1.Text = "Enter number of days";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(323, 140);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(108, 20);
this.textBox1.TabIndex = 1;
//
// button1
//
this.button1.Location = new System.Drawing.Point(171, 204);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(114, 38);
this.button1.TabIndex = 2;
this.button1.Text = "Calculate";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(84, 294);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(120, 95);
this.listBox1.TabIndex = 3;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(506, 405);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.ListBox listBox1;
}
}

Please rate it if the above solution helps you in any way or if you have any concerns comment it, I will help you through again.

Form1 - O X Enter number of days 5 | Calculate 500 1000 1000 3000 3000 9000 12000 33000 60000 153000


Related Solutions

A-Calculate the speed of a proton after it accelerates from rest through a potential difference of...
A-Calculate the speed of a proton after it accelerates from rest through a potential difference of 220V . B-Calculate the speed of an electron after it accelerates from rest through a potential difference of 220V .
what will be the code in C programming for the client and server chat application for...
what will be the code in C programming for the client and server chat application for the below issue :- write the C Programming code that able client have a unique ID to be known by the server
C# Programming Discuss how to build a Multi-Form Windows application in C#. That is an App...
C# Programming Discuss how to build a Multi-Form Windows application in C#. That is an App that has more than one form, like say maybe 5 forms. How do you connect these forms and pass data objects between these forms?
(a) What is the minimum speed, relative to the Sun, necessary for a spacecraft to escape...
(a) What is the minimum speed, relative to the Sun, necessary for a spacecraft to escape the solar system if it starts at the Earth's orbit? km/s (b) Voyager 1 achieved a maximum speed of 125,000 km/h on its way to photograph Jupiter. Beyond what distance from the Sun is this speed sufficient to escape the solar system? m
You have a spacecraft that is capable of reaching a speed of 0.99c and desire to...
You have a spacecraft that is capable of reaching a speed of 0.99c and desire to travel to Vega, a nearby star about 25 light years away. In order to keep track of your position, your spacecraft sends out a flash of light every second (by your ship’s clock) during the journey that can be picked up on Earth. In addition, the Earth sends out a flash every second (by the Earth clock) that you can see with a telescope...
If an object accelerates for infinite time, then it will in the end reach speed of light.
I have some question about relativistic features of objects which moves with speed of light. If an object accelerates for infinite time, then it will in the end reach speed of light. Then, to make it clear, assume a rocket with infinite power source (source is also assumed to be massless) that accelerates in space, or vacuum without any disturbance in its motion. Also assume that there is another rocket same as the one mentioned above and, in vacuum, it...
Implement the following socket programming in C (b) Chat Application using TCP
Implement the following socket programming in C (b) Chat Application using TCP
programming language is c#. Create a method that prompts a user of your console application to...
programming language is c#. Create a method that prompts a user of your console application to input the information for a student: static void GetStudentInfo() { Console.WriteLine("Enter the student's first name: "); string firstName = Console.ReadLine(); Console.WriteLine("Enter the student's last name"); string lastName = Console.ReadLine(); // Code to finish getting the rest of the student data ..... } static void PrintStudentDetails(string first, string last, string birthday) { Console.WriteLine("{0} {1} was born on: {2}", first, last, birthday); } 1. Using the...
2.1) What is the speed of an electron that accelerates from rest starting close to the...
2.1) What is the speed of an electron that accelerates from rest starting close to the negative plate of a capacitor just before it hits the positive plate? The electric field between the plates is 300 V/m and the distance between the plates is 0.050 m. 3.25 x 106 m/s 2.30 x 106 m/s 5.28 x 1012 m/s 2.64 x 1012 m/s 2.2) A charge of +2.00 nC is on the Y axis at the point (0, 2.00) m. A...
This is C# programming. In Chapter 2, you created an interactive application named GreenvilleRevenue. The program...
This is C# programming. In Chapter 2, you created an interactive application named GreenvilleRevenue. The program prompts a user for the number of contestants entered in this year’s and last year’s Greenville Idol competition, and then it displays the revenue expected for this year’s competition if each contestant pays a $25 entrance fee. The programs also display a statement that compares the number of contestants each year. Now, replace that statement with one of the following messages: If the competition...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT