Q BgQuestion:

      
Novice
Karma Points: 35
Respect (100%):
posted by  freekina191 on 11/2/2009 11:13:46 PM  |  status: Closed  |  Earned Karma: 35

java methods and procedures?

Course Textbook Chapter Problem Needs by
Software Design N/A N/A N/A 11/3/2009 at 2:00:00 PM
Question Details:
1. For each of the following tasks, design a class (i.e., static) method heading with an appropriate name, parameters, and return type (or void). You do not need to write the method body. For example, the heading for a method that computes and returns the largest of two real numbers could be something like this
    private static double max(double x, double y).
    1. The task is to convert a given integer grade (0..100) into a corresponding letter grade.
    2. The task is to compute the state tax on an item, given the cost of the item and the tax rate.
    3. Given three names, the task is to output them in aphabetical order.
    4. Given a sentence, the task is to print each word in the sentence on a separate line of output.
    5. Given a string and a character, the task is return the string obtained by removing all occurrences of the given character from the given string.
2.
  1. What is the output produced by the following programs?
    1. public class ChangeParam
      {
      public static void main(String[] args)
      {
      int i = 1;
      double x = 3.4;
      String s = "hi!";

      System.out.println(i + " " + x + " " + s);
      changeUs(i, x, s);
      System.out.println(i + " " + x + " " + s);
      }

      private static void changeUs(int j, double y, String t)
      {
      j = 7;
      y = -1.2;
      t = "there";
      System.out.println(j + " " + y + " " + t);
      }
      }
    2. public class TraceMe
      {
      public static void main(String[] args)
      {
      printBox(5, 3);
      }

      private static void printBox(int rows, int columns)
      {
      int i = 0;
      while (i < rows)
      {
      int j = 0;
      while (j < columns)
      {
      if ((i % 2) == (j % 2))
      {
      System.out.print('A');
      }
      else
      {
      System.out.print('B');
      }
      j = j + 1;
      }
      System.out.println();
      i = i + 1;
      }
      }
      }
    3. public class ItsAMistery
      {
      public static void main(String[] args)
      {
      mistery("123456789");
      }

      private static void mistery(String str)
      {
      int i = 0;
      while (i < str.length())
      {
      System.out.print(str.charAt((i + 5) % str.length()));
      i = i + 1;
      }
      }
      }
IF YOU TRY AND PRACTICE ENOUGH, YOU TRULY CAN ACHIEVE ANYTHING!!
Bonus Point Alert! Earn +7 additional karma points for helping this gold member.

AAnswers:

Answer Question Ask for clarification
posted by Reena on 11/3/2009 12:19:10 AM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:
Dear...
Here is the code..
1)
The output of  changeprm class is
1 3.4 hi!
7 -1.2 there
1 3.4 hi!
The output of TraceMe class is
ABA
 BAB
 ABA
 BAB
 ABA
The output of ItsMystery class is
678912345
Hope this will help you...
Oracle
Karma Points: 18,830
posted by Marth on 11/3/2009 6:49:43 PM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:

1. The task is to convert a given integer grade (0..100) into a corresponding letter grade.

private static char convertToLetter(int grade);

2. The task is to compute the state tax on an item, given the cost of the item and the tax rate.

private static double computeStateTax(double cost, double rate);

3. Given three names, the task is to output them in aphabetical order.

This is somewhat ambiguous...I will assume you want to print them alphabetically, rather than return a list or array with the sorted names.


private static void printAlphabetically(String name1, String name2, String name3);

4. Given a sentence, the task is to print each word in the sentence on a separate line of output.

private static void printWordsIndividually(String sentence);

5. Given a string and a character, the task is return the string obtained by removing all occurrences of the given character from the given string.

private static String removeLetter(char letter, String string);



Thank you for rating my response. Feel free to PM me if you have further questions.

Java Genius

"Lois Lane is falling, accelerating at an initial rate of 32ft per second per second. Superman swoops down to save her by reaching out two arms of steel. Ms. Lane, who is now traveling at approximately 120 miles per hour, hits them, and is immediately sliced into three equal pieces." - Sheldon
Answer Question Ask for clarificarion

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different from tutoring »