Discount Get CS 520 ALL WEEKS Solution ONLY $154.91
CS520, CIS 520, CIS 520 Week 1 assignment - iLab 1 - Lab 1 - Java... [$8.99]
CS520, CIS 520, CIS 520 Week 2 assignment Part 1 - iLab 2 - Lab 2... [$11.99]
CS520, CIS 520, CIS 520 Week 2 assignment Part 2 - iLab 2 - Lab 2... [$15.99]
CS520, CIS 520, CIS 520 Week 2 assignment Part 3 - iLab 2 - Lab 2... [$19.99]
CS520, CIS 520, CIS 520 Week 3 assignment Part 1 - iLab 3 - Lab 3... [$15.99]
CS520, CIS 520, CIS 520 Week 3 assignment Part 2 - iLab 3 - Lab 3... [$19.99]
CS520, CIS 520, CIS 520 Week 4 assignment Part 1 and Part 2 - iLa... [$21.99]
CS520, CIS 520, CIS 520 Week 5 assignment - iLab 5 - Lab 5 - Java... [$19.99]
CS520, CIS 520, CIS 520 Week 6 assignment - iLab 6 - Lab 6 - Java... [$19.99]
Get Selected Weeks Solution with ONLY NOT Add Selected Tutorials To Cart
CS520, CS 520, CS 520 Week 4 assignment Part 1 and Part 2 - iLab 4 - Lab 4 - Java Programming
    CS520, CS 520, CS 520 Week 4 assignment Part 1 and Part 2 - iLab 4 - Lab 4 - Java Programming CS520, CS 520, CS 520 Week 4 assignment Part 1 and Part 2 - iLab 4 - Lab 4 - Java Programming CS520, CS 520, CS 520 Week 4 assignment Part 1 and Part 2 - iLab 4 - Lab 4 - Java Programming

CS520, CS 520, CS 520 Week 4 assignment Part 1 and Part 2 - iLab 4 - Lab 4 - Java Programming

$21.99

Part 1 (40 Points) – Strings

Create a package named cs520.hw4.part1. Using this package, create the class StringTest and implement the specified functionality in its main method.

a. Ask the user, through a single input dialog, for the user’s first name, last name, and age in the format 
FirstName,LastName,Age

b. Trim the user’s input, in case spaces were entered at the beginning or at the end.

c. Display the trimmed data to the console. Do the following operations using this trimmed string.

d. Find the index of the first comma in the input using the indexOf method. Using this value, extract the first name part of the input using the substring method.

e. Display the position of the first comma, the first name, and the length of the first name to the console.

f.   Find the index of the second comma in the input using the indexOf method. Using this value, extract the last name part of the input using the substring method.
g. Display the position of the second comma, the last name, and the length of the last name to the console.

h. Extract the age using the substring method. Convert the value to an integer. Display the age in 10 years from now.

Now, examine the code for all possible exceptions that could occur. Using a single try-catch construct, handle all the different exceptions explicitly and print out the exception message.
Also, test the following inputs where exceptions will occur and your program handles them gracefully -- when Cancel is clicked, when only the first name is entered, when only the first name and the last name are entered, and when all the three values are specified but the age is not an integer

Part 2 (60 Points) – StringTokenizer and File Input

Create a package named cs520.hw4.part2. Using this package, create the following classes.

 Create a class named Student as follows. The class keeps track of the student’s homework grades.
The instance (or member) private variables – name (String), homework1, homework2, homework3, homework4, homework5 and homework6 (all of type integer).
A single constructor with name as its argument.
The public set methods for the six homework instance variables. The get methods are optional.
A public computeAverage method which takes no arguments and returns a double showing the average homework grade for this student.
Override the toString method to return the string representation of this object in the format “The <studentName>’s average grade is <the computed average>”.
 

 Create a Test class to test the following functionality in its main method.

a.Use the BufferedReader class to read the data.txt file. The contents of the file are shown below. Create the data.txt file in HW4_lastName.

b.Read the contents of the text file one line at a time using a loop. The program should work for any number of input lines. Invoke the processInputData method for each line read.

c. Write a private method processInputData which processes its string input argument as follows.

Tokenize the string argument using the StringTokenizer class using the comma as the delimiter.
Extract the name token. Create a Student object and assign to the variable currentStudent.
Read each homework grade token one token at a time. Use the corresponding set method on the student object to set the instance value.
Display the string representation of the currentStudent object to the console.
       Sample Input data.txt file:

 Alice,44,79,85,72,77,57

Bob,79,94,70,71,71,51

Charlie,95,99,41,55,65,50

Dave,87,89,88,55,74,63

Ed,82,51,44,67,73,49  

My tutorial contains Java Programs - Eclipse Project and Document.

If you have more questions, please contact me via email support@extutorials.com

I will help you any time

Thank you !

Attached Files

Move over [ preview ] file name to preview content in it!

  • HW4_lastname.zip [11KB]
    • .classpath
      • .project
        • .settings
        • bin
        • data.txt [0.1KB] [ preview ]
        • src
          • cs520
            • hw4
              • part1
                • StringTest.java [1.3KB] [ preview ]
              • part2
                • Student.java [0.8KB] [ preview ]
                • Test.java [1.4KB] [ preview ]

      Write a review

      Your Name:


      Your Review: Note: HTML is not translated!

      Rating: Bad           Good

      Enter the code in the box below:



      Tags: CS520, CS 520
      PURCHASE SAVE
      2 Tutorials 10%
      3 Tutorials 13%
      4 Tutorials 16%
      5 Tutorials 19%
      6 Tutorials 22%
      7 Tutorials 25%
      8 Tutorials 28%
      9 Tutorials 31%
      10 Tutorials 34%
      add url more

      9MZQASHWN73B