this is advance java
// save it as Snake2d.java thanks
import java.util.*;
public class Snake2d {
static int rows= 40, cols= 40; //set
these values only (array size) set any numbers as you wish
static int sleeeptime = 100; //time beatween each move
milli seconds
static int sourceR, sourceC, destR, destC;
static int snake[][] = new int[rows][cols];
public static void fill()
{
int cakes = 8; // how many cakes to
eat
Random rand = new Random();
List<Integer> randomNumbers =
new ArrayList<Integer>(cakes);
//first fill all to 0
for (int a = 0; a < rows;
a++)
for (int b = 0;
b < cols; b++)
snake[a][b]=0;
//--------------------
for (int i = 2; i<= 9; i++)
{
randomNumbers.add(i);
}
Collections.shuffle(randomNumbers);
for (int i = 0; i< cakes;
i++) {
int randomRow = rand.nextInt(((rows-1) - 0) + 1) + 0;
//random row index
int randomCol =
rand.nextInt(((cols-1) - 0) + 1) + 0; //random col
index
if (
snake[randomRow][randomCol]== 0) // if there is already 0 then
replace with randomNum
{
snake[randomRow][randomCol]=
randomNumbers.get(i);
}
else
{
i--;
continue;
}
}
}
public static void print()
{
for (int a = 0; a < rows;
a++)
{
for (int b = 0;
b < cols; b++)
{
switch (snake[a][b])
{
case -1:
System.out.print("@ "); // use # here if you dont want @ as monster
head
break;
case 1:
System.out.print("# ");
break;
case 0:
System.out.print(". ");
break;
default:
System.out.print( snake[a][b]+" ");
break;
}
}
System.out.println();
}
System.out.println();
System.out.println();
}
public static void move(int i, int j, int r, int
c)throws Exception
{
snake[i][j] = 1;
if (i<r)
{
while
(i!=r)
{
i++;
snake[i][j] = -1;
print();
snake[i][j] = 1;
Thread.sleep(sleeeptime);
}
}
else if (i>r)
{
while
(i!=r)
{
i--;
snake[i][j] = -1;
print();
snake[i][j] = 1;
Thread.sleep(sleeeptime);
}
}
if (j<c)
{
while
(j!=c)
{
j++;
snake[i][j] = -1;
print();
snake[i][j] = 1;
Thread.sleep(sleeeptime);
}
}
else if (j>c)
{
while
(j!=c)
{
j--;
snake[i][j] = -1;
print();
snake[i][j] = 1;
Thread.sleep(sleeeptime);
}
}
System.out.println( i+ " " +j
);
sourceR = i; //update source row
index
sourceC = j; //update source col
index
print();
Thread.sleep(1000); // pause for 1
sec after eating
}
public static void main (String args[])throws
Exception
{
sourceR = 0;
sourceC = 0;
fill(); //fill array randomly
int max = 0;
while(max!=1)
{
//find max
number
for(int i=0;
i<rows; i++){
for(int j =0; j<cols; j++){
if(max<snake[i][j]) //max number is found at i j location
{
max = snake[i][j];
destR = i; //mark destination row
destC = j; //mark destination col
}
}
}
if
(max==1)
{
break; // if no max number is left
other than 1, then exit program
}
else
{
System.out.println("### Monster on the move!
###");
System.out.println("### Monster wants "+ max + "
###");
Thread.sleep(2000);
}
max =
0;
move(sourceR,
sourceC, destR, destC); // move towards max
number
}
}
}
this is advance java Monster ARray Summary: Write a program that shows the path of an imaginary monster moving through a two dimensional array trying to "eat...
IN JAVA Write a program that uses a two-dimensional array to store daily minutes walked and carb intake for a week. Prompt the user for 7 days of minutes walked and carb intake; store in the array. Write a sort ( your choice which sort ) to report out the sorted minute values -lowest to highest. Write another to report out the sorted carb intake - highest to lowest. These methods MUST be your original code. Your program should output...
Write a Java program to play the game Tic-Tac-Toe. Start off with a human playing a human, so each player makes their own moves. Follow the design below, creating the methods indicated and invoking them in the main program. Use a char array of size 9 as the board; initialize with the characters 0 to 8 so that it starts out looking something like the board on the left. 0|1|2 3|4|5 6|7|8 and then as moves are entered the board...
Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...
C Programming write two functions, similar to what you see in the sample program. The first will ask the user to enter some information (I have included the type in parentheses) First Name (char[]) Last Name (char[]) Age (int) Height in Inches (double) Weight in Pounds (double) You will use pass-by-reference to modify the values of the arguments passed in from the main(). Remember that arrays require no special notation, as they are passed by reference automatically, but the other...
Summary Write a program that demonstrates the skills you’ve learned throughout this quarter. This type of project offers only a few guidelines and requirements, allowing you to invest as much time, effort and imagination as you want. Submit your java programs (*.java) and any other I/O (*.txt) via Canvas You’ve worked quite hard to make it this far, so have a bit of fun with this project! Design Brief: Use Case Scenario You are hired to develop a...
Python Program Eratosthenes of Cyrene lived approximately 275-195 BC. He was the first to accurately estimate the diameter of the earth. For several decades he served as the director and chief librarian of the famous library in Alexandria. He was highly regarded in the ancient world, but unfortunately only fragments of his writing have survived. The algorithm described for this assignment is known as the Sieve of Eratosthenes. The algorithm is designed to find all prime numbers within a given...
Using Merge Sort: (In Java) (Please screenshot or copy your output file in the answer) In this project, we combine the concepts of Recursion and Merge Sorting. Please note that the focus of this project is on Merging and don't forget the following constraint: Programming Steps: 1) Create a class called Art that implements Comparable interface. 2) Read part of the file and use Merge Sort to sort the array of Art and then write them to a file. 3)...
I have this case study to solve. i want to ask which type of case study in this like problem, evaluation or decision? if its decision then what are the criterias and all? Stardust Petroleum Sendirian Berhad: how to inculcate the pro-active safety culture? Farzana Quoquab, Nomahaza Mahadi, Taram Satiraksa Wan Abdullah and Jihad Mohammad Coming together is a beginning; keeping together is progress; working together is success. - Henry Ford The beginning Stardust was established in 2013 as a...
How can we assess whether a project is a success or a failure? This case presents two phases of a large business transformation project involving the implementation of an ERP system with the aim of creating an integrated company. The case illustrates some of the challenges associated with integration. It also presents the obstacles facing companies that undertake projects involving large information technology projects. Bombardier and Its Environment Joseph-Armand Bombardier was 15 years old when he built his first snowmobile...