struggling with this simple java object oriented program [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
well simple to many of you i'm sure...
basically we have to create a program to process tickets for a fair. A person can buy more than 1 ticket but they need a print-out at the end for each person attending..
ex. thanks!
child: 1
adult: 1
total: $16
Our program should make just 1 object (use of arrays is not allowed) and when the object is created we will display the name of the county fair.
Kids under 12 pay $5.
Adults pay $9.
a fee of $2 is added to the sale.
i'm just confused at how to set this up because apparently we need a data definition class and a use of a constructor but I only am familiar with doing this only in the Main...
thanks for any help!

Make a Ticket class. It should take a variable age..
Use if statements to assign adult/child and make constant price for each.
As for the print out just after each order, ask if there are anymore tickets to be bought. If no, print out totals.
This is probably a homework assignment, I actually did this last year for APCS. Please just read your book and study the information. This forum is not to do your homework, its to help individuals develop an understanding of programming. Good luck.

Related

Java naming conventions versus English language correctness [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm not sure is this right place to ask so correct me if I'm wrong.
The case is that:
one category has one code
we want to get list of codes for multiple categories
Which version is correct and why?
getCategoriesCodes()
or
getCategoryCodes()
I see this problem from two points of view, one is the English grammar, and the second one is the clean code and code meaningful naming.
Please give me your opinion which method name is better and add note is English you native language.
As both a native English speaker and a Java programmer: getCategoryCodes() is preferable. getCategoriesCodes() implies to me that I am getting multiple codes for each category, or that the codes relate to the collection of categories, rather than a code for each category.
As an example from "real" English: a car has one driver; you would refer to the drivers of many cars as "car drivers", not "cars drivers".
I would side with the clean code and meaningful naming. Nobody will judge your English in your code and also looking at the code in a month or a year will make it easier to understand if its worded correctly
There is no harm in giving names grammatical correct provided it is readable and understandable and not become very long because long names are difficult to understand.

java programming homework 2015 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i am having some issues with this question for my homework and was wondering if anyone has any ideas or insights to the answer really struggling ,,,,
You are to amend the program you created last week, this time however the program will ask you to
type the names that need to be stored. Once this is complete the program will display the names in
alphabetical order and display the number of characters for each name and the number of vowels
each name has.
Since this is homework, I'll give you a hint. If you've studied the Java Collections, you can stored the names in alphabetical order. If you've not got to collections yet, the you simply save them off as Strings as they come in.
When it's time to display them in alphabetical order you could:
- sort them before you display them
- or brute force it. Loop thru your storage of names and display all the A's. Then loop thru picking up the B's.
As for counting vowels, look at the Java documentation for the methods that are on the String class. Hint - look for methods that return an "int".

Java - Object - Field and Method example - Basics [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am learning the very basics of Java and I decided to expand on an example a little further in order to understand it better.
In this instance, the object in question is a car. Let's say 'example car 1'.
The focus for my analogy is the engine temperature.
Firstly, I would view this as a field (state).
I also have a warning light for the engine temperature. Again, I would view this as a field.
Thinking about how they would interact I see it like this.
Engine temperature > 90°c ----> Warning Light -----> ON
To me, the method would be the switching on of the warning light.
Assuming I have been correct with the analogy so far, would there also be a method that would be the reference from the engine temp to the warning light?
so: If engine temp = > 90°c then refer to warning light <---- Is this a method of the engine temp?
Many thanks in advance!
Usually you would represent engine "temperature" as a field (as you said) and provide a getEngineTemperature and setEngineTemperature method. You can provide another method such as hasEngineTemperatureWarning to represent whether the temperature is in the dangerous range. Ultimately, however, these distinctions are up to you, the programmer, and there is no "always right" approach. But I think this is a good starting point.

Java newbie. Using the Math class [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am writing a piece of code that allows users to enter test scores. I then need to use the Math.max and Math.min to keep track of max and min and display the answer. I am not sure where I type that code or how I type that code.
Please let me know what pieces of the code would be helpful to post!
Thanks in advance!
Start by breaking down the problem into steps and figure out what you need to know. In your case you need to know four things:
How to get input from the console
How to compare values
How to conditionally change values
How to display things to the console
One and four you can search up pretty easy. Look into "Hello world" and other such starter programs for Java. Two and three you should look up "if" statements for Java. Hope this sets you on the right track.

Creating a ship log... What method to use? JAVA [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm working on my first big project and one thing I need to do is create a log of all the ships in a game and all their stats, their name, class etc... There must be at least over 100 ships. I thought about using a Hashmap, but I would need more than one value per key. I thought about doing a bunch of string arrays, but I think that would take too much memory. Should I read the values in from a .txt file? Any suggestions would be greatly appreciated, and thank you for your time. :D
What is the unique identifier for a ship? You can simply create a hashmap using that unique identifier as the key and the ship instance as the value. In addition, there is nothing preventing you from using a MultiMap to store a collection of values at each key if that makes semantic sense. But this question is rather poorly defined with respect to what you actually want this 'log' to do.

Categories

Resources