



Code in Java:
import java.util.Random;
import java.util.Scanner;
public class Solution {
// random generator
private static Random rand = new Random();
public static void main(String[] args){
Scanner r = new Scanner(System.in);
while (true) {
System.out.println("Welcome to the terrain generator.\n" +
"Please select an option\n" +
"1 - Single Strip of Land\n" +
"2 - Island\n" +
"-1 - Exit");
int num = r.nextInt();
if (num == -1){
break;
} else if (num == 1){
singleStrip(r);
} else if (num == 2){
island(r);
} else {
break;
}
}
r.close();
}
/*
generating next for grass
* */
private static char getNextFromGrass(){
int rNum = Math.abs(rand.nextInt()) % 100;
if (rNum < 10){
return 'D';
} else if (rNum < 25){
return 'W';
} else if (rNum < 55){
return 'H';
} else {
return 'G';
}
}
/*
generating next for hill
* */
private static char getNextFromHill(){
int rNum = Math.abs(rand.nextInt()) % 100;
if (rNum < 20){
return 'M';
} else if (rNum < 30){
return 'W';
} else if (rNum < 75){
return 'H';
} else {
return 'G';
}
}
/*
generating next for mountain
* */
private static char getNextFromMountain(){
int rNum = Math.abs(rand.nextInt()) % 100;
if (rNum < 55){
return 'M';
} else if (rNum < 60){
return 'D';
} else if (rNum < 75){
return 'W';
} else {
return 'H';
}
}
/*
generating next for desert
* */
private static char getNextFromDesert(){
int rNum = Math.abs(rand.nextInt()) % 100;
if (rNum < 5){
return 'M';
} else if (rNum < 70){
return 'D';
} else {
return 'G';
}
}
/*
generating next for water
* */
private static char getNextFromWater(){
int rNum = Math.abs(rand.nextInt()) % 100;
if (rNum < 5){
return 'M';
} else if (rNum < 55){
return 'W';
} else if (rNum < 70){
return 'H';
} else {
return 'G';
}
}
/*
generating neighboring character
* */
private static char generateNeighbor(char curCh){
switch (curCh){
case 'G':
return getNextFromGrass();
case 'M':
return getNextFromMountain();
case 'H':
return getNextFromHill();
case 'W':
return getNextFromWater();
case 'D':
return getNextFromDesert();
default:
break;
}
return '\0';
}
/*
generating island
* */
private static void island(Scanner r) {
int n, m;
System.out.print("Get width: ");
m = r.nextInt();
System.out.print("Get height: ");
n = r.nextInt();
System.out.print("Generating ... ... ...\n");
char[][] island = new char[n][m];
String s = "HWDMG";
int pos = Math.abs(rand.nextInt()) % 5;
char ch = s.charAt(pos);
System.out.print(ch);
island[0][0] = ch;
for (int i=1; i<m; ++i){
ch = generateNeighbor(ch);
island[0][i] = ch;
}
for (int i=1; i<n; ++i){
island[i][0] = generateNeighbor(island[i - 1][0]);
for (int j=1; j<m; ++j){
int id = Math.abs(rand.nextInt()) & 1;
if (id == 1){
island[i][j] = generateNeighbor(island[i][j - 1]);
} else {
island[i][j] = generateNeighbor(island[i - 1][j]);
}
}
}
System.out.print("Your Island:\n");
for (int i=0; i<n; ++i){
System.out.println(island[i]);
}
System.out.println();
}
/*
generating strip
* */
private static void singleStrip(Scanner r) {
System.out.print("Get length of the strip: ");
int size = r.nextInt();
System.out.print("Generating ... ... ...\n");
String s = "HWDMG";
System.out.print("Your Strip:\n");
int pos = Math.abs(rand.nextInt()) % 5;
char ch = s.charAt(pos);
System.out.print(ch);
for (int i=1; i<size; ++i){
ch = generateNeighbor(ch);
System.out.print(ch);
}
System.out.print("\n\n");
}
}
Comment down for any queries Please give a thumb up
**JAVA PLEASE!!** CSE205 Assignment 2 ASCII Terrain Generator 5Opts Topics: Arrays Multidimensional Arrays Metho...
For this exercise, you will complete the TicTacToe Board that we started in the 2D Arrays Lesson. We will add a couple of methods to the TicTacToe class. To track whose turn it is, we will use a counter turn. This is already declared as a private instance variable. Create a getTurn method that returns the value of turn. Other methods to implement: printBoard()- This method should print the TicTacToe array onto the console. The board should include numbers that...
This is java, please follow my request and use netbeans.
Thank you.
A3 15. 2D Array Operations Write a program that creates a two-dimensional array initialized with test data. Use any primitive data type that you wish. The program should have the following methods: • getTotal. This method should accept a two-dimensional array as its argument and return the total of all the values in the array. .getAverage. This method should accept a two-dimensional array as its argument and return...
Count Occurrences in Seven Integers Using Java Single Dimension
Arrays
In this assignment,
you will design and code a Java console application that reads in
seven integer values and prints out the number of occurrences of
each value. The application uses the Java single dimension array
construct to implement its functionality.
Your program output
should look like the sample output provided in the "Count
Occurrences in Seven Integers Using Java Single Dimension Arrays
Instructions" course file resource. Full instructions for...
Using Java
In this assignment we are working with arrays. You have to ask the user to enter the size of the integer array to be declared and then initialize this array randomly. Then use a menu to select from the following Modify the elements of the array. At any point in the program, if you select this option you are modifying the elements of the array randomly. Print the items in the array, one to a line with their...
Assignment overview In this assignment, you will implement a simple game of Battleship. If you are unfamiliar with the game Battleship, there are tutorials online describing the game. In short, there are two players that each have a 10 by 10 grid where ships are placed. The players take turns taking shots at each other’s ships. A player wins when they have shot at all spaces on their opponent’s grid that are occupied by ship. To sink a ship, you...
[JAVA/chapter 7] Assignment: Write a program to process scores for a set of students. Arrays and methods must be used for this program. Process: •Read the number of students in a class. Make sure that the user enters 1 or more students. •Create an array with the number of students entered by the user. •Then, read the name and the test score for each student. •Calculate the best or highest score. •Then, Calculate letter grades based on the following criteria:...
Advanced Object-Oriented Programming using
Java
Assignment 4: Exception Handling and Testing in
Java
Introduction - This assignment is
meant to introduce you to design and implementation of
exceptions in an object-oriented language. It will
also give you experience in testing an
object-oriented support class.
You will be designing and implementing a version of the game
Nim. Specifically, you will design and implement a
NimGame support class that stores all actual
information about the state of the game, and detects and throws...
Programming Assignment 6 Write a Java program that will implement a simple appointment book. The program should have three classes: a Date class, an AppointmentBook class, and a Driver class. • You will use the Date class that is provided on Blackboard (provided in New Date Class example). • The AppointmentBook class should have the following: o A field for descriptions for the appointments (i.e. Doctor, Hair, etc.). This field should be an array of String objects. o A field...
This assignment will continue our hardware store system. You will turn in a java file named "MyMethods.java". It will contain one class named "MyMethods". That class will contain three methods. These methods must be exactly as specified (including method names): getAnInt will return a value of type int, and take as an argument a string to prompt the user. The actual prompt presented to the user should include not only the string argument, but also the information that the user...
Assignment is designed to develop your ability to create static methods and manipulate 1D and 2D arrays in Java. Create a single Java class Matrix and inside the class create the specified static methods as described Task # Description 1 Create a matrix (known components) 2 Create a matrix (random components) 3 Create a matrix from vectors 4 Compare two matrices 5 Add two matrices 6 Subtract two matrices 7 Multiply a matrix by a scalar 8 Multiply two matrices...