public class Section4Method { /** * @param args the command line arguments */ public static void main(String[] args) { //instantiate Calculator calc = new Calculator(); calc.originalPrice = 10.00; System.out.print("person1:$"); calc.findTotal(); calc.originalPrice = 12.00; System.out.print("person2:$"); calc.findTotal(); calc.originalPrice = 9.00; System.out.print("person3:$"); calc.findTotal(); calc.originalPrice = 8.00; System.out.print("person4:$"); calc.findTotal(); calc.originalPrice = 7.00; System.out.print("person5:$"); calc.findTotal(); calc.originalPrice = 15.00; System.out.print("person6:$"); calc.findTotal(); calc.originalPrice = 11.00; System.out.print("person7:$"); calc.findTotal(); calc.originalPrice = 30.00; System.out.print("person8:$"); calc.findTotal(); } } ////PUBLIC CLASS CALCULATOR public class Calculator { //public to be access main public double tax = .05; public double tip = .15; public double originalPrice = 0.0; public void findTotal(){//2 paremeters of price and string name double total = originalPrice * (1 + tax + tip); System.out.println(total); } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter