Question

In: Computer Science

This is a very simple program that will ONLY print a heading and columns of text...

This is a very simple program that will ONLY print a heading and columns of text to emulate the following information:

Sales This Month

Admin Fee

Commission Rate

----------------------------------------------

----------------------------------------------

----------------------------------------------

Less than $10,000

$150

5%

$10,000 – 14,999

$150

10%

$15,000 – 17,999

$150

12%

$18,000 – 21,999

$200

15%

$22,000 or more

$200

16%

******Salesperson of the month******

Name: STUDENT NAME

ID: STUDENT ID

public class SalesResult {

public static void main(String[] args) {

System.out.println();

. . .

}

}

Create a Java project in Eclipse named SalesProject and add a class named SalesResult to reproduce a table like the above. In your program repeat the System.out.println(); as many times as needed.

I was wondering how to write the code to create such a table...

Solutions

Expert Solution

//------------ SalesResult.java -------------------

public class SalesResult
{
   public static void printLine()
   {
       System.out.println("______________________________________________________________________");
   }
   public static void main(String[] args)
   {
       //headers for table here mention your headers
       String[] headers = {"Sales This Month" , "Admin Fee" , "Commission Rate"};
       //create a table of contents to be displayed
       //here mention your table rows.
       //NOTE: IF YOU GIVE MORE COLUMNS THAN THE HEADERS LENGTH
       //FIRST HEADER LENGTH COLUMNS WILL BE CONSIDERED.
       //EXAMPLE HERE HEADERS LENGTH IS 3, IF I INCLUDE > 3 COLUMNS IN
       //MY ROWS THEN FIRST 3 WILL BE CONSIDERED
       String[][] table = {
           //ROWS.
           {"Less than $10,000" , "$150" , "5%"},
           {"$10,000 – 14,999" ,"$150" ,"10%"},
           {"$15,000 – 17,999" , "$150" ,"12%"},
           {"$18,000 – 21,999" , "$200" ,"15%"},
           {"$22,000 or more" , "$200" ,"16%"}
       };
      
      
      
       System.out.println();
       int i,j;
       //length is the total columns or headers int table.
       int length = headers.length;
      
       //printLine() for printing a horizentol line
       printLine();
       //print headers
       System.out.print("\n");
       for(i = 0 ;i<length;i++)
       {
           System.out.print(String.format("| %-20s ",headers[i]));
       }
       //print closing | for row.
       System.out.println("|");
       //print line
       printLine();
      
       System.out.println();
       //print dashes like in the given table for
       //since there are length columns we have to print those many dashes columns.
       for(i=0;i<length;i++)
       {
           System.out.print(String.format("| %-20s ","-----------------"));
       }
       //print closing | for row.
       System.out.println("|");
      
       //print dashes like in the given table for
       //since there are length columns we have to print those many dashes columns.
       for(i = 0;i<length;i++)
       {
           System.out.print(String.format("| %-20s ","--------------"));
       }
       //print closing | for row.
       System.out.println("|");
       printLine();
      
       //now get number of rows.
       int rows = table.length;
       for(i = 0;i<rows;i++)
       {
           //print first length columns of i_th row .
           System.out.print("\n");
           for(j = 0;j<length;j++)
           {
               System.out.print(String.format("| %-20s ",table[i][j]));
           }
           //print closing | for row and horizentol line.
           System.out.println("|");
           printLine();
       }
       System.out.println("\n****** Salesperson of the month ******\n");
      
   }
}
//--------------- OUTPUT -----------------


Related Solutions

Write in C++ Print the following heading (should be in heading function) Welcome to Reference parameters...
Write in C++ Print the following heading (should be in heading function) Welcome to Reference parameters 2 ) ask the user for 2 numbers (should be in main) 3 ) Calculate the sum and product of the numbers using reference parameters (should be in getAnswer function) 4 ) Print the sum and product of the numbers in the following format: (should be in printmessage function) Here is the function you need        Function name | Parameters                       | Return Type    heading |...
Swift - Implement a simple text editor program that includes a text input field (with several...
Swift - Implement a simple text editor program that includes a text input field (with several lines), a text label, and two buttons, called "Open" and "Save". When the button "Save" is touched, the app will save the contents of the text input field to a data file (sample.txt). When the button "Open" is touched, the app will read the content from the data file, (sample.txt)) and feed the content into the text label. Thank you.
IN C LANGUAGE This program will read in a series of strings and print only the...
IN C LANGUAGE This program will read in a series of strings and print only the consonants (including Y) until the word "stop" appears. No string will be longer than 100 characters. A consonant is any letter that is not a vowel. Don't forget to follow the standard read pattern! Examples Enter a string: Hello Hll Enter a string: World! Wrld Enter a string: 123! Enter a string: stop Enter a string: stop
Design a program that will read each line of text from a file, print it out...
Design a program that will read each line of text from a file, print it out to the screen in forward and reverse order and determine if it is a palindrome, ignoring case, spaces, and punctuation. (A palindrome is a phrase that reads the same both forwards and backwards.) Example program run: A Toyota's a Toyota atoyoT a s'atoyoT A This is a palindrome! Hello World dlroW olleH This is NOT a palindrome! Note: You are only designing the program...
The textbook presents a very simple, linear scheme of the central dogma of molecular biology (text...
The textbook presents a very simple, linear scheme of the central dogma of molecular biology (text page 500), but is explicit in noting the simplicity of the original concept and exceptions to it. Which of the following would NOT be reasonable additions or modifications that could be made to this simple linear scheme to account for experimental data? The textbook presents a very simple, linear scheme of the central dogma of molecular biology (text page 500), but is explicit in...
JavaScript Find and Replace Text Main text: a text area with 3 rows and 20 columns....
JavaScript Find and Replace Text Main text: a text area with 3 rows and 20 columns. The default text is “Hello testing”. The text area cannot be empty. • Find text: a text box for the user to key in text he/she wants to find. • Replacement text: a text box for the user to key in the replacement text. If the find text is empty, this element should be disabled (i.e. user cannot key in anything here). • Find...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an...
ONLY IN C LANGUAGE Write a C program to print all the unique elements of an array. Print all unique elements of an array Enter the number of elements to be stored in the array: 4 Input 4 elements in the arrangement: element [0]: 3 element [1]: 2 element [2]: 2 element [3]: 5 Expected output: The only items found in the array are: 3 5
How can I write a simple MIPS program to print out the following elements of an...
How can I write a simple MIPS program to print out the following elements of an array of the size of 10: 5,10,15,20,25,30,35,40,45,50
write a c# program that: The file is using a very simple form of compression in...
write a c# program that: The file is using a very simple form of compression in which there are no spaces, each word is separated by camel casing. For Example, the string "TheCatWillRun" is parsed as "The Cat Will Run". *Now for the statistics* Prints to the console the following statistics about the content in the file retrieved above. - How many of each letter are in the file - How many letters are capitalized in the file - The...
Write about your gender schema. Make two columns, one with the heading “female” and one with...
Write about your gender schema. Make two columns, one with the heading “female” and one with the heading “male. In each column list the characteristics and behaviors you consider to belong in each category, including physical appearance and functioning, societal roles, personality traits and relationships. Have your current views of gender functioning changed from when you were growing up? If so, what contributed to the change? Do you have a problem with the way society currently views either gender? Explain.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT