首页 > > 详细

辅导Java语言程序、辅导program程序设计、Java编程调试辅导留学生 Statistics统计、回归、迭代|解析C/C++编程

Assignment 4
Important
Deadline: 10:00 PM, May 30, 2021
You can submit your solution to the OJ system for multiple times. But note that too many
submissions many affect your final score!
You can discuss with your classmates about the assignment but do NOT copy others’
solutions. The OJ system can detect the duplication. If confirmed that there is a plagiarism,
both parties will get 0 mark for this assignment as a penalty.
Note that this time you may need to change the judging environment according to
problem's requirement!
Problems
Problem A - Fraction [Easy, 25 marks, Java (JUnit5)]
Problem B - Triangle [Easy, 25 marks, Java (JUnit5)]
Problem C - Hotel [medium, 50 marks, Java (JUnit5)]
Problem A - Fraction
Description
Design a class Fraction to represent fractions. This class needs to implement the four
operations(plus, subtract, multiply and divide) on fractions and find the reciprocal of a fraction.
Submission
Please select Java(JUnit5) as the judge environment when submitting.
You need submit Fraction.java .
Requirements
Do not modify or remove any methods or fields that have been already defined.
You can add methods or fields that you think are necessary.
This class uses two variables of type int to represent the numerator and denominator
respectively (Both of these variables should be non-negative), and one variable of type
boolean to represent whether the fraction is positive or negative (the value should be true
when the fraction is 0).
Simplify the result after each operation or set the value of the numerator or denominator.
For example, if you get "2/4", you need to convert it to "1/2".
When the numerator is greater than the denominator, there is no need to present the
integer part. For example, "31/30" is a correct output.
For integers, when calling toString() only the numerator should be displayed, like "0", "3" or
"-10".
Sample
You can use FractionTest.java to test. The output of it would be
You are supported to add some test cases yourself to test other situations.
Problem B - Triangle
Description
You need to implement a class to represent triangles. Implement functions to determine if a
triangle is a special triangle (right triangle, isosceles triangle, equilateral triangle) and to determine
if this triangle is similar or congruent to another triangle.
Submission
Please select Java(JUnit5) as the judge environment when submitting.
You need submit Triangle.java .
Requirements
Do not modify or remove any methods or fields that have been already defined.
You can add methods or fields that you think are necessary.
You need a constructor with no arguments to create a triangle with all three sides of length
1. You also need a constructor with three arguments representing the length of three side in
the triangle. If these three arguments do not enclose the triangle (e.g. 1, 1, 2), then a triangle
with all three side lengths of 1 will also be created.
Sample
You can use TriangleTest.java to test. The output of it would be
You are supported to add some test cases yourself to test other situations.
3/4
0.75
4/3
1
1
6.0
12
true
true
Problem C - Hotel
Description
As you know that for some hotels, they have different type of rooms. Everyday, several rooms
have been checked in and several rooms have been checked out, and during the process the
hotel has incomes accordingly. Then you are asked to help a hotel owner to design a room
management system. There are two types of rooms: Ordinary Room and Luxury Room.
Submission
Please select Java(JUnit5) as the judge environment when submitting.
You need submit Hotel.java , ConcreteHotel.java , Day.java , Room.java ,
LuxuryRoom.java and OrdinaryRoom.java .
Do not modify or remove any methods or fields that have been already defined in these two
files Hotel.java and Room.java .
Requirements
Your task is to design following classes:
1. Room and Hotel
Do not modify or remove any methods or fields that have been already defined.
You can add methods or fields that you think are necessary.
You can see the job for each function in Hotel.java by looking at Hotel.html .
2. LuxuryRoom and OrdinaryRoom. Those are the subclasses of the class Room.
LuxuryRoom: adding a private data field named addBed(boolean) with an initial value
false.
OrdinaryRoom: adding a private data field name breakfastCount(int) with an initial
value 0.
toString method: Override toString method in each subclasses. Here the return format
must strictly follow the requirement.
checkOut and checkIn method: Override the abstract method in each subclasses.
You can add other methods or attributes that you think are necessary.
3. Day. We use this class to represent the days of the week. There are three required data
fields to hold the required information
name: private, String. Name of this day.
rate: private, double. The rate of price in this day.
gift: private, String. A gift from the hotel on this day.
Information for this class:
name rate gift
MONDAY MON 0.8 Fruits
TUESDAY TUE 0.75 Drinks
WEDNESDAY WED 0.71 GYM CARD
THURSDAY THU 0.68 Fruits
FRIDAY FRI 1 GYM CARD
SATURDAY SAT 1 HOT SPRINGS
SUNDAY SUN 0.95 SWIMMING
When you call the toString method you will get return value like "Day{name='MON',
rate=0.8, gift='Fruits'}".
4. ConcreteHotel. It is a concrete class of the interface Hotel, in which you need to implement
all the abstract methods that are declared in the interface Hotel. In concrete Hotel, the
following important data field must be defined. Beyond that, you can define any attributes
that you think are important.
rooms: It is a List type, which contains all rooms, including two different types,
in concrete hotel.
5. Other import parameters:
However, there are several initial parameters needs to be mentioned to you, where defining
those parameters depends on your design.
The price of breakfast for one person in Ordinary Room is 180.
The price of adding a bed in Luxury Room is 250.
The initial basic price of Luxury Room is 1200 per night (the breakfast is included).
The initial basic price of Ordinary Room is 500 per night (adding a bed is not allowed).
The calculation of total price for one room per night is
For Luxury Room:
Basic price of Luxury Room * the rate of price in current day + the price of added
beds (if need)
For ordinary Room:
Basic price of Ordinary Room * the rate of price in current day + the price of
breakfast * the number of breakfast.
The initial value of day is MONDAY
Sample
You can use HotelTest.java to test. The output of it would be
private List rooms = new ArrayList<>();
L R1 false
O R2 0
L R3 false
You are supported to add some test cases yourself to test other situations.
L R4 false
L R5 false
L R6 false
L R7 false
O R8 0
O R9 0
O R10 0
O R11 0
O R12 0
1200 500
Day{name='MON', rate=0.8, gift='Fruits'}
Day{name='TUE', rate=0.75, gift='Drinks'}
Day{name='WED', rate=0.71, gift='GYM CARD'}
Day{name='THU', rate=0.68, gift='Fruits'}
Day{name='FRI', rate=1.0, gift='GYM CARD'}
Day{name='SAT', rate=1.0, gift='HOT SPRINGS'}
Day{name='SUN', rate=0.95, gift='SWIMMING'}
R1 R2 R3 R8
R3
3330
Day{name='TUE', rate=0.75, gift='Drinks'}

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!