Question

Europe South Amaricn 1 125 7.5 625 Central Amenta South Amenca 1 25 h Amenia 2 12.5 dde Eazt

Practice: Two-dimensional arrays

Design an algorithm that takes two locations from the user and outputs the correct points, as shown in the table above. For this problem you only need to output what is on the white lines of the table.

  1. You must declare the 2D array and give it a suitable name, but for initialization you can simply write input mySuitablyNamedArray from points table.
  2. The user enters the two locations as numbers, for example 0 would refer to Main, US, Alaksa, Canada, 1 would refer to Hawaii, etc.
  3. If points are not applicable for a pair of locations, output "NA" to the user. For this part, think of how will you handle the "-" in the table above that means not applicable. What value might best represent this in the 2D array? Recall our Sentinel Value discussion in Week 4.

This is worth 10 points.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;
class Main
{
public static void main(String[] args)
{
int a,b; //variable declaration
double k=0;
Scanner sc=new Scanner(System.in);
//asking the prompt from user
System.out.println("Enter the first point");
a=sc.nextInt();
System.out.println("Enter the second point");
b=sc.nextInt();
double arr[][]={{12.5,22.5,17.5,17.5,17.5,22.5,30,30,40,40,30,40,50,40,50},
{0,7.5,25,25,25,30,40,40,40,40,30,35,60,40,50},
{0,0,-1,17.5,17.5,25,30,35,50,50,60,50,60,60,50},
{0,0,0,-1,17.5,22.5,35,35,50,50,50,50,50,50,50},
{0,0,0,0,-1,10,22.5,35,50,50,50,50,50,50,50},
{0,0,0,0,0,-1,22.5,50,60,60,57.5,-1,60,60,60},
{0,0,0,0,0,0,12.5,60,60,80,60,60,60,60,60},
{0,0,0,0,0,0,0,15,25,35,50,50,60,23,35},
{0,0,0,0,0,0,0,0,-1,40,40,40,60,22.5,40},
{0,0,0,0,0,0,0,0,0,-1,40,35,60,40,40},
{0,0,0,0,0,0,0,0,0,0,15,22.5,35,40,50},
{0,0,0,0,0,0,0,0,0,0,0,22.5,40,40,80},
{0,0,0,0,0,0,0,0,0,0,0,0,22.5,60,60},
{0,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,-1}};
k=arr[a][b];
if(k==-1) //checking if the value is "-"
System.out.println("NA");
else
System.out.println("The value is "+arr[a][b]);
}
}

OUTPUT

Enter the first point Enter the second point 12 The value is 50.0

Add a comment
Know the answer?
Add Answer to:
Practice: Two-dimensional arrays Design an algorithm that takes two locations from the user and outputs the...
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
  • The user (me) will input between 3 and 20 data points for two variables on Sheet1...

    The user (me) will input between 3 and 20 data points for two variables on Sheet1 starting in cells A2 and B2 (your program should work if I input 3, 4, 5, … , or 20 data points). Column A will contain the values for variable x and column B will contain the values for variable y. Graphical User Interface Create a UserForm on Sheet1 that contains the following controls: A Run button will be used to execute a macro...

  • P7.5– A theater seating chart is implemented as a two-dimensional array of ticket prices, like this:...

    P7.5– A theater seating chart is implemented as a two-dimensional array of ticket prices, like this: 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 20 20 20 20 20 20 10 10 10 10 20 20 20 20 20 20 10 10 10 10 20 20 20 20 20 20 10 10 20 20 30 30...

  • need question 3 assap using cin and cout outputs please Ctrl CSC 270 Final Exam-Spring2 1) [10 pts] Create anarray x which includes integers fron ltos obtain the array y which, even formula. Displ...

    need question 3 assap using cin and cout outputs please Ctrl CSC 270 Final Exam-Spring2 1) [10 pts] Create anarray x which includes integers fron ltos obtain the array y which, even formula. Display both arrays x and y in a table with labeled column headings. 0 y- 2x+1 2) 120 pts] Consider the following 2D array. 01 2 -1 X-3 5 0 6 -3 7 -15 Use the standard notation and obtain the following (a) Create and display array...

  • Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers...

    Lab #7 CSE110 - Arizona State University Topics • Basic arrays Coding Guidelines • Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc). • Keep identifiers to a reasonably short length. • Use upper case for constants. Use title case (first letter is upper case) for classes. Use lower case with uppercase word separators for all other identifiers (variables, methods, objects). • Use tabs or spaces to indent code within blocks (code surrounded by braces)....

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • Need help Purpose Calculate mileage reimbursements using arrays and methods. The Mathematical Association of America hosts...

    Need help Purpose Calculate mileage reimbursements using arrays and methods. The Mathematical Association of America hosts an annual summer meeting. Each state sends one official delegate to the section officers’ meeting at this summer session. The national organization reimburses the official state delegates according to the scale below. Write a Java program to calculate the reimbursement values, satisfying the specifications below. Details on array and method usage follow these specs. 1. The main method should declare all the variables at...

  • Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt...

    Project 4: Month-end Sales Report with array and validation Input dialog box for initial user prompt with good data and after invalid data Input OK Cancel Input dialog boxes with sample input for Property 1 Ingut X Input Enter the address for Property 1 Enter the value of Property 1: OK Cancel Input dialog boxes after invalid data entered for Property 1 Error Please enter anmumber greater than D Ester the walue of Peoperty t Console output END SALES REPORT...

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • Make a program using Java that asks the user to input an integer "size". That integer...

    Make a program using Java that asks the user to input an integer "size". That integer makes and prints out an evenly spaced, size by size 2D array (ex: 7 should make an index of 0-6 for col and rows). The array must be filled with random positive integers less than 100. Then, using recursion, find a "peak" and print out its number and location. (A peak is basically a number that is bigger than all of its "neighbors" (above,...

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