获取并设置此接口的方法 [英] Get and set methods for this interface

查看:78
本文介绍了获取并设置此接口的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我是java编程的新手,并且正在努力学习接口,抽象类,set和get方法。我知道这些是OOP的基础知识。





有人可以帮我解决以下部分问题:

in iterface EssentialLivingCosts我应该包含更多内容以便我可以从课堂上访问它OncampusStudents



fullproblem:

写一个使用面向对象编程计算大学生年度开支成本的程序。代码使用以下条件。



1.制作一个抽象的UniversityStudent Class来编写以下条件。您必须使用构造函数,setter和getter并将字段设为私有。



对于所有学生:姓名和年份(新生,大二,大三,大四)(这些是除年份以外的所有领域,即ArrayList)年度课程数量(假设每个课程是3学分)(这是一个字段并分配一个恒定的费用值1000.30 $ /课程)



2.创建一个名为EssentialLivingCost的接口有3种计算方法:食品,教科书和杂项的成本。 (服装,娱乐等)。 (这是一种抽象方法)



3.制作2个具体类,称为OnCampusStudent和OffCampusStudent。这些类扩展了UniversityStudent类并实现了EssentialLivingCost接口。相应地对相应的方法进行编码,对于OnCampusStudent,将一年的住房成本分配为12000美元/年。对于OffCampusStudent,请问他的住所。如果是Surrey,住房的费用是7200美元/年,如果Burnaby是13200美元/年。



4.现在编写主类,在这里询问名称学生,他的学习年限,食物费用,教科书和杂项,他的生活地点,一年中的课程数量。使用来自2个具体类的实例化对象来查找该年度学生的总成本。打印学生的姓名,他在学校的一年以及他估计的每年总费用。



我尝试了什么:



公共界面EssentialLivingCost {

公共抽象双食();

公共抽象双书();

public abstract double clothes();

public abstract double transport();

public abstract double misc();



}

So i am new to java programming and struggling with interfaces, abstract class, set and get methods. i know these are the basics of OOP.


CAN someone please help me with the following part of my problem:
in iterface EssentialLivingCosts what should i include more so that i can access it from the class OncampusStudents

fullproblem:
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.

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)

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 13200$/year.

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.

What I have tried:

public interface EssentialLivingCost {
public abstract double food();
public abstract double books();
public abstract double clothes();
public abstract double transport();
public abstract double misc();

}

推荐答案

/ course)



2.使用名称创建一个接口EssentialLivingCost有3种计算方法:食品,教科书和杂项的成本。 (服装,娱乐等)。 (这是一种抽象方法)



3.制作2个具体类,称为OnCampusStudent和OffCampusStudent。这些类扩展了UniversityStudent类并实现了EssentialLivingCost接口。相应地编码相应的方法,并且OnCampusStudent将一年的住房成本分配为12000
/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)

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。对于OffCampusStudent,请问他的住所。如果是萨里,住房的费用是7200
/year. For OffCampusStudent, ask his place of dwelling. If Surrey, the cost of housing is 7200


/年,如果Burnaby是13200
/year and if Burnaby it is 13200


这篇关于获取并设置此接口的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆