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.
  3. This means there will be two programs written. First using compound logic(And,Or). Second, write the same program using nested if statement.
  4. This means that there will be two different pseudcode for the two programs written.

Submit:

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

Solutions

Expert Solution

Using compound logic :


//import package
import java.util.*;

//Java class
public class CompoundLogic {
   // main() method
   public static void main(String[] args) {
       // Object of Scanner class
       Scanner sc = new Scanner(System.in);
       // asking user GPA
       System.out.print("Enter GPA : ");
       // reading GPA
       double GPA = sc.nextDouble();
       // asking user Family income
       System.out.print("Enter Family income : ");
       // reading Family income
       double familyIncome = sc.nextDouble();
       sc.nextLine();
       // asking user resident
       System.out.print("Enter resident : ");
       // reading resident
       String resident = sc.nextLine();
       //This line is using ternary operator in java
       System.out.println(GPA>=3.75 && familyIncome>60000 && resident.toUpperCase().contentEquals("NEW JERSEY")?"Student accepted to XYZ college":"Student not accepted to XYZ college");
   }

}
=====================================

Output :

Screen when meets the requirements :

Screen when requirements does not meet :

**********************************************************

using nested if statement :


//import package
import java.util.*;

//Java class
public class nestedifstatement {
   // main() method
   public static void main(String[] args) {
       // Object of Scanner class
       Scanner sc = new Scanner(System.in);
       // asking user GPA
       System.out.print("Enter GPA : ");
       // reading GPA
       double GPA = sc.nextDouble();
       // asking user Family income
       System.out.print("Enter Family income : ");
       // reading Family income
       double familyIncome = sc.nextDouble();
       sc.nextLine();
       // asking user resident
       System.out.print("Enter resident : ");
       // reading resident
       String resident = sc.nextLine();
       // using nested of checking
       if (GPA >= 3.75) {
           // when GPS is greater then 3.75
           // checking family income
           if (familyIncome > 60000) {
               // when family income greater than 60000 then
               // checking resident
               if (resident.toUpperCase().contentEquals("NEW JERSEY")) {
                   // when resident is of New Jersey then
                   System.out.println("Student accepted to XYZ college");
               }
           }
       }

   }

}
===========================================

Output :


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. Submit: Source code for both...
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