Click here to Skip to main content
15,889,723 members
Home / Discussions / Java
   

Java

 
GeneralRe: Doubt regarding Java coding Pin
Richard MacCutchan10-Mar-16 21:24
mveRichard MacCutchan10-Mar-16 21:24 
Questioncoffee shop management system in java Pin
Hussain Anwer6-Mar-16 2:52
Hussain Anwer6-Mar-16 2:52 
AnswerRe: coffee shop management system in java Pin
Richard MacCutchan6-Mar-16 4:20
mveRichard MacCutchan6-Mar-16 4:20 
QuestionCustom Browser Pin
sandeep kamara26-Feb-16 18:06
sandeep kamara26-Feb-16 18:06 
AnswerRe: Custom Browser Pin
Richard MacCutchan26-Feb-16 21:57
mveRichard MacCutchan26-Feb-16 21:57 
Questioncore java (Singleton pattern ) Pin
Hiren Akbari25-Feb-16 6:45
professionalHiren Akbari25-Feb-16 6:45 
AnswerRe: core java (Singleton pattern ) Pin
NickPace25-Feb-16 7:00
NickPace25-Feb-16 7:00 
QuestionHow to use setters and getters. Pin
Member 1234728623-Feb-16 14:49
Member 1234728623-Feb-16 14:49 
Hey guys. I'm having so much trouble understanding setters and getters. I've read the setter/getter chapter for our testbook multiple times and have looked up many things online but can't get it to work. It doesn't help that there are very few completed examples in my book so its hard to actually see how anything is applied in a finished state. This is one of our programs we have to do for class. We were supposed to use setters and getters, but I couldn't figure it out, so desperately created the program below to at least get the end result, albeit not with the method required.

Utilizing my program below, can someone explain the basics of setters and getters and how I would apply them? Not asking for someone to do my work for me, just thought it'd give a good example for me to understand.

My program basically shows a menu, a user enters how many of each product they want through keyboard input, and then the program calculates the subtotal before tax, the tax amount, and then the grand total (subtotal + tax). Pretty simple.

C#
public class CateringOrderApp {

	public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in);
		
		//Declares tax rate constant.
		double SALES_TAX_RATE = .0875;
		//Declares calculation variables.
		double subtotalCost;
		double taxAmount;
		double totalCost;
		//Sets constant prices for items.
		double VEGGIE_SANDWICH_PRICE = 2.75;
		double HAM_AND_CHEESE_SANDWICH_PRICE = 3.25;
		double SPAGHETTI_PRICE = 35.00;
		double SALAD_PRICE = 18.00;
		//Declares order count for items
		double veggieSandwichCount = 0;
		double hamAndCheeseSandwichCount = 0;
		double spaghettiCount = 0;
		double saladCount = 0;
		
		//Displays menu
		System.out.println("Food Item                                          Price");
		System.out.println("--------------------------------------------------------");
		System.out.println("Veggie Sandwich                                    $2.75");
		System.out.println("Ham and Cheese Sandwich                            $3.25");
		System.out.println("Spaghetti (tray serves 20)                        $35.00");
		System.out.println("Salad (tray serves 20                             $18.00");
		System.out.println("--------------------------------------------------------");
		
		//Begins to ask customer about the number of orders for each specific item.
		System.out.println("Please enter the amount of Veggie sandwiches that you want: ");
		veggieSandwichCount = keyboard.nextDouble();
		System.out.println("Please enter the amount of Ham and Cheese sandwiches that you want: ");
		hamAndCheeseSandwichCount = keyboard.nextDouble();
		System.out.println("Please enter the orders of Spaghetti that you want: ");
		spaghettiCount = keyboard.nextDouble();
		System.out.println("Please enter the orders of salad that you want: ");
		saladCount = keyboard.nextDouble();
		
		//Calculations for
		//totals, including tax amount.
		subtotalCost = (veggieSandwichCount*VEGGIE_SANDWICH_PRICE)+
				(hamAndCheeseSandwichCount*HAM_AND_CHEESE_SANDWICH_PRICE)+
				(spaghettiCount*SPAGHETTI_PRICE)+
				(saladCount*SALAD_PRICE);
		taxAmount = (subtotalCost*SALES_TAX_RATE);
		totalCost = (subtotalCost + taxAmount);
		
		//Displays all of this information after having been calculated.
		System.out.println("Food Item                                 Number Ordered");
		System.out.println("--------------------------------------------------------");
		System.out.println("Veggie Sandwich                            " + veggieSandwichCount);
		System.out.println("Ham and Cheese Sandwich                    " + hamAndCheeseSandwichCount);
		System.out.println("Spaghetti (tray serves 20)                 " + spaghettiCount);
		System.out.println("Salad (tray serves 20                      "  + saladCount);
		System.out.println("--------------------------------------------------------");
		//Prints total cost information
		System.out.println("Sutotal: " + subtotalCost);
		System.out.println("Tax Amount: " + taxAmount);
		System.out.println("Total: " + totalCost);
		
	}

}

AnswerRe: How to use setters and getters. Pin
Richard MacCutchan23-Feb-16 21:26
mveRichard MacCutchan23-Feb-16 21:26 
GeneralMessage Closed Pin
25-Mar-20 19:16
Sherin_Mathew25-Mar-20 19:16 
GeneralRe: How to use setters and getters. Pin
Richard MacCutchan25-Mar-20 21:29
mveRichard MacCutchan25-Mar-20 21:29 
GeneralRe: How to use setters and getters. Pin
OriginalGriff16-Apr-20 0:06
mveOriginalGriff16-Apr-20 0:06 
GeneralRe: How to use setters and getters. Pin
Richard MacCutchan16-Apr-20 0:43
mveRichard MacCutchan16-Apr-20 0:43 
QuestionHow to fetch the data from pos to my application Pin
Vandip11-Feb-16 12:22
Vandip11-Feb-16 12:22 
AnswerRe: How to fetch the data from pos to my application Pin
Richard MacCutchan11-Feb-16 21:10
mveRichard MacCutchan11-Feb-16 21:10 
QuestionDouble variable and array working in java Pin
Indan10-Feb-16 7:18
Indan10-Feb-16 7:18 
AnswerRe: Double variable and array working in java Pin
jschell12-Feb-16 12:35
jschell12-Feb-16 12:35 
Questionhow to use selenium webdriver with existing firefox browser Pin
neodeaths3-Feb-16 5:38
neodeaths3-Feb-16 5:38 
Questionusing "while" reverse the digits of the number in java? Pin
Member 123033992-Feb-16 8:05
Member 123033992-Feb-16 8:05 
AnswerRe: using "while" reverse the digits of the number in java? Pin
Richard Andrew x642-Feb-16 8:15
professionalRichard Andrew x642-Feb-16 8:15 
GeneralREPOST Pin
Sascha Lefèvre2-Feb-16 8:28
professionalSascha Lefèvre2-Feb-16 8:28 
Questionget the context path in jsp Pin
Member 1026351929-Jan-16 21:27
Member 1026351929-Jan-16 21:27 
Generaljava Pin
Hiren Akbari27-Jan-16 5:49
professionalHiren Akbari27-Jan-16 5:49 
QuestionRe: java Pin
Richard MacCutchan27-Jan-16 6:28
mveRichard MacCutchan27-Jan-16 6:28 
GeneralRe: java Pin
iskSYS24-Feb-16 22:09
professionaliskSYS24-Feb-16 22:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.