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...
/* 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...
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
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...
IN JAVA Create a program that uses a nested for loop to display a rectangle of...
IN JAVA Create a program that uses a nested for loop to display a rectangle of #'s with a given number of rows and columns,. This should only display the # when the column is an odd number (see examples below). Get the number of rows and columns from the user, and display the result. Examples: If the user provided rows=4, and columns=7, the program should display a pattern as follows: # # # # # # # # #...
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. ****** //////////// ****** ***** //////////\\ ***** **** ////////\\\\ **** *** //////\\\\\\ *** ** ////\\\\\\\\ ** * //\\\\\\\\\\ * \\\\\\\\\\\\
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All...
JAVA PROGRAMMING Part 1 Create a class Student, with attributes id, first name, last name. (All the attributes must be String) Create a constructor that accepts first name and last name to create a student object. Create appropriate getters and setters Create another class StudentOperationClient, that contains a main program. This is the place where the student objects are created and other activities are performed. In the main program, create student objects, with the following first and last names. Chris...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT