In: Computer Science
I have the problem in bold below. I am completely confused. I am hoping that I will see how you did this and will be able to follow it. Please remember that I have just started this so please don't use any complex features that an absolute beginner (like me) wouldn't know.
Additional information:
/*This is what everyone owes before tax and tip:
Person 1: $10
Person 2: $12
Person 3: $9
Person 4: $8
Person 5: $7
Person 6: $15
Person 7: $11
Person 8: $30
*/
package Tip02;
public class Calculator {
public double tax = .05;
public double tip = .15; //Change tax and tip if you prefer different values
public double originalPrice = 0;
public void findTotal(){
//Calculate an individual's total after tax and tip
//Print this value
}
}
Please give me a solution and (explanation if possible).
Package Tip02;
public class CalculatorTest {
public static void main(String[] args) {
//Instantiate a Calculator object
Calculator calc = new Calculator ();
//Access the Calculator object's fields and methods
//to find the total for each member of the birthday party
/*This is what everyone owes before tax and tip:
Person 1: $10
Person 2: $12
Person 3: $9
Person 4: $8
Person 5: $7
Person 6: $15 (Alex)
Person 7: $11
Person 8: $30
*/
}
}
input code:
package:
Main file:
output:
code:
package:
package Tip02;
class Calculator {
/*declare the variables*/
public double tax = .05;
public double tip = .15; //Change tax and tip if you prefer
different values
public double originalPrice = 0;
/*find Total method*/
public void findTotal()
{
/*find and print Total*/
System.out.println(" Total =
"+String.format("%.2f",(originalPrice+originalPrice*tax+originalPrice*tip)));
}
}
main file:
import Tip02;
public class CalculatorTest {
public static void main(String[] args) {
/*make Calculator object*/
Calculator calc = new Calculator ();
/*for Person 1 Calculate total bill*/
System.out.print("Person 1");
/*set value of originalPrice*/
calc.originalPrice=10;
/*call findTotal method*/
calc.findTotal();
/*for Person 2 Calculate total bill*/
System.out.print("Person 2");
/*set value of originalPrice*/
calc.originalPrice=12;
/*call findTotal method*/
calc.findTotal();
/*for Person 3 Calculate total bill*/
System.out.print("Person 3");
/*set value of originalPrice*/
calc.originalPrice=9;
/*call findTotal method*/
calc.findTotal();
/*for Person 4 Calculate total bill*/
System.out.print("Person 4");
/*set value of originalPrice*/
calc.originalPrice=8;
/*call findTotal method*/
calc.findTotal();
/*for Person 5 Calculate total bill*/
System.out.print("Person 5");
/*set value of originalPrice*/
calc.originalPrice=7;
/*call findTotal method*/
calc.findTotal();
/*for Person 6 Calculate total bill*/
System.out.print("Person 6");
/*set value of originalPrice*/
calc.originalPrice=15;
/*call findTotal method*/
calc.findTotal();
/*for Person 7 Calculate total bill*/
System.out.print("Person 7");
/*set value of originalPrice*/
calc.originalPrice=11;
/*call findTotal method*/
calc.findTotal();
/*for Person 8 Calculate total bill*/
System.out.print("Person 8");
/*set value of originalPrice*/
calc.originalPrice=30;
/*call findTotal method*/
calc.findTotal();
}
}