Question

In: Computer Science

Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...

  • Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following:
    • Declare an array reference variable called myFavoriteSnacks for an array of String type.
    • Create the array so that it is able to hold 10 elements - no more, no less.
    • Fill the array by having each array element contain a string stating one of your favorite foods/snacks.
      • Note: Only write the name of the snack, NO numbers (i.e. Do not write "1. cookies")
    • Use a loop to print out the contents of the array.
  • Your program MUST:
    • Actively use in-line comments stating what each section of code does.
    • Print out the numbers 1 to 10 -- NOT 0 to 9 (see Example Output below)
  • Your program must conform to the Java coding standards

Solutions

Expert Solution

Source Code:

Output:

Code in text format (See above image of code for indentation):

import java.util.*;

/*class definition*/

public class LastnameFirstname09

{

    /*main method*/

    public static void main(String[] args)

    {

        /*Scanner object to read data from the user*/

        Scanner in=new Scanner(System.in);

        /*array declaration*/

        String[] myFavoriteSnacks=new String[10];

        /*read item names from user and store in array using loop*/

        System.out.println("Enter 10 items in one of your favorite foods/snacks:");

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

            myFavoriteSnacks[i]=in.nextLine();

        /*print contents of the array*/

        System.out.println("Your favourite foods/snacks");

        System.out.println("-------------------------------------");

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

            System.out.println(i+1+"\t"+myFavoriteSnacks[i]);

    }

}


Related Solutions

Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
jgrasp environment, java write a complete program that prompts the user to enter their first name,...
jgrasp environment, java write a complete program that prompts the user to enter their first name, middle name, and last name (separately). print out thier name and initials, exactly as shown: your name is: John Paul Chavez your initials are: J. P. C. use string method chartAt() to extract the first (zero-th) character from a name(the name is a string type): username.charAt(0). thank you.
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other.
java programming write a program with arrays to ask the first name, last name, middle initial,...
java programming write a program with arrays to ask the first name, last name, middle initial, IDnumber and 3 test scores of 10 students. calculate the average of the 3 test scores. show the highest class average and the lowest class average. also show the average of the whole class. please use basic codes and arrays with loops the out put should look like this: sample output first name middle initial last name    ID    test score1 test score2...
Write a Java program using jGRASP directions are as follows: Uses a while loop to print...
Write a Java program using jGRASP directions are as follows: Uses a while loop to print the numbers from 3 - 19. Uses a do-while loop to print the numbers from 42 - 56. Uses a for loop to print the numbers from 87 - 95. Asks the user for 2 numbers. Uses a loop to print all numbers between the given numbers, inclusive. Note: Consider that your user's second number can be lower! (see example below) Note: Also consider...
Write a class named Person with data attributes for a person’s first name, last name, and...
Write a class named Person with data attributes for a person’s first name, last name, and telephone number. Next, write a class named Customer that is a subclass of the Person class. The Customer class should have a data attribute for a customer number and a Boolean data attribute indicating whether the customer wishes to be on a calling list. Demonstrate an instance of the Customer class in a simple program. Using python
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
Write a short, cohesive java program in jGrasp that interacts with the user and does the...
Write a short, cohesive java program in jGrasp that interacts with the user and does the following: create at least 2 double variables create at least 1 constant get at least 1 string input from the user get at least 1 int/double input from the user include both, incorporating the input you got from the user: 1 multiway if-else with at least 3 "else if" 1 nested if Your program should combine all of these into one cohesive, interactive program...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
C++ Write a program that asks a teacher to input a student’s first name, last name,...
C++ Write a program that asks a teacher to input a student’s first name, last name, and four test scores. The program should find the average of the four test scores and should then write the following information to a file named “students.txt” last_name first_name average A student's first name of “XX” should be used as a sentinel value and no numeric grades less than 0 or greater than 100 should be accepted.  The program should then read the information in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT