Java: Questions About Music & App Store Program

  • Java
  • Thread starter MarcL
  • Start date
  • Tags
    Java
In summary, the program asks the user for the amount of money they wish to prepay, and displays two messages indicating:- the maximum number of apps that can be downloaded, and how much funds will remainin the account after that, if any.- the maximum number of songs that can be downloaded, the number of apps that can bedownloaded after that if funds allow, and how much funds will remain in the accountafter that, if any.
  • #1
MarcL
170
2
Hey so I have to write a program that does the following for my class ( Object oriented programing 1, so basic stuff really...)

An online music and apps store offers all apps for 3$ each and all songs for 7$ each. The store
requires members to prepay any amount of money they wish, and then download as many apps
or as many songs accordingly. You are required to write a program that would ask the user for
the amount that he/she will pay, then display two messages indicating:
- the maximum number of apps that can be downloaded, and how much funds will remain
in the account after that, if any.
- the maximum number of songs that can be downloaded, the number of apps that can be
downloaded after that if funds allow, and how much funds will remain in the account
after that, if any.
 Notice the parenthesis in app(s) and song(s) in the output.

And I wrote this, but I have a few question about what I wrote ...

"
public class MusicStore
{ double prePay;
prePay = x;
int. songs, apps;
Final int. Songs=3$ , apps=7$
public static void main (String arg[])
{ system.out.println("How much money do you wish to prepay?")"

Keep in mind I am not done. My first (1) question was whether or not I have to define my variables and constants before or after my main method? ( and why if anyone can explain) . Secondly, I don't know how to ask / allow the user to input a number after a question. Finally, for my system output, would I be better using "How much money do you wish to prepay?" or use the define variable.

Really sorry if this is a mess, it's my first time doing this alone!
 
Technology news on Phys.org
  • #2
The variables and contants can be defined anywhere. They don't have to be defined before the method that uses them. It's mainly a convention for readability.

If you are going to ask questions about your code, please use the <code> block (under the +) so that it's more readable.
 
  • #3
MarcL said:
Hey so I have to write a program that does the following for my class ( Object oriented programing 1, so basic stuff really...)

An online music and apps store offers all apps for 3$ each and all songs for 7$ each. The store
requires members to prepay any amount of money they wish, and then download as many apps
or as many songs accordingly. You are required to write a program that would ask the user for
the amount that he/she will pay, then display two messages indicating:
- the maximum number of apps that can be downloaded, and how much funds will remain
in the account after that, if any.
- the maximum number of songs that can be downloaded, the number of apps that can be
downloaded after that if funds allow, and how much funds will remain in the account
after that, if any.
 Notice the parenthesis in app(s) and song(s) in the output.

And I wrote this, but I have a few question about what I wrote ...

"
public class MusicStore
{ double prePay;
prePay = x;
int. songs, apps;
Final int. Songs=3$ , apps=7$
public static void main (String arg[])
{ system.out.println("How much money do you wish to prepay?")"

Keep in mind I am not done. My first (1) question was whether or not I have to define my variables and constants before or after my main method? ( and why if anyone can explain) . Secondly, I don't know how to ask / allow the user to input a number after a question. Finally, for my system output, would I be better using "How much money do you wish to prepay?" or use the define variable.

Really sorry if this is a mess, it's my first time doing this alone!
Yes, it's pretty much a mess, and you have a lot of work ahead of you to get something that will compile without error and run. To get an idea of what some working Java code looks like, take a look at this tutorial and some of the others in this series: http://docs.oracle.com/javase/tutorial/getStarted/cupojava/netbeans.html

Here's a list of a few of the problems I see in your code.

x is undeclared, and you use it to set a value for prePay.
There is no int. type (the period at the end should not be there).
Final is misspelled - it should be final, uncapped.
Numerica values cannot include $.
Some statements are missing the terminating ; character.
Every opening brace ({) must have a matching closing brace (}). You have no closing braces.

Regarding input, see this tutorial on reading input from the command line: http://docs.oracle.com/javase/tutorial/essential/io/cl.html.

Finally, when you post code, please put [ code ] and [ /code ] tags (without the extra spaces) around your code. These tags preserve your indentation and make your code easier to read.
 
  • Like
Likes MarcL
  • #4
alright first time I was posting it. Sorry about that, for the closing bracket I should've done it straight at the beginning, but I didn't out of sheer laziness ( but i should put it so I definitely don't forget). I understand the idea about the "final" being misspelled. As for numerical value (the $ sign) how would I include it, or at least label it. I mean isn't that a vital part when writing units down so it is user friendly?
 
  • #5
MarcL said:
As for numerical value (the $ sign) how would I include it, or at least label it. I mean isn't that a vital part when writing units down so it is user friendly?
There is a big difference between what is displayed to the user and variables in your program. The variables in your program are internal - the user never sees them, so denomination symbols are not part of variable names. Of course, when you print values, you should include the monetary denominations, but you do this by including the denomination symbol when you print the money amount, something like this:

Code:
system.out.println("The cost is $" + itemCost);

BTW, the denomination comes first in US monetary amounts, as in $3 or $5.95, not 3$ or 5.95$.
 
  • Like
Likes Medicol

What is Java?

Java is a high-level, object-oriented programming language used for developing a wide range of applications, including music and app store programs. It was created by James Gosling at Sun Microsystems in 1995 and is now owned by Oracle.

What is the role of Java in music programs?

Java is often used in music programs as it allows for the creation of interactive and dynamic audio applications. It provides a platform-independent environment for music software development and has a wide range of libraries and tools specifically designed for audio programming.

How is Java used in app store programs?

Java is commonly used in app store programs for its versatility and cross-platform compatibility. It allows developers to create apps that can run on different operating systems and devices, making it a popular choice for app development.

What are some advantages of using Java for music and app store programs?

One of the main advantages of using Java for music and app store programs is its ability to run on multiple platforms, making it accessible to a wider audience. It also has a large and active community, which provides support and resources for developers. Additionally, Java is known for its reliability, security, and scalability.

What are some popular music and app store programs that are built using Java?

Some popular music programs that use Java include jMusic, Sonic Pi, and jVSTwRapper. As for app store programs, popular examples include Minecraft, OpenOffice, and Vuze.

Similar threads

  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
10
Views
1K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
19
Views
3K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
5
Views
899
  • Programming and Computer Science
Replies
12
Views
2K
  • Programming and Computer Science
Replies
11
Views
2K
Back
Top