Working With Abstraction Lab

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Working with Abstraction: Lab

Problem 1. Rhombus of Stars


Create a program that reads a positive integer n as input and prints on the console a rhombus with size n:

Examples
input output input output input output input output
1 * 2 * 3 * 4 *
* * * * * *
* * * * * * *
* * * * * *
* * * *
* *
*

Hint
Create a PrintRow() method to easily reuse code.

Problem 2. Point in Rectangle


Create a class Point and a class Rectangle. The Point should hold coordinates X and Y and the Square should hold 2
Points – its top left and bottom right corners. In the Rectangle class, you should implement a Contains(Point
point) method that returns true or false, based on whether the Point given as attribute is inside or outside of the
Rectangle object. Points on the side of a Square are considered inside.

Input
 On the first line read the coordinates of the top left and bottom right corner of the Rectangle in the format:
“<topLeftX> <topLeftY> <bottomRightX> <bottomRightY>”.
 On the second line, read an integer N and on the next N lines, read the coordinates of points.

Output
 For each point, print out the result of the Contains() method.

Examples
input output input output input output
0 0 3 3 True 2 -3 12 3 True 5 8 12 15 False
5 True 4 True 6 True
0 0 False 8 -1 False 0 0 True
0 1 False 11 3 False 5 8 True
4 4 True 1 1 12 15 True
5 3 2 4 8 15 True
1 2 7 15
8 12

Page 1 of 3
Problem 3. Student System
You are given a working project for a small Student System, but the code is very poorly organized. Break up the
code logically into smaller functional units – methods and classes and don’t break the functionality.
The program supports the following commands:
 “Create <studentName> <studentAge> <studentGrade>” – creates a new student and adds them to the
repository.
 “Show <studentName>” – prints on the console information about a student in the format:
“<studentName> is <studentAge> years old. <commentary>”, where the commentary is based on the
student’s grade.
 “Exit” – closes the program.
Do not add any extra validation or functionality to the app!

Examples
input output
Create Pesho 20 5.50 Pesho is 20 years old. Excellent student.
Create Mimi 18 4.50 Mimi is 18 years old. Average student.
Create Gosho 25 3
Show Pesho
Show Mimi
Exit

Problem 4. Hotel Reservation


Create a class PriceCalculator that calculates the total price of a holiday, given the price per day, number of days,
the season and a discount type. The discount type and season should be enums.
Use the class in your Main() method to read input and print on the console the price of the whole holiday.
The price per day will be multiplied depending on the season by:
 1 during Autumn
 2 during Spring
 3 during Winter
 4 during Summer
The discount is applied to the total price and is one of the following:
 20% for VIP clients
 10% for clients, visiting for a second time
 0% if there is no discount

Input
On a single line you will receive all the information about the reservation in the format:
“<pricePerDay> <numberOfDays> <season> <discountType>”, where:
 The price per day will be a valid decimal in the range [0.01…1000.00]
 The number of days will be a valid integer in range [1…1000]
 The season will be one of: Spring, Summer, Autumn, Winter
 The discount will be one of: VIP, SecondVisit, None, but it can also be omitted from the input

Page 2 of 3
Output
On a single line, print the total price of the holiday, rounded to 2 digits after the decimal separator.

Examples
input output

50.25 5 Summer VIP 804.00

40 10 Autumn SecondVisit 360.00

120.20 2 Winter 721.20

Page 3 of 3

You might also like