This repository was archived by the owner on Mar 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 384
update prompts #409
Merged
Merged
update prompts #409
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// Mobile struct represents a mobile device. | ||
type Mobile struct { | ||
Brand string | ||
Model string | ||
IsOn bool | ||
Battery int | ||
LastUsage time.Time | ||
} | ||
|
||
// TurnOn turns on the mobile device. | ||
func (m *Mobile) TurnOn() { | ||
m.IsOn = true | ||
m.LastUsage = time.Now() | ||
fmt.Printf("%s %s is now turned on.\n", m.Brand, m.Model) | ||
} | ||
|
||
// TurnOff turns off the mobile device. | ||
func (m *Mobile) TurnOff() { | ||
m.IsOn = false | ||
fmt.Printf("%s %s is now turned off.\n", m.Brand, m.Model) | ||
} | ||
|
||
// UseMobile simulates the usage of the mobile device. | ||
func (m *Mobile) UseMobile(minutes int) { | ||
if !m.IsOn { | ||
fmt.Println("Please turn on the mobile device first.") | ||
return | ||
} | ||
|
||
if m.Battery <= 0 { | ||
fmt.Println("The mobile device is out of battery. Please charge it.") | ||
return | ||
} | ||
|
||
m.LastUsage = time.Now() | ||
fmt.Printf("Using %s %s for %d minutes.\n", m.Brand, m.Model, minutes) | ||
|
||
// Simulate battery drain | ||
m.Battery -= minutes | ||
if m.Battery < 0 { | ||
m.Battery = 0 | ||
} | ||
|
||
// Check battery level | ||
if m.Battery == 0 { | ||
m.TurnOff() | ||
fmt.Println("The mobile device is out of battery. Please charge it.") | ||
} | ||
} | ||
harjotgill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// ChargeMobile charges the mobile device. | ||
func (m *Mobile) ChargeMobile(minutes int) { | ||
m.LastUsage = time.Now() | ||
m.Battery += minutes | ||
if m.Battery > 100 { | ||
m.Battery = 100 | ||
} | ||
fmt.Printf("Charging %s %s for %d minutes.\n", m.Brand, m.Model, minutes) | ||
} | ||
harjotgill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
func main() { | ||
// Create a new mobile device | ||
myMobile := Mobile{ | ||
Brand: "Apple", | ||
Model: "iPhone X", | ||
IsOn: false, | ||
Battery: 50, | ||
} | ||
|
||
// Turn on the mobile device | ||
myMobile.TurnOn() | ||
|
||
// Simulate using the mobile device | ||
myMobile.UseMobile(60) | ||
|
||
// Charge the mobile device | ||
myMobile.ChargeMobile(30) | ||
|
||
// Simulate using the mobile device again | ||
myMobile.UseMobile(120) | ||
|
||
// Turn off the mobile device | ||
myMobile.TurnOff() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.