Question

In: Computer Science

You will create a program with 3 methods. For the previous homework with three problems, you...

You will create a program with 3 methods. For the previous homework with three problems, you will create a method for each problem.

In the main method, you will declare the three arrays and create the memory space for each of them. The first method will receive a one dimension array and then it will assign the values ( e.g., a[4] = 4*4*4*4;). The second method receives a 2 dimensional array and creates the calendar. The third method receives a two dimensional array and inverts row 1 in row.

Please note that you already have the bodies of the methods. You are only creating the methods and calling them in the main method.

You will also create methods printOneDimArray; printArrayCalendar; and printTwoDimArray to print each of the arrays.

Previous Homework Instructions

  1. Assigning values to an array. Write a pseudo and the java code that for the first 10 numbers, the calculated number is equal to that number multiplied by itself that number of times. The result is saved in an array in the number cell. Also, you shall print all the values of the array.
    Constraints: you must use a loop instruction to assign values to the array.

arrayNum [0] = 0
arrayNum [1] = 1
arrayNum [2] = 2*2
arrayNum [3] = 3*3*3
arrayNum [4] = 4*4*4*4

arrayNum [10] = 10*10*10…..*10

Hints: a) arrayNum [2] has a value of 4 and arrayNum [3] has a value of 27; b) use one loop to traverse the array and another to calculate the value based on the current index.

  1. Assigning values to a multidimensional array. Write a pseudocode and java code that puts the days of the month organized by weeks (as a calendar). Use a matrix of 5 x 7 (weeks of 7 days). Day 1 starts at [0][0]. See image in class ppt for arrays.

Hint: a) use one loop to manage the weeks and another to manage the days of the weeks

  1. Manipulating arrays. Given a two dimensional array, invert the first row into the second row.   Print the array once you have inverted the first row. Initialize your array as follows:
    int [ ] [ ] myBiDimArrayNum = {
                                                             { 1, 3, 5 ,7},
                                                             { 0, 0, 0, 0 }
                                                          };
    Note: you algorithm should modify the array as follow:
    myBiDimArrayNum   
       row 1: 1, 3, 5 ,7
       row 2: 7, 5, 3, 1

previous homework attached below

1) public class Test{

public static void main(String []args){
int[] arrayNum=new int[11];
for(int i=0;i<=10;i++)
{
arrayNum[i]=i;
for(int j=0;j<i-1;j++)
{
arrayNum[i]=arrayNum[i]*i;
}
}
System.out.println("Array is");
for(int i=0;i<=10;i++)
{
System.out.println("arrayNum["+i+"]="+arrayNum[i]);
}

}
}

2) import java.util.Scanner;
import java.util.Arrays;
  
public class MyClass
{

public static void main(String args[])
{
int [ ] [ ] matrix = new int [5][7];

Scanner sc = new Scanner(System.in);
int days=1;
System.out.println("Assigning Values");

for (int i = 0; i <5; i++)
{
for (int j = 0; j < 7; j++)
{
matrix[i][j] = days++;
if(days==32)
{
break;
}

}
//because day can be 31 only.
if(days==31)
{
break;
}
}

  
for (int i = 0; i < 5; i++)
{
// Loop through all elements of current row
for (int j = 0; j < 7; j++)
{
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}
  
}
}

3)

import java.util.Scanner;
import java.util.Arrays;
  
public class MyClass
{

public static void main(String args[])
{
int [ ] [ ] myBiDimArrayNum = {
{ 1, 3, 5 ,7},
{ 0, 0, 0, 0 }
};

Scanner sc = new Scanner(System.in);
int days=1;
System.out.println("Manipulating Array");

for (int i = 0; i <2; i++)
{
//take this variable to copy elements from end of row first.
int last=3;
for (int j = 0; j < 4; j++)
{
//because indexing start from zero 1 will represent row second now we have to change its content.
if(i==1)
{
//As we have to manipulate the second from ending of row first we are using ***(i-1) and assign it to second row that is **(i).
myBiDimArrayNum[i][j]=myBiDimArrayNum[i-1][last];
last--;
}

}
}

  
for (int i = 0; i < 2; i++)
{
// Loop through all elements of current row
for (int j = 0; j < 4; j++)
{
System.out.print(myBiDimArrayNum[i][j] + " ");
}
System.out.println();
}
  
}
}

Solutions

Expert Solution

This is modified java code.

import java.util.Scanner;
import java.util.Arrays;
class one{

void one1(int arr1[]){



for(int i=0;i<=10;i++)
{

arr1[i]=i;


for(int j=0;j<i-1;j++)
{

arr1[i]=arr1[i]*i;


}
}
System.out.println("Array is");
for(int i=0;i<=10;i++)
{

System.out.println("arrayNum["+i+"]="+arr1[i]);
}

}
}

class two{

void two1(int matrix[][])
{




int days=1;
System.out.println("Assigning Values");

for (int i = 0; i <5; i++)
{
for (int j = 0; j < 7; j++)
{
matrix[i][j] = days++;
if(days==32)
{
break;
}

}
//because day can be 31 only.
if(days==31)
{
break;
}
}


for (int i = 0; i < 5; i++)
{
// Loop through all elements of current row
for (int j = 0; j < 7; j++)
{
System.out.print(matrix[i][j] + " ");
}
System.out.println();
}

}
}

class three{
void three1(int myBiDimArrayNum[][])
{



int days=1;
System.out.println("Manipulating Array");

for (int i = 0; i <2; i++)
{
//take this variable to copy elements from end of row first.
int last=3;
for (int j = 0; j < 4; j++)
{
//because indexing start from zero 1 will represent row second now we have to change its content.
if(i==1)
{
//As we have to manipulate the second from ending of row first we are using ***(i-1) and assign it to second row that is **(i).
myBiDimArrayNum[i][j]=myBiDimArrayNum[i-1][last];
last--;
}

}
}


for (int i = 0; i < 2; i++)
{
// Loop through all elements of current row
for (int j = 0; j < 4; j++)
{
System.out.print(myBiDimArrayNum[i][j] + " ");
}
System.out.println();
}

}
}

public class Main
{


Scanner sc = new Scanner(System.in);
public static void main(String[] args) {

int[] arr1=new int[11];


int [ ] [ ] matrix = new int [5][7];
int [ ] [ ] myBiDimArrayNum = {
{ 1, 3, 5 ,7},
{ 0, 0, 0, 0 }
};

one obj1=new one();
two obj2=new two();
three obj3=new three();
System.out.println("method one\n\n");
obj1.one1(arr1);
System.out.println("method two\n\n");
obj2.two1(matrix);
System.out.println("method three\n\n");
obj3.three1(myBiDimArrayNum);
}
}

Output


Related Solutions

3. See the table below that was assigned to you as homework in a previous week.  Suppose...
3. See the table below that was assigned to you as homework in a previous week.  Suppose that the market price is $13 per unit. Quantity Total Cost Fixed Cost Variable Cost ATC AVC MC 0 $18 $18 0 18 0 0 1 $27 $18 $9 $27 $9 $9 2 $32 $18 $14 $16 $7 $5 3 $33 $18 $15 $11 $5 $1 4 $40 $18 $22 $10 $5.50 $7 5 $60 $18 $42 $12 $8.40 $20 a. What quantity will...
3) Create a Java program that uses NO methods, but use scanner: Write a program where...
3) Create a Java program that uses NO methods, but use scanner: Write a program where you will enter the flying distance from one continent to another, you will take the plane in one country, then you will enter miles per gallon and price of gallon and in the end it will calculate how much gas was spend for that distance in miles. Steps: 1) Prompt user to enter the name of country that you are 2) Declare variable to...
Problems create a C++ program that will do the followings - define 3 double variables x,...
Problems create a C++ program that will do the followings - define 3 double variables x, y, z - calculate the value of y as the following formula: y = 2*x*x+4*x+5 and print x and y; - assign a new value to x: x=5.6 - calculate the value of z as the following formula z = (y*y)/4 + (x*x)/5 - print x, y,x
4.) Create a Java program using the “extends” and “runnable” methods. You will be creating your...
4.) Create a Java program using the “extends” and “runnable” methods. You will be creating your own threaded program using the threadExtend.java code and the threadRunnable.java code. A.) Focus the threadExtend.java code DETAILS TO NOTE: - It creates 4 instances of the same thread. This means that the thread code is actually running 4 separate times - The thread accepts 2 parameters, an INTEGER from 1 to 4, as well as an ID - Note the parameters are hard coded...
can you assist me in getting the desired output? Homework 5-3 Write a Java program that...
can you assist me in getting the desired output? Homework 5-3 Write a Java program that prompts the user for an int n. You can assume that 1 ≤ n ≤ 9. You program should use two embedded for loops that produce the following output:     1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 . . . This is the code: import java.util.Scanner; public class PatternOne {    public static void main(String[] args) {...
There are three "methods" to compute and work problems to calculate these figures. The first is...
There are three "methods" to compute and work problems to calculate these figures. The first is simply by way of a formula...(i.e. beginning finished goods + cost of goods manufactured - ending finished goods = cost of goods sold). The second was by visualizing the flow of goods throughout the various T accounts for Raw Materials, Work in Process, and Finished Goods. The third was to prepare journal entries in order to compute each of these amounts, which is similar...
Determine two to three (2-3) methods of using stocks and options to create a risk-free hedge...
Determine two to three (2-3) methods of using stocks and options to create a risk-free hedge portfolio can be created. Support your answer with examples of these methods being used to create a risk-free hedge portfolio.?
Determine two to three (2-3) methods of using stocks and options to create a risk-free hedge...
Determine two to three (2-3) methods of using stocks and options to create a risk-free hedge portfolio can be created. Support your answer with examples of these methods being used to create a risk-free hedge portfolio.
C++ program homework question 1 1. Create and implement a class called clockType with the following...
C++ program homework question 1 1. Create and implement a class called clockType with the following data and methods (60 Points.): Data: Hours, minutes, seconds Methods: Set and get hours Set and get minutes Set and get seconds printTime(…) to display time in the form of hh:mm:ss default and overloading constructor Overloading Operators: << (extraction) operator to display time in the form of hh:mm:ss >> (insertion) operator to get input for hours, minutes, and seconds operator+=(int x) (increment operator) to...
Description: For this assignment, you are required to write 3 recursive methods described below. Create a...
Description: For this assignment, you are required to write 3 recursive methods described below. Create a class named HW06 and implement the following 3 methods . The implementation MUST use recursive calls. - static int multiplyPositiveIntegers(int a, int b) //multiplies two positive integers using recursion (no use of * allowed). Returns the result of multiplication. (30 points) - static void recursiveBubbleSort(int[] arr) //Sorts an array using bubble sort in a recursive manner. Hint: do one pass(which puts the biggest element...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT