Skip to content

Commit

Permalink
Update Chapter 9 Problems for Champions Part 2 - Minor Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexpeev9 committed Aug 17, 2021
1 parent 72008ed commit 7cb7905
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions chapter-09-problems-for-champions-part-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@ In this chapter we will review three additional problems that belong to the cate

## More Complex Problems on the Studied Material

Before we move on to particular tasks, we must clarify that these can be solved in an easier way with **additional knowledge in programming with Java** (methods, arrays, collections, recursion, etc.), but each solution that will be provided now only uses the material covered in this book. The goal is to learn how to construct **more complex algorithms** based on your knowledge collected up to the present moment.
Before we move on to particular tasks, we must clarify that these can be solved more easily way with **additional knowledge in programming with Java** (methods, arrays, collections, recursion, etc.), but each solution that will be provided now only uses the material covered in this book. The goal is to learn how to construct **more complex algorithms** based on your knowledge collected up to the present moment.


## Problem: Passion Shopping Days

Lina has a real shopping passion. When she has some money, she immediately goes to the closest shopping center (mall) and tries to spend as much as she can on clothes, bags and shoes. But her favorite thing are winter sales. Our task is to analyze her strange behavior and **calculate the purchases** that Lina does when she enters the mall, as well as the **money she has left** when the shopping is over. All prices and money are in BGN (Bulgarian levs, **lv**).
Lina has a real shopping passion. When she has some money, she immediately goes to the closest shopping center (mall) and tries to spend as much as she can on clothes, bags, and shoes. But her favorite thing is winter sales. Our task is to analyze her strange behavior and **calculate the purchases** that Lina does when she enters the mall, as well as the **money she has left** when the shopping is over. All prices and money are in BGN (Bulgarian levs, **lv**).

The **first line** of the input will pass the **amount** that Lina has **before** she starts shopping. After that, upon reading the "**`mall.Enter`**" command, Lina enters the mall and starts shopping until the "**`mall.Exit`**" command is given. When Lina starts shopping, **on each line** of the input you will be given strings that are **actions performed by Lina**. Each **symbol** in the string is a **purchase or another action**. String commands contain only symbols of the **ASCII table**. The ASCII code of each sign is **related to what Lina must pay** for each of the goods. You need to interpret the symbols in the following way:

- If the symbol is a **capital letter**, Lina gets a **50% discount**, which means that you must decrease the money she has by 50% of the numeric representation of the symbol from the ASCII table.
- If the symbol is a **small letter**, Lina gets a **70% discount**, which means that you must decrease the money she has by 30% of the numeric representation of the symbol from the ASCII table.
- If the symbol is **"`%`"**, Lina makes a **purchase** that decreases her money in half.
- If the symbol is **"`*`"**, Lina **withdraws money from her debit card** and adds 10 lv. to her available funds.
- If the symbol is **different from all of the aforementioned**, Lina just makes a purchase without discount, and in this case you should simply subtract the value of the symbol from the ASCII table from her available funds.
- If the symbol is **different from all of the aforementioned**, Lina just purchases without discount, and in this case, you should simply subtract the value of the symbol from the ASCII table from her available funds.

If a certain value of her purchases is **higher** than her current available funds, Lina **DOES NOT** make the purchase. Lina's funds **cannot be less than 0**.

The shopping ends when the "**`mall.Exit`**" command is given. When this happens, you need to **print the number of purchases made and the money** that Lina has left.

### Input Data

The input data must be read from the console. The **first line** of the input will indicate the **amount that Lina has before starting to purchase**. On each of the following lines there will be a particular command. After you read the command "**`mall.Enter`**", on each of the following lines you will be given strings holding **information regarding the purchases / actions** that Lina wants to perform. These strings will keep being passed, until the "**`mall.Exit`**" command is given.
The input data must be read from the console. The **first line** of the input will indicate the **amount that Lina has before starting to purchase**. On each of the following lines there will be a particular command. After you read the command "**`mall.Enter`**", on each of the following lines, you will be given strings holding **information regarding the purchases/actions** that Lina wants to perform. These strings will keep being passed until the "**`mall.Exit`**" command is given.

Always only one "**`mall.Enter`**" command will be given, as well as only one "**`mall.Exit`**" command.

Expand All @@ -37,7 +37,7 @@ When shopping is over, you must print on the console a particular output dependi
- If **no purchases have been made** – "**No purchases. Money left: {remaining funds} lv.**"
- If **at least one purchase** is made – "**{number of purchases} purchases. Money left: {remaining funds} lv.**"

**The funds** must be printed with **accuracy of up to 2 symbols after the decimal point**.
**The funds** must be printed with an **accuracy of up to 2 symbols after the decimal point**.

### Constraints

Expand All @@ -64,21 +64,21 @@ We will separate the solution of the problem into three main parts:
- **Algorithm** for solving the problem.
- Formatting the **output**.

Let's examine each of the parts in details.
Let's examine each of the parts in detail.

#### Processing the Input Data

The input of our task consists of a few components:
- On the **first line we have all the money** that Lina has for shopping.
- On **each of the following lines** we will have some kind of a **command**.
- On the **first line, we have all the money** that Lina has for shopping.
- On **each of the following lines**, we will have some kind of **command**.

The first part from the reading is trivial. We should keep in mind that we will be using the **`BigDecimal`** type, because we are working with money and we need precise accuracy:
The first part of the reading is trivial. We should keep in mind that we will be using the **`BigDecimal`** type because we are working with money and we need precise accuracy:

![](assets/chapter-9-2-images/01.Passion-days-01.png)

The second one contains a detail that we need to take into consideration. The requirements state the following:

> On each of the following lines there will be a particular command. After you read the command "**`mall.Enter`**", on each of the following lines you will be given strings containing information regarding the purchases / actions that Lina wants to perform.
> On each of the following lines, there will be a particular command. After you read the command "**`mall.Enter`**", on each of the following lines you will be given strings containing information regarding the purchases/actions that Lina wants to perform.
This is where we need to take into consideration the fact that from the **second input line on, we need to start reading commands**, but **only after we read** the command **"mall.Enter"**, we must start processing them. How can we do this? Using a **`while`** or a **`do-while`** loop is a good option. Here is an exemplary solution of how **to skip** all commands before processing the command "**`mall.Enter`**":

Expand Down

0 comments on commit 7cb7905

Please sign in to comment.