Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Microsoft Visual C# 7th edition. In Chapter 7, you modified the GreenvilleRevenue program to include a number of methods.
Now, using your code from Chapter 7 Case Study 1, modify your program so every data entry statement uses a TryParse() method to ensure that each piece of data is the correct type.
Any invalid user entries should generate an appropriate message that contains the word Invalid, and the user should be required to reenter the data.
I am working in CENGAGE MINDTAP. Here is my code, but the TryParse is not working. I am not getting the point for TryParse. thanks
using System;
using static System.Console;
using System.Globalization;
class GreenvilleRevenue
{
static void Main()
{
int numLastYear;
int numThisYear;
double revenue;
int fee = 25;
const int MAX_CONTESTANTS = 30;
string[] names = new string[MAX_CONTESTANTS];
char[] talents = new char[MAX_CONTESTANTS];
char[] talentCodes = { 'S', 'D', 'M', 'O' };
string[] talentCodesStrings = { "Singing", "Dancing", "Musical instrument", "Other" };
int[] counts = { 0, 0, 0, 0 }; ;
numLastYear = GetContestantNumber("last", 0, 30);
numThisYear = GetContestantNumber("this", 0, 30);
WriteLine("Last year's competition had {0} contestants, and this year's has {1} contestants", numLastYear, numThisYear);
revenue = (numThisYear * fee);
WriteLine("Revenue expected this year is {0}", revenue.ToString("C", CultureInfo.GetCultureInfo("en-US")));
DisplayRelationship(numThisYear, numLastYear);
GetContestantData(numThisYear, names, talents, talentCodes, talentCodesStrings, counts);
GetLists(numThisYear, talentCodes, talentCodesStrings, names, talents, counts);
}
public static int GetContestantNumber(string when, int min, int max)
{
int contestants;
string contestantString;
WriteLine("Enter number of contestants {0} year >> ", when);
contestantString = ReadLine();
while(! int.TryParse(contestantString, out contestants))
{
WriteLine("Invalid");
WriteLine("Reenter the valid constestants number");
contestantString = ReadLine();
}
return contestants;
}
public static void DisplayRelationship( int numThisYear2, int numLastYear2)
{ if (numThisYear2 > 2 * numLastYear2)
WriteLine("The competition is more than twice as big this year!");
else
if (numThisYear2 > numLastYear2)
WriteLine("The competition is bigger than ever!");
else
if (numThisYear2 < numLastYear2)
WriteLine("A tighter race this year! Come out and cast your vote!"); }
public static void GetContestantData(int numThisYear, string[] names, char[] talents, char[] talentCodes, string[] talentCodesStrings, int[] counts)
{ int x = 0;
bool isValid;
string talentString;
while (x < numThisYear)
{ Write("Enter contestant name >> ");
names[x] = Console.ReadLine();
WriteLine("Talent codes are:");
for (int y = 0; y < talentCodes.Length; ++y)
WriteLine(" {0} {1}", talentCodes[y], talentCodesStrings[y]);
Write(" Enter talent code >> ");
talentString = ReadLine();
while(! char.TryParse(talentString, out talents[x]))
{ WriteLine(" Invalid format - entry must be a single character");
WriteLine("That is not a valid code");
Write(" Enter talent code >> ");
talentString = ReadLine();}
talents[x] = GetChar();
isValid = false;
while (!isValid)
{for (int z = 0; z < talentCodes.Length; ++z)
{
if (talents[x] == talentCodes[z])
{isValid = true;
++counts[z];
}
}
if (!isValid)
{WriteLine("{0} is not a valid code", talents[x]);
Write(" Enter talent code >> ");
talents[x] = GetChar();
}
}
++x;
}
}
public static void GetLists(int numThisYear, char[] talentCodes, string[] talentCodesStrings, string[] names, char[] talents, int[] counts)
{int x;
char QUIT = 'Z';
char option;
bool isValid;
int pos = 0;
bool found;
WriteLine("\nThe types of talent are:");
for (x = 0; x < counts.Length; ++x)
WriteLine("{0, -20} {1, 5}", talentCodesStrings[x], counts[x]);
WriteLine("\nEnter a talent type or {0} to quit >> ", QUIT);
option = GetChar();
while (option != QUIT)
{ isValid = false;
for (int z = 0; z < talentCodes.Length; ++z)
{if (option == talentCodes[z])
{ isValid = true;
pos = z;
}
}
if (!isValid)
WriteLine("{0} is not a valid code", option);
else
{ WriteLine("\nContestants with talent {0} are:", talentCodesStrings[pos]);
found = false;
for (x = 0; x < numThisYear; ++x)
{ if (talents[x] == option)
{WriteLine(names[x]);
found = true;}
}
if (!found)
Console.WriteLine("No contestants had talent {0}", talentCodesStrings[pos]);
}
WriteLine("\nEnter a talent type or {0} to quit >> ", QUIT);
option = GetChar();
}
}
private static char GetChar()
{char validChar = '0';
bool isValidChar = false;
var charInput = string.Empty;
while (!isValidChar)
{ charInput = Console.ReadLine();
isValidChar = Char.TryParse(charInput, out validChar);
if (!isValidChar)
{
WriteLine("Invalid character - Please try again by entering one character!");
/* WriteLine("Invalid format - entry must be a single character");
}
else
WriteLine("That is not a valid code");*/
}
}
return validChar;-
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Computer Science JAVA #7 - program that reads the file named randomPeople.txt sort all the names alphabetically by last name write all the unique names to a file named namesList.txt , there should be no repeatsarrow_forwardPart 3. arange Method Define a method in simpy named arange. Its purpose is to fill in the values attribute with range of values, like the range built-in function, but in terms of floats. It has three parameters in addition to self, the last being optional: 1. start - a float indicating the first value in the range 2. stop - a float that is not included in the produced range values 3. step - a float whose default value is 1.0 that indicates how to increase (or decrease) each subsequent item in the generated range. Unlike the built- in range function, this can be a fractional, float value. Step cannot be 0.0. Think carefully about what the value of step tells you about how to design your loop(s) for this method. Before any looping, you should assert step != 0.0 to be sure you avoid an infinite loop with an invalid argument. positive = Simpy([]) positive.arange(1.0, 5.0) print("Actual: ", positive, " - Expected: Simpy([1.0, 2.0, 3.0, 4.0])") fractional = Simpy([]) positive.arange (0.0,…arrow_forwardJavaDriver Program Write a driver program that contains a main method and two other methods. Create an Array of Objects In the main method, create an array of Food that holds at least two foods and at least two vegetables. You can decide what data to use. Method: Print Write a method that prints the text representation of the foods in the array in reverse order (meaning from the end of the array to the beginning). Invoke this method from main. Method: Highest Sugar Food Write a method that takes an array of Food objects and finds the Food that has the most sugar. Note that the method is finding the Food, not the grams of sugar. Hint: in looping to find the food, keep track of both the current highest index and value. Invoke this method from main.arrow_forward
- A for construct is a loop construct that processes a specified list of objects. As a result,it is executed as long as there are remaining objects to process. True or False?arrow_forwardPLEASE COMMENT CODE In a python program, create a new file and call it “ tracking”. Write to it four lines each contains information about an order like this: 1-00654-021 Dell charger Toronto-WEST 99-49-ZAD011-76540-022 ASUS battery Milton-EAST 34-56-CBH561-09239-026 HP HD Scarborough-NORTH 12-98-AZC451-12349-029 Mac FD North York-LAWRENCE 34-49-ZWL01Add the file two more lines: 1-34567-055 Lenovo SSD Milton-ON 34-09-MT04 1-90432-091 Lenovo battery Oakville-ON 78-KL98 Define a function that searches for a brand (e.g. Dell, ASUS, etc.). Test the function in your program.arrow_forwardPlease create a Java class that has the following data attributes and methods: private int count - number of customers in the array private customer Record[] data - array of customerRecord objects public customer List() constructor that should initialize memory for data array and count value public void getCustomerList(String fileName) - reads a file call fileName which is a text file containing lines (records) of customer data. This method fills the data array with the records from the file. The file will not have more than 100 records and will have the following format (where customer Number is an integer, firstName and lastName are Strings, and balance is a float: customerNumber firstName lastName balance public customerRecord getCustomer(int customerNumber) - returns the object corresponding to the customer with customerNumber. If the customer number is not in the array, return null. public void enter CustomerRecord(customerRecord new_record)…arrow_forward
- A file USPopulation.txt contains the population of the US starting in year 1950 and then each subsequent record has the population for the following year. USPopulation.txtDownload USPopulation.txt Write a program that uses an array with the file that displays these in a menu and then produces the results. This is not an Object Oriented Program but should be a procedural program, calling methods to do the following: 1: Displays the year and the population during that year 2. The average population during that time period (Add up the populations of all records and divide by the number of years). 3. The year with the greatest increase in population - print the year and that population and that amount. To figure this out, compare the difference in population before of say year 1950 and 1951, store that difference somewhere. Compare 1951 with 1952, find that difference. Is that difference greater than the stored difference? If so, move that the the maximum place. 4.…arrow_forwardYou have the following workspace in MATLAB: Workspace Name Value Beccentricity Egrav_const Binclination Emass_Earth Horbit_period Bradius_Earth E semi_major E spacecraft_loc 6918900 E spacecraft_vel 7.5883e+03 2.8300e-04 6.6730e-11 28.4700 5.9720e+24 95.4320 6378000 6917100 In the box below, fill in the exact command necessary to delete the variable spacecraft_vel from the workspace without deleting any other variables clear spacecraft_vel Question 2 In MATLAB, you are calculating friction forces on five rail materials for a comparison study. One variable you must define is the time traveled on the aluminum rail. Which of the following are appropriate, descriptive variable names that could be used for this variable? Select all that apply. timeAl alum time Alt U aluminum timearrow_forwardWhen we use the Group-Object cmdlet, it will create this new property, which displays the number of objects in each grouping: Group of answer choices Number Count Entry Namearrow_forward
- Microsoft Visual C# 7th edition. In Chapter 7, you modified the GreenvilleRevenue program to include a number of methods. Now, using your code from Chapter 7 Case Study 1, modify your program so every data entry statement uses a TryParse() method to ensure that each piece of data is the correct type. Any invalid user entries should generate an appropriate message that contains the word Invalid, and the user should be required to reenter the data. Cengage requirement for the shaded part is attached and I don't understand it. I need help with the highlighted part (getContestantData() method) please. Thanks using System; using static System.Console; using System.Globalization; class GreenvilleRevenue { static void Main() { int numLastYear; int numThisYear; double revenue; int fee = 25; const int MAX_CONTESTANTS = 30; string[] names = new string[MAX_CONTESTANTS]; char[] talents = new char[MAX_CONTESTANTS]; char[] talentCodes = { 'S', 'D', 'M', 'O'…arrow_forwardJAVA I cannot figure this one out no matter what I do I cannot get it to run. Please write it in a student way not in an too advance way. Write an application containing three parallel arrays that hold 10 elements each. The first array hold four-digit student ID numbers, the second array holds first names, and the third array holds the students’ grade point averages. Use dialog boxes to accept a student ID number and display the student’s first name and grade point average. If a match is not found, display an error message that includes the invalid ID number and allow the user to search for a new ID number.arrow_forwardplease write in javaarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education