Question

Write a program to generate the below table: . The table should be able to vary in size based on a class constant called SIZE

Notes: The cell sizes do not change when the table size changes . You need to only format the table for sizes 1 though 9, the

1 The Os and 1 are the result of a mathematical expression using the column number and the row number These are your column

Example Output, SIZE 3: Blue1: Terminal Window-CSC142 Options に 1 an only enter input whle your prog Example Output, SIZE 7:

Java use for loop (nested for loop) if/else possible on blue J.
(row *col)%2 for 0's and 1's.

Write a program to generate the below table: . The table should be able to vary in size based on a class constant called SIZE; minimum of 1, maximum of 9. . The O's and 1's can and should be generated by evaluating a mathematical expression using the row and column numbers Think about the operators: +-* / % . The output should be generated by running the main method only; all helper methods should be called from main Notes: The cell sizes do not change when the table size changes . You need to only format the table for sizes 1 though 9, therefore you don't have to worry about formatting for double digit numbers Homework Submission:
Notes: The cell sizes do not change when the table size changes . You need to only format the table for sizes 1 though 9, therefore you don't have to worry about formatting for double digit numbers Homework Submission: . All code should be contained in 1 Java Class called "HW01_Student_Name" Submit your java code in a file called "HW01_Student_Name.txt". Do not submit a .java file. . This is an individual assignment, all work should be your own.
1 The O's and 1 are the result of a mathematical expression using the column number and the row number These are your column labels they should only print once 1 2 3 Hint: The expression uses the % operator These are your rOWS- you should print these in a loop that terates SIZE times Row Column Result 0 These are your row labels Here are the cells where your data is you should print these once stored. These should be printed in a loop at the beginning of each row that iterates SIZE times for each row
Example Output, SIZE 3: Blue1: Terminal Window-CSC142 Options に 1 an only enter input whle your prog Example Output, SIZE 7: 1- -I
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the answer below:

I have created a separate method which prints design according to the argument passed.

I have mentioned all the details in the comment.

Please change class name according to your requirement.


import java.util.Scanner;

public class Table {
    public static int SIZE = 7;

    //method to print different design as per requirement
    public static void print_design(int d,int n){
        switch (d){
            case 1 :
                System.out.print("         ");
                break;
            case 2:
                System.out.print("------- ");
                break;
            case 3:
                System.out.print("        |");
                break;
            case 4:
                System.out.print("       |");
                break;
            case 5:
                System.out.print("   "+n+"   |");
                break;
            case 6:
                System.out.print(" -------|");
                break;
            case 7:
                System.out.print("-------|");
                break;
            case 8:
                System.out.print("|       |");
                break;
            case 9:
                System.out.print("       |");
                break;
            case 10:
                System.out.print("|   "+n+"   |");
                break;
            case 11:
                System.out.print("|-------|");
                break;
        }
    }

    //print the last line of each row
    public static void print_row_label(int row){
        for(int i=0;i<=SIZE;i++){
            //if it's first row
            if(i==0 && row==0){
                print_design(6,-1);
            }
            //for each row except 0th one
            else if(i==0 && row==1){
                print_design(11,-1);
            }
            //for all other values
            else{
                print_design(7,-1);
            }
        }
    }
    //method to print coloumn header
    public static  void print_coloum_header(){
        for(int i=0;i<=SIZE;i++){
            if(i==0){
                print_design(1,-1);
            }
            else{
                print_design(2,-1);
            }
        }
        System.out.println();
        for(int i=0;i<=SIZE;i++){
            if(i==0){
                print_design(3,-1);
            }
            else{
                print_design(4,-1);
            }
        }
        System.out.println();
        for(int i=0;i<=SIZE;i++){
            if(i==0){
                print_design(3,-1);
            }
            else{
                print_design(5,i);
            }
        }
        System.out.println();
        for(int i=0;i<=SIZE;i++){
            if(i==0){
                print_design(3,-1);
            }
            else{
                print_design(4,-1);
            }
        }
        System.out.println();
        print_row_label(0);
        System.out.println();

    }
    //method to print each individual row
    public static void print_row(int row){
        int i;
        for(i=0;i<=SIZE;i++){
            if(i==0)
                print_design(8,-1);
            else
                print_design(9,-1);
        }
        System.out.println();
        for(i=0;i<=SIZE;i++){
            if(i==0)
                print_design(10,row);
            else
                print_design(5,(row*i)%2);
        }
        System.out.println();
        print_row_label(1);
        System.out.println();

    }
    public static void main(String[] args) {
        int i,j;
        //to get the size from user
        //if you don't want it comment next 5 lines
        int n;
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the SIZE: ");
        n = sc.nextInt();
        Table.SIZE = n;
        //code to print the table
        //print coloum headers
        print_coloum_header();
        //print each row after that
        for(i=1;i<=SIZE;i++){
            print_row(i);
        }

    }
}

Output:

311I

し1110|1101110|1 2 0 0000 311I0 101 | 40 0000 15 11I0 101 δ!010101010101 1 711I0 101

Add a comment
Know the answer?
Add Answer to:
Java use for loop (nested for loop) if/else possible on blue J. (row *col)%2 for 0's and 1's.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the...

    Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...

  • Row and columns sum Create a java program that: Input: Receive as input in command line...

    Row and columns sum Create a java program that: Input: Receive as input in command line the sizes m and n of a two dimensional array Receive as input in command line the minValue and maxValue between which the random numbers will be generated for your two dimensional array Generate: Generate a two-dimensional with numbers between minValue and maxValue (inclusive) with the given size (m x n) Compute: Compute the sum for each row and store the results in a...

  • Need some help I am not understanding this programming class at all. We are using Microsoft...

    Need some help I am not understanding this programming class at all. We are using Microsoft visual studio with python in console mode to complete these labs. Double-click to hide white space CIS115 Week 4 Lab Overview Title of Lab: Multiplication Table in Python Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to...

  • java Write an application that input a number from the user and checks if all digits...

    java Write an application that input a number from the user and checks if all digits are prime numbers using method prime. The number entered can be of any size. If all digits are prime your program should stop. Use do/while for reading the input and any loop format to test if the number is prime. When checking the prime numbers don’t use an if to check numbers from 1 – 9; you need to find an algorithm to check...

  • PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1...

    PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1 setLocation(row : int, col : int) getRow(): int getColl): int isEmpty(): bool Details Write all the code necessary to implement the Location class as shown in the UML Class Diagram to the right. Do this in a project named snake (we'll continue adding files to this project as the term progresses). Your class definition and implementation should be in separate files. When complete, you...

  • Need help with java In this program you will use a Stack to implement backtracking to solve Sudok...

    need help with java In this program you will use a Stack to implement backtracking to solve Sudoku puzzles. Part I. Implement the stack class.  Created a generic, singly-linked implementation of a Stack with a topPtr as the only instance variable. Implement the following methods only: public MyStack() //the constructor should simply set the topPtr to null public void push(E e) public E pop()  Test your class thoroughly before using it within the soduku program Part II. Create...

  • hello. i need help with number 2 ONLY 1. Use if statements to write a Java...

    hello. i need help with number 2 ONLY 1. Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way 2=ABC 3 = DEF 4 GHI 5 JKL 6 - MNO 7 - PRS 8 - TUV 9-WXY No digit corresponds to either Qor Z. For these 2 letters your program should print a message indicating that they...

  • IN PYTHON Print out a table of powers. Use a for loop that goes from 101 to 112 inclusive. Print out r, r squared, r cub...

    IN PYTHON Print out a table of powers. Use a for loop that goes from 101 to 112 inclusive. Print out r, r squared, r cubed, square root of r, and cube root of r. Use two decimal places for the roots, and zero decimal places for the squares and cubes, and 2 decimal places for the averages. Use commas in numbers 1000 and above. After the loop, print out the average of the r squared and r cubed. Use...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...

  • write a java program that does the following Part one Use a For loop to compute...

    write a java program that does the following Part one Use a For loop to compute the sum of all the odd numbers from 1 through 99. Your result should be labeled, and the value should be 2500. Print your name 7 times using a While loop. String dogNames[ ] = {"Sam","Buster","Fido","Patches","Gromit","Flicka"}; Using the array defined here, print the values of the array vertically and horizontally using one For-Each loop. Reverse the logic (Nested loops: Indent text) so that the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT