Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.62 KB | None | 0 0
  1. /*  COPYRIGHT OF CONCORDIA UNIVERSITY
  2.     DEPARTMENT OF ENGINEERING AND COMPUTER SCIENCE
  3.  
  4.     COMP248 LAB7    Fall 2019
  5.     PROF: Nancy Acemian
  6.  
  7.     Topic: Simple Class  
  8.  */
  9. import java.util.Scanner;
  10. public class School {
  11.         // Declare instance variables
  12.     private String program, university;
  13.     private double tuition;
  14.    
  15.     // Implement default constructor
  16.     public School() {
  17.         program = university = null;
  18.         tuition = 0.0;
  19.     }
  20.     public School(String program, String university, double tuition) {
  21.         this.program = program;
  22.         this.university = university;
  23.         this.tuition = tuition;
  24.     }
  25.     // Implement Get/Set methods
  26.     public String getProgram() {
  27.         return program;
  28.     }
  29.     public String getUniversity() {
  30.         return university;
  31.     }
  32.     public double getTuition() {
  33.         return tuition;
  34.     }
  35.     public void setProgram(String p) {
  36.         this.program = p.toUpperCase();
  37.     }
  38.     public void setUniversity(String university) {
  39.         this.university = university.toUpperCase();
  40.     }
  41.     public void setTuition(double tuition) {
  42.         this.tuition = tuition;
  43.     }
  44.     // Implement toString method
  45.     public String toString() {
  46.         return "University name: " + university + "\nProgram name: " + program + "\nTuition: $" + tuition;
  47.     }
  48.    
  49.     // Implement equals method
  50.     public boolean equals(School school) {
  51.         return this.program.equals(school.program) && this.university.equals(school.university) && this.tuition == school.tuition;
  52.     }
  53.    
  54.     // Implement isCheaper method
  55.     public boolean isCheaper(School school) {
  56.         return this.tuition < school.tuition;
  57.     }
  58.  
  59.  
  60. /* ================================================================================================== */
  61. /* =====*****-----+++++!!!!! DO NOT ALTER, CHANGE, OR MODIFY THE CODE BELOW !!!!!+++++-----*****===== */
  62. /* ================================================================================================== */
  63.  
  64.     public static void main(String[] args) {
  65.         School school1 = new School();
  66.         School school2 = new School();
  67.         Scanner keyIn = new Scanner(System.in);
  68.         String temp;
  69.        
  70.         System.out.println("Enter info for your 1st choice:");
  71.         System.out.print("Enter university name: ");
  72.         school1.setUniversity(keyIn.nextLine());
  73.         System.out.print("Enter program: ");
  74.         school1.setProgram(keyIn.nextLine());
  75.         System.out.print("Enter tuition: $");
  76.         school1.setTuition(keyIn.nextDouble());
  77.        
  78.         System.out.println("\nHere is what you entered as your 1st choice:");
  79.         System.out.println("University name: " + school1.getUniversity());
  80.         System.out.println("Program: " + school1.getProgram());
  81.         System.out.println("Tuition: $" + school1.getTuition());
  82.        
  83.         System.out.println("\nEnter info for your 2nd choice: ");
  84.         temp = keyIn.nextLine();
  85.         System.out.print("Enter university name: ");
  86.         school2.setUniversity(keyIn.nextLine());
  87.         System.out.print("Enter program: ");
  88.         school2.setProgram(keyIn.nextLine());
  89.         System.out.print("Enter tuition: $");
  90.         school2.setTuition(keyIn.nextDouble());
  91.        
  92.         System.out.println("\nHere is what you entered as your 2nd choice:");
  93.         System.out.println(school2);
  94.        
  95.         if (school1.equals(school2))
  96.         System.out.println("?!?! --- Do you realize your 2 choices are identical --- ?!?!");
  97.         System.out.println();
  98.         if (school1.isCheaper(school2))
  99.             System.out.println("Mom & Dad .. see my 1st choice is cheaper than my second choice");
  100.         else if (school2.isCheaper(school1))
  101.             System.out.println("Mom & Dad, my 1st choice is more expensive, but please I really want to go to "+ school1.getUniversity());
  102.         else
  103.             System.out.println("Mom & Dad, seeeee ... they are the same price!");
  104.        
  105.         System.out.println("\nYour Java program says \"Hope you get your 1st choice!\"");
  106.         keyIn.close();
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement