Create private static int variables

Assignment Help Computer Engineering
Reference no: EM132157015

Use comments liberally to document exactly what you are doing in the program.

Use descriptive variable names in camel-case with the first letter in lowercase. If the instructions tell you to use a certain variable or method name, use that specific name.

Create private static int variables for maxNumberStudents and actualNumberStudents; these must be placed after the class statement and before the main method. Initialize both to zero.

Create a private static String [] variable for studentNames.

In the main method, ask the user for the maximum number of students and read it into maxNumberStudents, and instantiate the studentNames array by setting it equal to new String[maxNumberStudents].

You previously declared it as a private static String array, but it didn't equal anything at that point or even have an address in memory, in other words, it was null (in fact, you could have instantiated it in the same statement where you declared it, but at that time you had no idea of what the maximum number of students was). Now each of the array's elements is still null, but the array itself exists and has an address.

In a new method called enterStudentNames, use a for-loop with loop control variable actualNumberStudents (this was created as a static var earlier) to ask for all of the students' names by firstName and lastName into separate Strings. Tell the user to enter a period in firstName to signal that they are done entering students' names.

In a real application, you would have made an object called studentName and have the first and last names in separate fields, but you don't know how to do that yet, so you will build a full name called fullStudentName using concatenation with lastName, then comma, then blank, then firstName so that the entire name will be stored in a local String called fullStudentName.

Set the element at the position actualNumberStudents of studentNames to fullStudentName, that is:
studentNames[actualNumberStudents] = fullStudentName;

Test firstName to see if it is a period. Remember that you cannot use == with objects, and Strings are objects; see Notes below. If firstName is a period ".", then you are done accepting names (and don't enter a studentName of "."), and break out of the loop. When you get out of the loop, actualNumberStudents will reflect the actual number of students, which is why we called it that.

Call enterStudentNames from the main method.

Test this and get any bugs out before moving on.

Write a method called printStudentNames that will print out the array of students.

Call this method from your main method. Print one name per line at the beginning of each line. You should test that the element is not null before doing things with it.

You should NOT print blank lines (or anything else) for the empty/null elements at the end. If you hit a null element, you can break out of the loop because everything after that will be null also.

Call printStudentNames from the main method.

Test this and get any bugs out before moving on. Be sure to make a backup at this point.

In printStudentNames, also print the next counting number in front of each student's name along with a period and a space. Format this so that they all take up 2 spaces and the periods will all line up (also that will make the last names all line up). Test this and get any bugs out before moving on. Be sure to make a backup at this point.

Write another method called sortStudentNames that will sort the array by the student's names. Do NOT use any of the built-in sort methods; you MUST write your own.

I don't care which kind you write, but I would suggest that the bubble sort is easiest even though it's not very efficient. However, on short lists, efficiency is not usually a factor; even 1000 elements would be considered short for these purposes. Remember to test to see whether you've hit the end of actually used elements by testing whether the element == null. If so, you can treat it as if you hit the end of the array. Do NOT sort the empty elements; leave them at the end of the array. Call the sort method from your main method.

Then call the print method again. Test this and get all the bugs out. Contact me if you are having trouble. Be sure to make a backup at this point.

Test the program with the data that I use in the Sample Runs.

10% Extra Credit: In printStudentNames, make the first names line up by making the last names all take the same amount of space. Make the last names stay left-justified. You'll have to figure out how to split the names into first and last name again. This will involve using this statement:

int indexOfComma = studentNames[i].indexOf(',');
Then use the substr method with indexOfComma to split names[i] into the first and last names. You'll need to use the printf statement with the proper formatters. It might be a good idea to create another method to do this and call it from printStudentNames. That will help keep your code clean and readable.

Sample Runs: Enter this data exactly and make screen-prints to paste into a Word document that you will turn in to prove that your program works correctly. On the final first name, just hit the Enter key without entering anything:

Please enter the maximum number of students: 8

First name (enter period . to quit): Luke

Last name: Skywalker

First name (enter period . to quit): Darth

Last name: Vader

First name (enter period . to quit): Han

Last name: Solo

First name (enter period . to quit): R2D2

Last name: Droid

First name (enter period . to quit): 3CPO

Last name: Droid

First name (enter period . to quit): .

1. Skywalker , Luke

2. Vader , Darth

3. Solo , Han

4. Droid , R2D2

5. Droid , 3CPO

1. Droid , 3CPO

2. Droid , R2D2

3. Skywalker , Luke

4. Solo , Han

5. Vader , Darth

Reference no: EM132157015

Questions Cloud

What is the real interest rate : The nominal interest rate is 6.35%. The expected inflation rate is 2.20%. The actual inflation rate is 2.10%. What is the real interest rate?
Corporate bond default risk premium : What is the 10 year corporate bond's default risk premium if the risk free rate is 1%?
Statements is true regarding excel : Which of the following statements is True regarding excel?
Linear regression model : Consider the following linear regression model:
Create private static int variables : If the instructions tell you to use a certain variable or method name, use that specific name.
Which is nearest to the market value of the bond : The current market rate on bonds of this risk class is 12.1%. Which is nearest to the market value of the bond?
Development for new : You are considering investing in Tesla, which is in development for its new, more affordable Model III. Once in full production, sales are expected to grow
Computing the products of two 2-digit integers : You may exit the recursion when n = 2, i.e., computing the products of two 2-digit integers by the ordinary multiplication method.
What is the intrinsic value of a share today : After that, dividends are expected to grow at 10.6% per year indefinitely. The stock's required return is 14%. What is the intrinsic value of a share today?

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd