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...
/* 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