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

Part 2: Programming (15 pts) Write a Java program called Assignment4.java. The p

ID: 3756656 • Letter: P

Question

Part 2: Programming (15 pts) Write a Java program called Assignment4.java. The program is repeatedly to read a list of A. This program will follow a very simple loop command-program. Ask Question Get inputs Calculate Display results 4 of 8 O 2018 Yoshihiro Kobayashi eykobaya@asu edu> Format: Input: B B BA A AABCCAO Output GPA 3.27 This assignment has only one task, but the development process is decomposed into two steps. Follow the instruction one by one. Don't go to the next step if vour program does not Stepl The first step is to develop a loop command program to execute several different functions corresponding to the imput letter command. When the program starts, it displays the help-message below, "Choose (A: add grades)N new grades) or (Q quit)" and waits for the user input. When a command is input, execute a function corresponding to the command (look at the table below). Once it is completed, it displays the help-message again and waits for the other user input. The loop coetinues until the user inputs 'Q' or q which is to terminate the program. Command Function A or 'a'Display "Type the additional input in aingle line 1 Pt) N' or 'n'Display "Type a new 11st of input in single line Display End of program and, terminate the program Other Display letters Invalid command was input!

Explanation / Answer

Assignment4.java

import java.util.Scanner;

/*
   a) 'a' asks for the user to input 1s and 0s on one line with * at the end
       'b' says invalid command, try again
       'r' says the data is refreshed
       'q' says *** end of program ***
   b) if (command == 'D') { display the result; }
   c) num0 is *** num1 is ****
   d) System.out.printf(" %4s|", Num0);
       for (int i = 0; i < num0; i++) System.out.print("*");
       System.out.println();
       System.out.prinf(" %4s|", Num1);
       for (int i = 0; i < num1; i++) System.out.print("*");
       System.out.println();
       Num0| ***
       Num1| ****
   e) if (command == 'R')
*/

public class Assignment4
{
   public static void main(String[] args)
   {
       /*
       char command;
       Scanner in = new Scanner(System.in);
       int num0 = 0;
       int num1 = 0;
       do
       {
           System.out.println("Choose (A: add scores), (R: refresh scores), or (Q: quit)");
           String temp = in.next();
           command = temp.toUpperCase().charAt(0);

           System.out.println(command);
           if (command == 'A')
           {
               System.out.println("Input 0s and 1s in one line. and put * at the end");
               while (in.hasNextInt())
               {
                   int input = in.nextInt();
                   if (input == 0)
                   {
                       num0++;
                   }
                   else if (input == 1)
                   {
                       num1++;
                   }
               }
           }
           else if (command == 'R')
           {
               System.out.println("The data is refreshed");
           }
           else if (command == 'Q')
           {
               System.out.println("*** End of Program ***");
           }
           else if (command == 'D')
           {
               System.out.println(" %4S|", num0);
               for (int i = 0; i <num0; i++)
               {
                   System.out.print("*");
                   System.out.println();
               }
               for (int i = 0; i < num1; i++)
               {
                   System.out.println("*");
                   System.out.println();
               }
           }
           else
           {
               System.out.println("Invalid command. Try again");
           }
       }while (command != 'Q');
       */

       Scanner scan = new Scanner (System.in);
       char command;
       String temp;
       int numA = 0;
       int numB = 0;
       int numC = 0;

       do
       {
           System.out.println("Choose (A: add grades), (N: new grads), or (Q: quit):");
           temp = scan.next();
           command = temp.toUpperCase().charAt(0);
           System.out.println(command);

           if (command == 'A')
           {
               System.out.println("Add grades");
           }
           else if (command == 'N')
           {
               System.out.println("Type a new list of input in single line");
           }
           else if (command == 'Q')
           {
               System.out.println("*** End of program ***");
           }
           else
           {
               System.out.println("Invalid command was input!");
           }
       } while (command != 'Q');
   }
}