Question
Hi there, I need help with the 2 Questions for java where I need to use private intsance variables. Please provide commenting Question 1 Design
Hi there,
I need help with the 2 Questions for java where I need to use private intsance variables. Please provide commenting
Question 1
Design Lunch Order application that include private intance variables, that prompts the user for the number of hamburgers, salads, french fries, and sodas and then displays the total for the order. The Lunch Order application should include a Food object with a constructor that accepts the price, fat, carbs, and fibre for an item. Food methods should return the price of the item and return the fat, carbohydrates, and fibre. Use the chart below for
food prices and nutrition information:
Item Price Fat(g) Carbohydrates(g) Fibre(g)
hamburger $1.85 9 33 1
salad $2.00 1 11 5
french fries $1.30 11 36 4
soda $0.95 0 38 0
Your output should look similar to:
Enter number of hamburgers: 2
Each hamburger has 9 g of fat, 33 g of carbs, and 1 g of fibre.
Enter number of salads: 5
Each salad has 1 g of fat, 11 g of carbs, and 5 g of fibre.
Enter number of fries: 4
French fries have 11 g of fat, 36 g of carbs, and 4 g of fibre.
Enter number of sodas: 3
Each soda has 0 g of fat, 38 g of carbs, and 0 g of fibre.
Your order comes to: $21.75
Question 2
GIVEN THE CODE BELOW
Given the following class:
/**
* Document class.
*/
public class Document {
private int words;
/**
* constructor
* pre: none
* post: A Document object created. Words initialized to 0.
*/
public Document() {
words = 0;//default words
}
/**
* Changes the number of document words.
* pre: none
* post: Words has been changed.
*/
public void setWords(int numWords) {
words = numWords;
}
/**
* Calculates the number of pages.
* pre: none
* post: The number of pages has been returned.
*/
public int calculatePages() {
final int WORDS_PER_PAGE = 300;
int pages;
pages = words / WORDS_PER_PAGE;
if (words % WORDS_PER_PAGE > 0) {
pages += 1;
}
return(pages);
}
/**
* Returns the number of words in a document.
* pre: none
* post: The number of document words has been returned.
*/
public int getWords() {
return(words);
}
}
Design an Essay class that inherits the Document class. The Essay class should include private intance variables, member constants MIN_WORDS and MAX_WORDS.
An essay should be between 1500 and 3000. The Essay class should also contain
a member method validLength(), which returns true when the Essay object contains between MIN_WORDS and MAX_WORDS and false otherwise.
**Design an EssayAssignment application that tests the Essay class.EssayAssignment will contain the main() method.
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