Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Policy: Solve the programs as per instructions given in each question. Submit th

ID: 3891630 • Letter: P

Question

Policy: Solve the programs as per instructions given in each question. Submit the codes in Moodle. Submission requires 5 .java files only with the names: UniversityStudent.java, EssentialLivingCost.java, OnCampusStudent.java, OffCampusStudent.java and Main.java. Do not change the Class Names. Problem Write a program that computes the cost of yearly expenses of a university student using Object Oriented Programming. Code using the conditions below 1. Make an Abstract UniversityStudent Class to code the conditions below. You must use constructor, setters and getters and make the fields private. [5 Marks] For all students name and year (freshman, sophomore, junior, senior) (These are all fields except year which is an ArrayList) number of courses for the year (Assuming each course is 3 credits) (This is a field and Assign a constant fee value of 1000.30$/course) 2. Make an Interface with name EssentialLivingCost which has the 3 methods to calculate: costs of food, textbooks and misc. (clothing, entertainment etc.). (This is an abstract methods) [5 Marks] 3. Make 2 concrete classes known as OnCampusStudent and OffCampusStudent. These classes extend the UniversityStudent Class and Implement the EssentialLivingCost Interface. Code the respective methods accordingly and for OnCampusStudent assign cost of housing for a year to be 12000$/year. For OffCampusStudent, ask his place of dwelling. If Surrey, the cost of housing is 7200$/year and if Burnaby it is 13200S/year. [10 Marks] 4. Now code the Main Class, ask here the name of the student, his year of study, cost of food, textbooks and misc, his place of living, number of courses in the year. Use instantiated objects from the 2 concrete classes to find the total cost of the student for the year. Print the Student's name, his year at the school and his total estimated yearly cost. [10 Marks]

Explanation / Answer

Hi,

Please find the java classes below:

---------

import java.util.ArrayList;

/**
* @author
*
*/
public abstract class UniversityStudent {

   private String name;
   private int year;
   private ArrayList<String> courses;
   private static final int COURSEFEE = 30;

   public UniversityStudent(String name,ArrayList<String> courses,int year) {
       this.name=name;
       this.courses=courses;
       this.year=year;
   }

   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }

   public void setCourses(ArrayList<String> courses) {
       this.courses = courses;
   }
   public ArrayList<String> getCourses() {
       return courses;
   }
   public void setYear(int year) {
       this.year = year;
   }

   public int getYear() {
       return year;
   }

}


------------

/**
*
*/

/**
* @author
*
*/
public interface EssentialLivingCost {

   public abstract double costOfFood() ;

   public abstract double costOfTextBooks() ;

   public abstract double costOfMisc() ;
}

-----------------

/**
*
*/

import java.util.ArrayList;

/**
* @author
*
*/
public class OnCampusStudent extends UniversityStudent implements EssentialLivingCost {
   private double costOfLiving;
   private double costOfFood;
   private double costOfTextBooks;

   public void setCostOfFood(double costOfFood) {
       this.costOfFood = costOfFood;
   }

   public void setCostOfTextBooks(double costOfTextBooks) {
       this.costOfTextBooks = costOfTextBooks;
   }

   //OnCampusStudent constructor
   public OnCampusStudent(String name,ArrayList<String> courses,int year) {
       super(name,courses,year);
       costOfLiving=12000.00;
   }

   public double getCostOfLiving() {
       return costOfLiving;
   }

   @Override
   public double costOfFood() {
       return costOfFood;
   }

   @Override
   public double costOfTextBooks() {
       return costOfTextBooks;
   }

   @Override
   public double costOfMisc() {
       return 0;
   }

   public double totalCost() {
       return getCostOfLiving() + costOfFood() + costOfTextBooks() +costOfMisc() ;
   }

   @Override
   public String toString() {
       return " On Campus Student Details: "
               + " Name:" + getName()
               + " Year:" + getYear()
               + " TotalCost:" + totalCost();

   }

}

---------------------------

/**
*
*/

import java.util.ArrayList;

/**
* @author
*
*/
public class OffCampusStudent extends UniversityStudent implements EssentialLivingCost {
   private String placeOfDwell;
   private double costOfLiving;
   private double costOfFood;
   private double costOfTextBooks;

   public void setCostOfFood(double costOfFood) {
       this.costOfFood = costOfFood;
   }

   public void setCostOfTextBooks(double costOfTextBooks) {
       this.costOfTextBooks = costOfTextBooks;
   }


   public String getPlaceOfDwell() {
       return placeOfDwell;
   }

   public void setPlaceOfDwell(String placeOfDwell) {
       this.placeOfDwell = placeOfDwell;
   }

   public double getCostOfLiving() {
       return costOfLiving;
   }

   public void setCostOfLiving() {
       if(placeOfDwell.equalsIgnoreCase("Surrey")) {
           this.costOfLiving = 7200.00;
       }else if(placeOfDwell.equalsIgnoreCase("Burnaby")) {
           this.costOfLiving =13200.00;
       }

   }


   //OffCampusStudent constructor
   public OffCampusStudent(String name,ArrayList<String> courses,int year,String place) {
       super(name,courses,year);
       this.placeOfDwell=place;
       setCostOfLiving();
   }

   @Override
   public double costOfFood() {
       return costOfFood;
   }

   @Override
   public double costOfTextBooks() {
       return costOfTextBooks;
   }

   @Override
   public double costOfMisc() {
       return 200.00;
   }

   @Override
   public String toString() {
       return " Off Campus Student Details: "
               +" Name:" + getName()
               + " Year:" + getYear()
               + " TotalCost:" + totalCost();

   }

   public double totalCost() {
       return getCostOfLiving() + costOfFood() + costOfTextBooks() +costOfMisc() ;
   }

}

-------------------

import java.util.ArrayList;
import java.util.Scanner;

public class Main {

   public static void main(String[] args) {
       Scanner keyboard=new Scanner(System.in);
       char choice;
       String name;
       int year;
       String place;
       System.out.println("--------Program ----------- ");
       do {
           displayMenu();
           System.out.println("Enter your choice:");
           choice=keyboard.nextLine().charAt(0);
           switch(choice) {
           case 'a':
           case 'A':
               ArrayList<String> ArrayList<String>();
               System.out.print("Enter name of the student: ");
               name=keyboard.nextLine();
               System.out.print("Enter year of study: ");
               year=keyboard.nextInt();
               oncourses.add("Maths");oncourses.add("Physics");
               OnCampusStudent campusStudent=new OnCampusStudent(name,oncourses,year);
               System.out.println(campusStudent.toString());
               break;
           case 'b':
           case 'B':
               ArrayList<String> offcourses=new ArrayList<String>();;
               System.out.println("Enter name of the student: ");
               name=keyboard.nextLine();
               System.out.println("Enter year of study: ");
               year=keyboard.nextInt();
               offcourses.add("Chemistry");offcourses.add("Computers");
               System.out.println("Enter place of stay: ");
               place=keyboard.nextLine();
               OffCampusStudent offcampusStudent=new OffCampusStudent(name,offcourses,year,place);
               System.out.println(offcampusStudent.toString());
               break;
           case 'z':
           case 'Z':
               break;
           }
       }while (choice != 'Z' ||choice != 'z' );
       keyboard.close();  
   }

   public static void displayMenu() {
       System.out.println("A. OnCampusStudent. ");
       System.out.println("B. OffCampusStudent. ");
       System.out.println("Z. Exit. ");
   }
}

--------------------------

Note: i have not used course fee and credits. Kindly let me know the logic or kindly add the code.

Let me know if something is missing.