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...
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...
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...
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...
[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...
using java Program: Please read the complete prompt before going into coding. Write a program that handles the gradebook for the instructor. You must use a 2D array when storing the gradebook. The student ID as well as all grades should be of type int. To make the test process easy, generate the grade with random numbers. For this purpose, create a method that asks the user to enter how many students there are in the classroom. Then, in each...
Java Objective: The goal of this assignment is to practice 2-dimensional ragged arrays. Background: Within a healthy, balanced diet, a grownup needs 2,250 calories a day You will write a program to track calorie intake of a person. Assignment: Calorie intake data from a person is provided in a text file named input.txt. There are arbitrary number of double values on each line, separated by spaces. The numbers represent the number of calories consumed for meals and/or snacks on a...