Question
public class BankAccount { private double balance; */ public BankAccount() { balance = 0; } public BankAccount(double initialBalance) { balance = initialBalance; } public void
public class BankAccount | |
{ | |
private double balance; | |
*/ | |
public BankAccount() | |
{ | |
balance = 0; | |
} | |
public BankAccount(double initialBalance) | |
{ | |
balance = initialBalance; | |
} | |
public void deposit(double amount) | |
{ | |
balance = balance + amount; | |
} | |
public void withdraw(double amount) | |
{ | |
balance = balance - amount; | |
} | |
/** | |
*/ | |
public double getbalance() | |
{ | |
return balance; | |
I would like to see this completed to cross refernece my own aswers. Thanks. |
Calculating a tip when you go to a restaurant based on service if something we all do. However, current tip recommendations are not based on degree of satisfaction. This program should create such a tip calculator.
Create a Tip class.
Create an instance variable called satisfactionRating. This variable should be an int.
Create a constructor. The constructor sets (initializes) satisfactionRating variable to the value in the parameter.
Create a variable which is a double and called tip. If the satisfactionRating is 1, multiple the bill by 20% and assign it to the variable named tip. If the satisfactionRating is 2, multiple the bill by 15% and assign it to the variable named tip. If the satisfactionRating is 3, multiple the bill by 10% and assign it to the variable named tip. Add the tip to the bill and return the calculated value. The method should return a double which represents the numeric calculation of the tip + the cost.
In the tester class:
Create a main.
Create a Scanner object. (Dont forget you have to import it.)
Prompt the user to input the cost of the meal.
Create a double variable named mealCost and assign the user input to it.
Prompt the user to input a satisfaction rating of 1 for totally satisfied, 2 for satisfied, and 3 for dissatisfied.
Create an int named satisfaction and assign the user input to it.
Create a Tip object using satisfaction.
Call the method calculateBill and use mealCost your parameter input. Assign the returned value to a variable named totalCost. It should be a double.
Create a string variable named satisfactionLevel. You should convert the int satisfaction from the numerical value to the appropriate word representation. For example, if(satisfaction == 1) { satisfactionLevel = Totally Satisfied;}
Print the satisfactionLevel so that it reads Satisfaction is: XXXX.
Print the cost of the meal. This was input in step d. It should read The cost of the meal was: XXX.
Print the totalCost of the meal. It should read The total cost of the meal was: xxx.
In this problem, we are going to compare some values. We will examine the difference between comparing integers, doubles, and words.
Create a class named Comparison.
Do no create instance variables.
Do not create a constructor.
Write a method called compFloat2 which accepts as input two doubles as an argument (parameter). Write the appropriate code to test the two numbers up to two decimal points to see if they are close enough. If they are close enough return true else return false. This would be a Boolean value.
Write a method called compFloat5 which accepts as input two doubles as an argument (parameter). Write the appropriate code to test the two numbers up to five decimal points to see if they are close enough. If they are close enough return true else return false. This would be a Boolean value.
Write a method called compInt which accepts as input two integers as an argument (parameter). Write the appropriate code to test the two integers to see if they are equal. If they are equal return true else return false. This would be a Boolean value.
Write a method called stringEqual program that reads in two sentences as an argument (parameter). Write the appropriate code to test the two strings to see if they are the equal. If they are equal return true else return false. This would be a Boolean value.
Write a method called stringCompare program that reads in two sentences as an argument (parameter). Write the appropriate code to test the two strings to see if string 1 is greater than string 2. If they are return true else return false. This would be a Boolean value.
Now for the tester class:
Create a ComparisonTester class.
Import Scanner
Create a Scanner object.
Prompt the user to enter two doubles. You will need two variables to receive the input.
Create a Comparison object.
Create a Boolean variable named areTheyEqual. Boolean areTheyEqual;
Call compFloat2 and assign it to areTheyEqual.
Print The two doubles are equal up to two decimal points: areTheyEqual
Call compFloat5 and assign it to areTheyEqual.
Print The two doubles are equal up to five decimal points: areTheyEqual
Prompt the user to enter two integers. You will need two variables to receive the input.
Call compInt and assign the result to areTheyEqual.
Print using the same type of format as above.
Prompt the user to enter two Strings. You will need two variables to receive the input. These should be allowed to have spaces and therefore you need to use nextLine(). If you use that you will have an issue so do it this way. S1= in.nextLine(); in.nextLine(); s2 = in.nextLine().
Call stringEqual and assign the result to areTheyEqual.
Print using the same type of format as above.
Call stringCompare and assign the result to areTheyEqual.
Print using the same type of format as above.
Computing Taxes program. This is the problem 5.2 on page 228 of your text.
Create a class named TaxCalculator
Do not create instance variables or a constructor.
Create a method named calculateTax and it should return a double. It should have two arguments. One argument will be String named maritalStatus. The other argument should be a double named taxableIncome.
You will need nested if statements. The outside test should be whether maritalStatus is equal to married. Remember this is a String and you should use String comparison. An example of the if else statement is on page 200. An example of the String comparison is on page 186 and you need to use the .equals. Inside the comparison you need another set of if statements for the levels of taxableIncome. You will need to use a compound if statement to compare the various income levels. See top of page 212. Return the income tax due as a double.
Create a TaxCalculatorTester
Import Scanner
Create a Scanner object
Prompt the user for their marital status and assign it to a String.
Prompt the user for their income and assign it to a double.
Create an object of type TaxCalculator;
Create a taxDue double variable
Call the calculateTax method and assign the output to taxDue.
Print the martial status with appropriate words Marital Status is: XXX
Print the income with appropriate words.
Print the totalIncome with appropriate words.
In this problem, you are going to enhance the BankAccount class of Chapter 3, page 94 and 95. You should already have this coded. We are going to enhance it by making the deposit and withdraw methods more realistic. You could not withdraw any amount of money if your balance was less than or equal to 0. You also could not deposit a negative amount.
Create a new class named EnhancedBankAccount.
If you have it copy BankAccount to EnhancedBankAcount. If you no longer have the BankAccount class, copy the BankAccount class form page 94 and 95.
In the deposit method, check to see if the deposit is negative. If it is, then print You cannot make a negative deposit and do not make the deposit. If it is not, make the deposit.
In the withdraw method, check to see if the balance the amount to withdraw is less than 0. If it is then print You do not have enough money to make the withdrawal. If it is not, make the withdrawal.
Create a EnhancedBankAccountTester by either copying the prior one or entering the code from the text on page 101. Make sure the reference to BankAccount is changed to EnhancedBankAccount.
Enter the code as it appears on page 101.
Make a negative deposit.
Print the balance of harryChecking account.
Make a withdrawal greater than the balance.
Print the balance of harryChecking account.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started