Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming Help Please? Question 1: Print either \"Fruit\", \"Drink\", or

ID: 3680226 • Letter: J

Question

Java Programming Help Please?

Question 1: Print either "Fruit", "Drink", or "Unknown" (followed by a newline) depending on the value of userItem. Print "Unknown" (followed by a newline) if the value of userItem does not match any of the defined options. For example, if userItem is GR_APPLES, output should be: Fruit

Program with question:

import java.util.Scanner;

public class GrocerySorter {
   public enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};
      public static void main (String [] args) {

      GroceryItem userItem = GroceryItem.GR_APPLES;

      /* Your solution goes here */

      return;
   }
}

Question Two:

Given numRows and numCols, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use separate print statements to print the row and column. Ex: numRows = 2 and numCols = 3 prints:

Coding with question two:

public class NestedLoops {
   public static void main (String [] args) {
      int numRows = 2;
      int numCols = 3;

      // Note: You'll need to define more variables

      /* Your solution goes here */

      System.out.println("");

      return;
   }
}

Question Three:

Print numbers 0, 1, 2, ..., userNum as shown, with each number indented by that number of spaces. For each printed line, print the leading spaces, then the number, and then a newline. Hint: Use i and j as loop variables (initialize i and j explicitly). Note: Avoid any other spaces like spaces after the printed number. Ex: userNum = 3 prints:

Coding with question:

public class NestedLoop {
   public static void main (String [] args) {
      int userNum = 0;
      int i = 0;
      int j = 0;

      /* Your solution goes here */

      return;
   }
}

Question Four:

Write code that prints: userNum ... 2 1 Blastoff! Your code should contain a for loop. Print a newline after each number and after Blastoff!. Ex: userNum = 3 outputs:

Coding with question:

import java.util.Scanner;

public class CountdownRocket {
   public static void main (String [] args) {
      int userNum = 0;
      int i = 0;

      userNum = 3;

      /* Your solution goes here */

      return;
   }
}

Explanation / Answer

Question 1:

Answer:


import java.util.Scanner;
public class GrocerySorter {
public enum GroceryItem {GR_APPLES, GR_BANANAS, GR_JUICE, GR_WATER};
public static void main (String [] args) {
GroceryItem userItem = GroceryItem.GR_APPLES;
/* Your solution goes here */
switch(userItem){
case GR_APPLES:
case GR_BANANAS: System.out.println("Fruit");break;
  
case GR_JUICE:
case GR_WATER: System.out.println("Drink");break;
     
default: System.out.println("UNKNOWN"); break;
}

return;
}
}

Question 2:

Answer

public class NestedLoops {
   public static void main (String [] args) {
   int numRows = 2;
   int numCols = 3;
   // Note: You'll need to define more variables
   /* Your solution goes here */
   char a[] = {'A','B', 'C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
   String s = "";
   for(int i=1; i<=numRows; i++){
       for(int j=1; j<=numCols; j++){
           s = s + i + a[j-1]+" ";
       }
   }
   System.out.println(s);
      

   System.out.println("");
   return;
   }
   }

Question 3:

Answer

public class NestedLoop{
   public static void main (String [] args) {
   int userNum = 0;
   int i = 0;
   int j = 0;
   /* Your solution goes here */
   java.util.Scanner in = new java.util.Scanner(System.in);
       System.out.println("Please enter userNum value: ");
       userNum = in.nextInt();
       String s = "";
       for(i=0; i<=userNum; i++){
           for(j=0; j<i; j++){
               s = s + " ";
           }
           s = s + i + " ";
       }
       System.out.println(s);

   return;
   }
   }

Question 4:

Answer


import java.util.Scanner;
public class CountdownRocket {
public static void main (String [] args) {
int userNum = 0;
int i = 0;
userNum = 3;
/* Your solution goes here */
String s = "";
for(i=userNum; i>0; i--){
   s = s+ i + " ";
   if(i==1){
       s = s +"Blastoff!"+ " ";
   }
}
System.out.println(s);
  
return;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote