Calculate and display the total payment amount

Assignment Help Other Subject
Reference no: EM132540464

Question 1- Translating Text Messages

Instant messaging (IM) and texting on portable devices has resulted in a set of common abbreviations useful for brief messages. However, some individuals may not understand these abbreviations.

Write a program that reads a one-line text message containing common ab- breviations and translates the message into English using a set of translations stored in a file. For example, if the user enters the text message

y r u 18

the program should print

why are you late

As a simplification, you can assume that are no punctuation marks. Proceed as follows:

a. Build a dictionary with abbreviations as keys and associated texts as values.

Read the provided text file abbreviations.txt, each line of which contains an abbreviation and the associated text it.

The following code segment reads the file and store each line of the text file as a string in the list lines:

filename = "abbreviations.txt" infile = open(filename, "r") lines = file.readlines()

(You should display the list lines to see what a string of this list looks like.)
Complete the code to build a dictionary with abbreviations as keys and the associated texts as value.

b. Translate a message.
Split the message into "words". If a "word" is in the dictionary, replace it by the associated text. Otherwise simply copy the "word" to the translation.

Question 2- Merge Big Files

Suppose we have two very big text files, so big that we cannot read them into the computer's memory. The files are already sorted.
Now, we want to merge them. How can we do this?
We can use the following approach. Imagine that the names are on two piles of cards.

• We look at the cards on top of the two piles.
• We then pick out the smaller one to add to the merged pile. If the two top cards have the same name, we add one card to the merged pile and discard the other one.
• We repeat this until one pile is exhausted. We simply add all the cards of the other pile, if any, to the merged pile.

Write a program to implement the above approach. For demonstration pur- pose, you can take names set1.txt and names set2.txt as the two input files. Call the output file names merged big.txt.

Note: The merge problem we consider here is part of the algorithm known as external merge sort, which is used to sort very big files, without reading the whole files into computer memory.

Question 3 - The 72 Rule

The program below gets the annual interest rate from the user. It then calcu- lates and displays the estimate of number of years it takes to double the initial investment amount.

# Get annual interest rate

rate = float(input("Enter annual interest rate (5 for 5 ):"))

# Calculate and display number of of years it takes to double # the investment account

years = 72 / rate

print("at the rate of" , rate, " , it takes", years, "to double the initial investment")

The above program does not regard a negative interest rate as an error. From the business application viewpoint, a negative interest rate should be regarded as an error.
Modify the program to take this issue into account.
Handle any exception that may be raised. You can do this in any way you like. But the output should distinguish (i) the case in which is the input is not a number from (ii) the case in which the input is not a positive number.

Question 4 - The Student Class

a. Define a class named Student that holds the following data about a student in attributes id, name, and marks.

Attribute marks is a list that holds the marks of three assessment compo- nents, assignment 1, assignment 2 and the exam, with the weights of 30%, 30% and 40%, respectively.
Include the following:

• A constructor to initialize the student's id, name and marks.
• A method to display the student's details for inspection purpose,
• A method to change a particular mark (the mark to be changed is specified by its index in the list),
• A method to calculate the final mark.

b. Write statements to
• Create a student
• Display all of the student's details
• Display the student's id, name and marks on three separate lines (one line for id, one line for name and one line for the list of marks).
• Change the mark of one assessment component, and display the stu- dent's marks after the change.
• Get and display the final mark.
In your testing, observe the following usage-conforming rules:

• The student id is a non-empty string
• The student name is a non-empty string
• marks is a list of three float values between 0 and 100, inclusive State your assumptions, if any.

Question 5 - Classes Payment and Subclasses

a. Define class Payment that has an attribute amount (intended to be of type
float) that stores a payment amount.
In addition to init and repr , include method printDetails to print on the screen the payment details as shown in the example below:

PAYMENT
Amount: 400

b. Define class CashPayment as a subclass of Payment.
This class redefines printDetails to display the payment details as shown in the example below:

PAYMENT
Amount: 400 By cash

c. Define class CreditCardPayment as a subclass of Payment. This class has attribute creditCardNr for the credit card number.
This class redefines printDetails to display the payment details as shown in the example below:

PAYMENT
Amount: 400
By credit card: 12345678

d. A list of payments is created as shown below:

p1 = CashPayment(100)
p2 = CreditCardPayment(200, "AB123") p3 = CashPayment(200)
p4 = CreditCardPayment(100, "CD456") payments = [p1, p2, p3, p4]

Write statements to calculate and display the total payment amount of all the payments by credit cards.

Question 6 - Reading Bus Route Data

In this question and next two questions, you will work with a text file that contains information about the bus route that goes from the Bundoora campus of La Trobe University to the City of Melbourne.
The data (which is route 250) is stored in the text file BusRoute250.txt. It lists all the bus stops on the route, 67 of them actually. Details about a stop is stored on one line. The first 5 lines and the last 5 lines are shown below:

1/La Trobe Uni Terminus/Science Dr/Bundoora
2/La Trobe Uni Thomas Cherry Building/Science Dr/Bundoora 3/Kingsbury Dr/Waterdale Rd/Bundoora
4/Crissane Rd/Waterdale Rd/Heidelberg West 5/Percy St/Waterdale Rd/Heidelberg West
...
63/Exhibition St/Lonsdale St/Melbourne City 64/Melbourne Central/Lonsdale St/Melbourne City 65/Elizabeth St/Lonsdale St/Melbourne City 66/Little Bourke St/Queen St/Melbourne City 67/Little Collins St/Queen St/Melbourne City

Each line has four fields, separated by slash characters:

• The first is the stop number (an integer), counting from the La Trobe Uni- versity end.
• The second is the stop's name. You may be interested in how bus stops are named. In general, the name of a bus stop can be
- Either the name of a nearby street that cuts across the route (which will be referred to as the "cross-street"), e.g. Kingsbury Dr
- Or the name of a place of interest near the stop (which will be referred to as the "cross-site"), e.g. La Trobe Uni Thomas Cherry Building
• The third is the street along the route on which the stop lies, e.g. Science Dr for stop number 1.
• The fourth field is the name of the suburb of the stop. It is enclosed between a pair of brackets, e.g. Bundoora.

Write a program to read the file and display the details about the bus stops. The details of a bus stop is displayed on four lines, showing the bus stop number, the name, the street and the suburb. For example:

1
La Trobe Uni Terminus Science Dr
Bundoora
...

Question 7 - Defining the BusStop Class

Define the BusStop class that has the following attributes

• number, which is intended to be a positive integer
• name: the name of the bus stop, a non-empty string (note that, as you can tell from the file, they are also unique)
• street: the name of the street along the route
• suburb: the name of the suburb

Question 8 - Loading and Querying about the Bus Route

In this question, you write a number of functions to load the data into a list of bus stops (i.e. BusStop instances) and make various queries about the bus stops on the route.
Complete the program shown below:

from A2Q7 import BusStop busStopList = []
def loadData(): pass

def listAllBusStopNames(): pass

def listAllStreetsOnRoute(): pass

def listAllSuburbsOnRoute(): pass

def searchByNumber(start: "int, value: a stop number", end: "int, value: a stop number >= start"):
pass

def searchByName(nameKey): pass

def searchByStreet(streetKey): pass

def searchBySuburb(suburbKey): pass

def searchByAnyField(key): pass

#== Tests ==
# Add tests to test each of the functions

Attachment:- Translating Text Messages.rar

Reference no: EM132540464

Questions Cloud

Discussing three limitations of using ratio analysis : Looking at the information that is used in ratio analysis, Discussing three limitations of using ratio analysis as your major analysis method.
Encountered definitions and theories related to leadership : Throughout the course, you have encountered definitions and theories related to leadership.
What are responsibility of production manager and purchasing : What are the responsibility of Production Manager and Purchasing Manager in relation to the calculation of Material Variances.?
Calculate the net present value of the new product line : Bravo Pty Ltd, If Bravo's hurdle rate is 14 per cent, calculate the net present value of the new product line. (Income taxes can be ignored.)
Calculate and display the total payment amount : Write a program that reads a one-line text message containing common ab- breviations and translates the message into English using a set of translations
Exchange rates of the australian dollar : Assume that Australia trades mostly with two countries only, the United States and the United Kingdom, and that 65% of the trade is conducted
Determine the mark-up percentage used by the company : Company uses cost-plus pricing based on variable manufacturing costs, determine the mark-up percentage used by the company to obtain a price of $105.
How much cash should thomas expect to collect : Sales at Thomas are normally collected as 70% in the month of sale,How much cash should Thomas expect to collect during the month of April?
Evaluate online crowdsourcing site : Evaluate an online crowdsourcing site. Examples include, Dell's Ideastorm, and Starbucks.

Reviews

Write a Review

Other Subject Questions & Answers

  Discuss the given argument as per the given requirement

Symbolize each argument, providing a key. State whether the argument is valid or invalid, and state whether you think it is a persuasive/strong argument.

  Explain the purpose of the kmo and bartlett test

The relationship between project duration, project quality and project cost with the proposed contractor’s key performance indicators for housing construction.

  Intersection of faith and god power

Describe a time when you witnessed the intersection of faith and God's power. This can be a personal situation or one you heard or read about.

  Why are these factors so important to businesses

Explain what the following terms mean to you as they apply to information security and safe computing: Confidentiality, Integrity, and Availability.

  What precedents did he set with the decisions he made

Of the president you selected, what precedents did he set with the decisions he made that are i hat do you think - was the decision a good one, or did it have unfortunate unforseen consequences?

  How you would apply moneyballs management lessons

Examine why sabermetric-based player evaluation is such a shock to other executives in baseball. Explain how you would apply Moneyball's management lessons in your own endeavors.

  What steps are necessary to complete the research

Political Theorist and founder of the Global Parliament of Mayors, Benjamin Barber argues that globalization is "pressing nations into one homogeneous global.

  What risks are most commonly overlooked or not managed well

What risks are most commonly overlooked or not managed well within Oil and Gas organizations during IT projects?

  How has the registry improved and educated the community

How has the registry improved and/or educated the community on the disease? Is the registry effective? Why or why not?

  What lifestyle factors would you expect

What lifestyle factors (including diet) would you expect to have negative or positive effects on the efficacy of phytochemicals in health and disease? Give specific examples and provide possible mechanistic explanations.

  Operate in internal and external environments

Organizations are said to operate in internal and external environments that affect the way managers’ plan, organize, lead and coordinate their activities.

  Explain the importance of neuroscience in education

Explain The Importance of Neuroscience in Education. Describe how you might specifically incorporate them into your classroom instruction.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd