Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / QUESTION 1 Modify the Code Listing 7-26 (Pass2Darray

QUESTION 1 Modify the Code Listing 7-26 (Pass2Darray

Computer Science

QUESTION 1 Modify the Code Listing 7-26 (Pass2Darray.java) from page 515 as follows:

 

A)           Add a static method called showSumRows() that will display the sum for each row in the two-dimensional array. The code to do that is on page 513, 514.

PAGE 513

 

B)            Add another static method called showSumColums() that will display the sum for each column in the same two-dimensional array. The code to do that is on page 514.

 

 C) Finally, add calls to each of the above methods after line 20 in the existing program.

Here is the Pass2Darray.java code from the textbook:

 

                 QUESTION 2

 

Modify the the Code Listing 8-9 (DateTester.java) as Follows

 

 

 

A. Add an import statement for java.util.StringTokenizer.

B. Delete lines 12-14 from the original code and replace them with lines 22-34 from the Code Listing 8-8 (DateComponent.java). Variables month, day, year need to be declared as integer. So, you must use "Integer.parseInt()" to convert each call to nextToken() to an integer value. (see page 584)

 

Big Potential Gain: Although NOT REQUIRED here, after converting to integer, you could do math with these variables such as checking for range of values and/or leap year formula.

C. Change the display statements to use variables month, day, year instead of method calls.

IMPORTANT: final version of your code should not use DateComponent object.

 

Here are the original files: DateTester.Java

 

 

/**

 * This program demonstrates the DateComponent class.

 */

public class DateTester

{

   public static void main(String[] args)

   {

      // Create a string containing a date.

      String date = "10/23/2011";

     

      // Create a DateComponent object, initialized

      // with the date.

      DateComponent dc = new DateComponent(date);

      // Display the components of the date.

      System.out.println("Here's the date: " + date);

      System.out.println("The month is " + dc.getMonth());

      System.out.println("The day is " + dc.getDay());

      System.out.println("The year is " + dc.getYear());

   }

}

IMPORTANT: final version of your code should not use DateComponent object

                 DateComponent.Java

mport java.util.StringTokenizer;

/**

 * The DateComponent class extracts the month, day, and

 * year from a string containing a date.

 */

public class DateComponent

{

   private String month, // To hold a month

                  day,   // To hold a day

                  year;  // To hold a year

   /**

    * The constructor accepts a string containing a date 

    * in the form MONTH/DAY/YEAR. It extracts the month, 

    * day, and year from the string.

    */

   public DateComponent(String dateStr)

   {

      // Create a StringTokenizer object. The string to

      // tokenize is dateStr, and "/" is the delimiter.

      StringTokenizer strTokenizer =

                 new StringTokenizer(dateStr, "/");

      // Get the first token, which is the month.

      month = strTokenizer.nextToken();

     

      // Get the next token, which is the day.

      day = strTokenizer.nextToken();

     

      // Get the next token, which is the year.

      year = strTokenizer.nextToken();     

   }

   /**

    * The getMonth method returns the month field.

    */

   public String getMonth()

   {

      return month;

   }

   /**

    * The getDay method returns the day field.

    */

   public String getDay()

   {

      return day;

   }

   /**

    * The getYear method returns the year field.

    */

   public String getYear()

   {

      return year;

   }

}   {

      return year;

   }

 

 

 

          QUESTION 3

Please solve the following problems:

#6. Driver's License Exam --

 

 

 

#11. Sales Analysis--

 

 

 

Hint: this program should not assume a fixed number of weeks. So, a two-dimension array is NOT appropriate here.

 

1245.67,1490.07,1679.87,2371.46,1783.92,1461.99,2059.77

2541.36,2965.88,1965.32,1845.23,7021.11,9652.74,1469.36

2513.45,1963.22,1568.35,1966.35,1893.25,1025.36,1128.36

 

Save and submit your files with the names DriverExam.java,  DriverExamTest.java,  and SalesAnalysis.java respectively. For simplicity, you can compress all files under one single .zip or .rar file.

 

Option 1

Low Cost Option
Download this past answer in few clicks

22.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions