Question

In: Computer Science

Programming for business applications - (New to programming. Just learned arrays, for/if/ifelse/else, and tryParse method. Please...

Programming for business applications -

(New to programming. Just learned arrays, for/if/ifelse/else, and tryParse method. Please put comments so I am able to follow along with ease while doing this project.) C# is the language

Visual Studio 2019. Create a C# Console app (using .NET Framework)

Create a credit card console app. Each card has a Name, FICA score, and Credit Balance.

  • Prompt the user for the number of cards in this group
  • Declare/define 3 arrays (Names, FICA Scores, Balances) using the number entered by the user from 1 above
  • Prompt the user for the credit card user's Name, FICA score, and Credit Balance
    • Read in the input
    • Use TryParse when appropriate
    • If the input is invalid, loop until you get valid input
    • Names cannot be blank
    • FICA scores must be a value from 300 to 850 inclusive
    • Credit balance can be any valid decimal number ( positive or negative are okay)
    • Once the user's information is valid, put the data into the arrays
  • Display all the information to the console screen as shown below

   NAMES                      FICA          BALANCE

Ashley Bentley    700                $200.00

Berk Fields    850           $16,250.00

(the FICA scores and Balances are right aligned and the names are left aligned.)

Solutions

Expert Solution

Code:

Type1:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Main
{
public static void Main(string[] args)
{
  

Console.WriteLine("Enter the number of cards");
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Number= {0}",n);
string[] Names= new string[n];
int[] FicaScore = new int[n];
int[] Balance = new int[n];
  


  
for (int i = 0; i < n; i++)
{
Console.WriteLine("Enter user name");
string name=Console.ReadLine();
  
if(string.IsNullOrEmpty(name))
{
while (false)
{
Console.WriteLine("Please enter valid name");
Console.Beep();
}
  
}
else
{
Names[i] = name;
}

  
Console.WriteLine("Enter user FicaScore");
int score=Convert.ToInt32(Console.ReadLine());
if (score <350 || score >850)
{
Console.WriteLine("Please enter valid score between 350 and 850");
}
else
{
FicaScore[i] = score;
}

Console.WriteLine("Enter user Balance");
Balance[i] = Convert.ToInt32(Console.ReadLine());
}
  
Console.WriteLine("Name\t FicaScore\t Balance");
for(int j=0;j<n;j++)
{
  
Console.WriteLine("{0}\t {1}\t {2}\t",Names[j],FicaScore[j],Balance[j]);
}


}
  
}

Expalantion:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class ConsoleApp
{
public static void Main(string[] args)
{
  

Console.WriteLine("Enter the number of cards");

#asking input from number of cards and storing in n
int n = Convert.ToInt32(Console.ReadLine());

#Printing number of cards(you can ignore this if you don't want to display
Console.WriteLine("Number= {0}",n);

#initializing array with size n(i.e, n=number of cards)
string[] Names= new string[n];
int[] FicaScore = new int[n];
int[] Balance = new int[n];
  


#asking for input, and validating conditions for which we use for loop to perform operation for n number of times
for (int i = 0; i < n; i++)
{
Console.WriteLine("Enter user name");
string name=Console.ReadLine();
  

#IsNullOrEmoty is a function which accepts a string and returns true only if string not null or empty
if(string.IsNullOrEmpty(name))
{

#while loop is run untill valid name is given
while (false)
{
Console.WriteLine("Please enter valid name");
Console.Beep();
}
  
}

#if valid name is given then name is stored in array Names[i]
else
{
Names[i] = name;
}

  
Console.WriteLine("Enter user FicaScore");

#In c# input is read in string form so we are converting input to int using Convert.ToInt32
int score=Convert.ToInt32(Console.ReadLine());

#validating the score condition
if (score <350 || score >850)
{
Console.WriteLine("Please enter valid score between 350 and 850");
}

#else score is stored in array FicaScore[i]
else
{
FicaScore[i] = score;
}

Console.WriteLine("Enter user Balance");

#In c# input is read in string form so we are converting input to int using Convert.ToInt32
Balance[i] = Convert.ToInt32(Console.ReadLine());
}
  
Console.WriteLine("Name\t FicaScore\t Balance");

#Now we have to display the input, but the input is stored in arrays, so to traverse through array we take for loop
for(int j=0;j<n;j++)
{
#\t gives a tab space between each value
Console.WriteLine("{0}\t {1}\t {2}\t",Names[j],FicaScore[j],Balance[j]);
}


}
  
}

Snapshot of the input and the output obtained:

Input:

Output:

Type2:

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;


namespace ConsoleApplication
{
static class Program
{
public static void Main(string[] args)
{
int n;
Console.WriteLine("Enter the number of cards in this group");
if (Console.ReadLine()==null)
{
Console.WriteLine("Entergreater then zero");
}
else {
n = Int32.Parse(Console.ReadLine());
Method1(n);
}
  
  

}

public static void Method1(int n)
{
string[] Names = new string[n];
int[] FicaScores = new int[n];
int[] Balance = new int[n];
int input;
for (int i = 0; i < n; i++)
{
Console.WriteLine("Enter user name");
if (Console.ReadLine() == null) //Verify that input is not null
{
Console.WriteLine("Please enter user name.");
continue;
}
else
{
Names[i] = Console.ReadLine();
}

Console.WriteLine("Enter user FicaScore");
if (Int32.TryParse(Console.ReadLine(), out input) == true)
{
if (input < 350 && input > 850)
Console.WriteLine("Please enter score between 350 and 850");
}
else
{
FicaScores[i] = input;
}
Console.WriteLine("Enter user Balance");
Balance[i] = Int32.Parse((Console.ReadLine()));

Console.WriteLine("Name{i} \n FicaScore{i} \n Balance{i} \n",Names[i], FicaScores[i],
Balance[i]);
}


}
}
}


Related Solutions

This is for Java programming. Please use ( else if,) when writing the program) Write a...
This is for Java programming. Please use ( else if,) when writing the program) Write a java program to calculate the circumference for the triangle and the square shapes: The circumference for: Triangle = Side1 + Side2 +Sid3 Square = 4 X Side When the program executes, the user is to be presented with 2 choices. Choice 1 to calculate the circumference for the triangle Choice 2 to calculate the circumference for the square Based on the user's selection the...
The Business Club at Elk College Our VP of Marketing just learned the Business Club at...
The Business Club at Elk College Our VP of Marketing just learned the Business Club at Elk College (BCEB) is hosting the State Conference of Business Clubs on April 9 – 11, 2018 at the Central Downtown Campus in Dallas, Texas. Jack Morton director of the club has requested an Information System to register, monitor and house participants for the conference. BCEB has requested through the Director of Computer Systems Support that (You), one of our Marketing officers, investigate and...
Write 10-15 applications of each. (note formulas are not required, just applications) 1-Newton's Raphson Method 2-Langrange...
Write 10-15 applications of each. (note formulas are not required, just applications) 1-Newton's Raphson Method 2-Langrange Interpolation polynomial 3-Newton Divided Difference 10-15 applications of 1st topic 10 - 15 applications of 2nd topic 10-15 applications of 3rd topic
Lab # 4 Multidimensional Arrays Please write in JAVA. Programming Exercise 8.5 (Algebra: add two matrices)...
Lab # 4 Multidimensional Arrays Please write in JAVA. Programming Exercise 8.5 (Algebra: add two matrices) Write a method to add two matrices. The header of the method is as follows: public static double[][] addMatrix(double[][] a, double[][] b In order to be added, the two matrices must have the same dimensions and the same or compatible types of elements. Let c be the resulting matrix. Each element cij is aij + bij. For example, for two 3 * 3 matrices...
PLEASE USE ARRAYS IN JAVA TO ANSWER THIS Write a 'main' method that examines its command-line...
PLEASE USE ARRAYS IN JAVA TO ANSWER THIS Write a 'main' method that examines its command-line arguments and calls the (add) method if the first parameter is a "+" calls the (subtract) method if the first parameter is a "-" calls the (doubled) method if the first parameter is a "&" add should add the 2 numbers and print out the result. subtract should subtract the 2 numbers and print out the results. Double should add the number to itself...
You are an entrepreneur and just started a new business in the restaurant industry. The business...
You are an entrepreneur and just started a new business in the restaurant industry. The business must be hypothetical (made-up) for this assignment. Please propose a plan for protecting your hypothetical intellectual property (IP). Your plan should consist of the following information. Please keep in mind that you may find that some categories are more applicable than others. This is perfectly acceptable as long as you analyze each category.  Trademark Protection : Start by demonstrating your understanding of what...
I did the complete programming in python , just want to use tkinter for GUI. please...
I did the complete programming in python , just want to use tkinter for GUI. please look at the 2nd part . i did some part of this program using tkinter but could not finis it. Thank you. import random image = 'w' # modified functions which accepts two numbers each and returns the respective # output def add(a, b): return a + b def subtract(a, b): return a - b def multiply(a, b): return a * b def kidCalc():...
Please write a program in c++ The method sellProduct of the Juice Machine programming example gives...
Please write a program in c++ The method sellProduct of the Juice Machine programming example gives the user only two chances to enter enough money to buy the product. Rewrite the definition of the method sellProduct so that it keeps prompting the user to enter more money as long as the user has not entered enough money to buy the product. Also, write a program to test your method. Your program should produce the following example output: *** Welcome to...
You have just been made a valuation analyst. Before you get training (what else is new!),...
You have just been made a valuation analyst. Before you get training (what else is new!), your boss asks you to value a number of items: 1) a publicly-traded company; 2) a family business; 3) a shopping center; 4) an oil refinery; 5) a patent or trademark; and, by the way, 6) did the local tax assessor correctly value his house? How might you go about these tasks? While the course concentrates on the first two items, we will discuss,...
A new nail salon business just opened, in their first week of business they decided that...
A new nail salon business just opened, in their first week of business they decided that thy would conduct a promotion in which a customer's bill can be randomly selected to receive a discount. When a customer's bill is printed, a program in the cash register randomly determines whether the customer will receive a discount on the bill. The program was written to generate a discount with a probability of 0.2, that is, giving a discount to 20 percent of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT