Question

In: Computer Science

Java Programming Compound Logic and nested if statement For a student to be accepted in XYZ...

Java Programming

Compound Logic and nested if statement

For a student to be accepted in XYZ College, the student must meet the following requirements:

  1. GPA must be 3.75 or higher.
  2. Family income must be more than $60,000
  3. Applicant must be a New Jersey resident.

XYZ college asked you to write a program to implement the above requirements.

  1. Write the program using compound logic (AND, OR) whichever is applicable.
  2. Modify the program using nested if statement.

Submit:

  1. Source code for both version of the program
  2. Output for both versions.
  • Design for both versions

Solutions

Expert Solution

Code (compound logic)

import java.util.*;
public class xyz {

  public static void main(String[] args) 
  {
      Scanner in = new Scanner(System.in);
      System.out.println("Enter GPA : ");
      double gpa = in.nextDouble();
      System.out.println("Enter family income : ");
      int i = in.nextInt();
      System.out.println("Is New Jersey resident (y/n): ");
      char ch = in.next().charAt(0);
      if(gpa>=3.75 && i>60000 && ch=='y')
      {
         System.out.println("Accepted.");
      }
      else
      {
        System.out.println("Rejected.");
      }
  }

}

Code (Nested if)

import java.util.*;
public class xyz {

  public static void main(String[] args) 
  {
      Scanner in = new Scanner(System.in);
      System.out.println("Enter GPA : ");
      double gpa = in.nextDouble();
      System.out.println("Enter family income : ");
      int i = in.nextInt();
      System.out.println("Is New Jersey resident (y/n): ");
      char ch = in.next().charAt(0);
      if(gpa<=3.75)
      {
        System.out.println("Rejected.");
      }
      else if(i<=6000)
      {
        System.out.println("Rejected.");
      }
      else if(ch=='n')
      {
        System.out.println("Rejected.");
      }
      else
      {
        System.out.println("Accepted.");
      }
      
  }

}

Terminal Work (code 1)

Terminal Work(code 2)

.


Related Solutions

Java Programming Compound Logic and nested if statement For a student to be accepted in XYZ...
Java Programming Compound Logic and nested if statement For a student to be accepted in XYZ College, the student must meet the following requirements: GPA must be 3.75 or higher. Family income must be more than $60,000 Applicant must be a New Jersey resident. XYZ college asked you to write a program to implement the above requirements. Write the program using compound logic (AND, OR) whichever is applicable. Modify the program using nested if statement. This means there will be...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner...
This for Java Programming Write a java statement to import the java utilities. Create a Scanner object to read input. int Age;     Write a java statement to read the Age input value 4 . Redo 1 to 3 using JOptionPane
/* Homework Lab 8 Nested If statements Write the nested decision logic to print the recommended...
/* Homework Lab 8 Nested If statements Write the nested decision logic to print the recommended meal based on the user's choices for Restaurant and Load given the table shown below: Restaurant Preference Meal ----------------------------------------------------- (M)cDonald's (B)eef Quarter Pounder            (C)hicken Chicken McNuggets            (F)ish Filet-o-Fish            (S)alad Side Salad (O)utback            (B)eef Ribeye            (C)hicken Alice Springs Chicken            (F)ish Grilled Tilapia            (S)alad Aussie...
Be able to determine the runtime complexity of: A Java assignment statement A single loop Nested...
Be able to determine the runtime complexity of: A Java assignment statement A single loop Nested loop Given that for any polynomial of degree n, p(x) = anxn + an-1 xn-1 + …a1x + a0, p(x) = O(xn).  Show that: an expression such as the following                                                               4x3 + 7x2 + 12 is O(x3), by finding the witnesses, C and k.       Which of the following statements are true?                                              The running time of a loop is, at most, the running time of...
Be able to determine the runtime complexity of: A Java assignment statement A single loop Nested...
Be able to determine the runtime complexity of: A Java assignment statement A single loop Nested loop Given that for any polynomial of degree n, p(x) = anxn + an-1 xn-1 + …a1x + a0, p(x) = O(xn).              Show that:            an expression such as the following                                                               4x3 + 7x2 + 12 is O(x3), by finding the witnesses, C and k.      Which of the following statements are true?                                              The running time of a loop is, at most, the running time of...
object oriented programming java Create a Student class that have two data members id (assign to...
object oriented programming java Create a Student class that have two data members id (assign to your ID) and name (assign to your name). Create the object of the Student class by new keyword and printing the objects value. You may name your object as Student1. The output should be like this: 20170500 Asma Zubaida
What is the difference between Fact and Query in a logic programming language?
What is the difference between Fact and Query in a logic programming language?
Write a program that produces the following output using nested for loop in Java. ****** ////////////...
Write a program that produces the following output using nested for loop in Java. ****** //////////// ****** ***** //////////\\ ***** **** ////////\\\\ **** *** //////\\\\\\ *** ** ////\\\\\\\\ ** * //\\\\\\\\\\ * \\\\\\\\\\\\
Conceptually the two most common logics are propositional logic and Predicate Logic. An undergraduate student who...
Conceptually the two most common logics are propositional logic and Predicate Logic. An undergraduate student who took a course of discrete mathematics is inquiring as to how propositional and predicate logics can be used in software testing. How are ask to guide this student in this quest. One pointer may consist in presenting the characteristics and limitations of both logic as well as their use as a mean for software testing. Which Logic is most adequate for formal verification of...
Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT