Advertisement

06.15.2008 at 09:25AM PDT, ID: 23486331
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

Help with programming project

Asked by Hueydude in JavaScript

Tags:

I am writing a project for school and am at an impasse. I can't seem to get the data from my input file into my array. My values seem to be returning the default values only.

The problem is as follows

# Write a class Name that stores a person's first, middle, and last names and provides the following methods:

    * public Name(String first, String middle, String last) -- constructor. The name should be stored in the case given; don't convert to all upper or lower case.
    * public String getFirst() -- returns the first name
    * public String getMiddle() -- returns the middle name
    * public String getLast() -- returns the last name
    * public String firstMiddleLast() -- returns a string containing the person's full name in order, e.g., "Mary Jane Smith".
    * public String lastFirstMiddle() -- returns a string containing the person's full name with the last name first followed by a comma, e.g., "Smith, Mary Jane".
    * public String initials() -- returns the person's initials (a 3-character string). The initials should be all in upper case, regardless of what case the name was entered in. (Hint: Instead of using charAt, use the substring method of String to get a string containing only the first letter -- then you can upcase this one-letter string. See  in the text for a description of the substring method.)

 
# Now write a program TestNames.java that reads in ten names from an input file (you'll need first, middle, and last for each), creates a Name object for each, and uses the methods of the Name class to do the following:

    * displays the person's full name and initials on the screen(a 3-character string). The initials should be all in upper case, regardless of what case the name was entered.  For example:

      Mary Jane Smith MJS
      john donald doe JDD

       
    * writes the last-first-middle version (e.g., "Smith, Mary Jane"  )of each name in the input file to an output file.


I am not too concerned about the writing to a file yet. I can figure that out I think. My biggest problem is trying to find out why my input does not go into the array (or if it is why I can't access it)
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
public class Name
   {
      private String first;//First name
      private String middle;//Middle name
      private String last;//Last name
      private String initials;//Three character initials                   
    // ------------------------------------------------------------
   //   Default constructor - to initialize the variables
   // ------------------------------------------------------------
       Name(){
         first = "Tom";
         middle = "Jim";
         last = "Bob";             
         initials = "jjb";
      }
      private String newFirst , newMiddle, newLast ; // Name parts
   
   // ------------------------------------------------------------
   // Another constructor - with three parameters - if you know the first and middle and last name
   // ------------------------------------------------------------
       Name(String first, String middle, String last){
         first = newFirst;
         middle = newMiddle;
         last = newLast;   
      }
   
     
   
   // ------------------------------------------------------------
   //   Accessor methods
   // ------------------------------------------------------------
   
       public String getFirst(){
         return first;
      }
       public String getMiddle(){
         return middle;
      } 
       public String getLast(){
         return last;
      }
         
   
   // ------------------------------------------------------------
   //   Mutator methods
   // ------------------------------------------------------------
       public void setFirst(String newFirst){
         first = newFirst;
      }
       public void setMiddle(String newMiddle){
         middle = newMiddle;
      }
   
       public void setLast(String newLast){
         last = newLast;
      }
       public String firstMiddleLast(){
         return first + " " + middle + " " + last;
      }
   
   
   // ---------------------------------------------------------
   // Return the Initials
   // ---------------------------------------------------------
       public String initials(){
         return first.substring(0,1).toUpperCase()+
            middle.substring(0,1).toUpperCase()+
            last.substring(0,1).toUpperCase();
      
                  
                        
      }
   
   
        
   }// End Class
 
 
import java.util.Arrays;                
 
    public class TestName{
    
    
       
   
     // ---------------------------------------------------------
       public static void main(String[] args) throws Exception {
      // Create a File instance
         java.io.File file = new java.io.File("names.txt");
       
        // Name[]nameArray;
        
       //  nameArray = createNameArray();
         
        //Print Name Array
       //  printNameArray(nameArray);
                 
      // Create a Scanner for the file
         java.util.Scanner input = new java.util.Scanner(file);
      
      // Read data from a file
         while (input.hasNext()) {
            String first = input.next();
            String middle = input.next();
            String last = input.next();
                
            Name[]nameArray;
         
            nameArray = createNameArray();
            printNameArray(nameArray);
          //System.out.println(first + " " + middle + " " + last + " " + "nameArray[i].initials()");
         }
        
      // Close the file
         input.close();
      }
         
        
      public static Name[] createNameArray() {
         Name[]nameArray = new Name[10];//create an object
         int j = 0;
         for (int i = 0; i < nameArray.length; i++, j++) {
            nameArray[j] = new Name();
         }
         return nameArray; //Return Name Array
         
        
      }
    
       public static void printNameArray
       (Name[] nameArray){
         int j = 0;
         for (int i = 0; i < nameArray.length; i++, j++) {
         
           //nameArray = java.util.Arrays.toString(nameArray[j]);
            System.out.println(nameArray[j] + nameArray[j].initials());
           //  System.out.println(java.util.Arrays.toString(nameArray[j]));
         }
         
      }
   }
Attachments:
 
File input of names
 
[+][-]06.15.2008 at 10:15AM PDT, ID: 21789079

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.15.2008 at 10:31AM PDT, ID: 21789115

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.15.2008 at 10:39AM PDT, ID: 21789139

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.15.2008 at 10:49AM PDT, ID: 21789168

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.15.2008 at 10:57AM PDT, ID: 21789186

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.15.2008 at 11:20AM PDT, ID: 21789247

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.15.2008 at 11:50AM PDT, ID: 21789341

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.15.2008 at 02:22PM PDT, ID: 21789763

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: Java Script
Sign Up Now!
Solution Provided By: Airyck666
Participating Experts: 3
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628