How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask LogicPro Your Own Question

LogicPro
LogicPro, Engineer
Category: Homework
Satisfied Customers: 9541
Experience:  Expert in Java C++ C C# VB Javascript Design SQL HTML
29751445
Type Your Homework Question Here...
LogicPro is online now
A new question is answered every 9 seconds

Today in class I was asked to do the following: Write a class

Resolved Question:

Today in class I was asked to do the following:
Write a class Automaton which implements a basic vending machine. The machine has three things to o er: water, cola, and juice. The prices
are 10, 12, and 15, respectively. The customer selects this by typing W, C, or J re-
spectively. The the customer inserts coins with values 1, 2, 5, 10, or 20, and types
"SELECT" to complete the transaction. Depending on whether the customer paid to
much, exact, or too few, the output of the machine is like in the following example.
W Paid 15 change is 5
J Paid 15 thanks
C Not paid enough . Return 11
DONE
3
This example was generated by the following input:
W
5
10
SELECT
J
10
5
SELECT
C
1
10
SELECT
TERMINATE
The string TERMINATE makes the program write DONE and terminate. If an error occurs,
e.g. an illegal value of a coin or the selected item. The machine writes ERROR and
terminates, e.g., by System.exit(0).
Your program should read from standard input, for example using a scanner.
Submitted: 11 months ago.
Category: Homework
Expert:  LogicPro replied 11 months ago.
Hi,
Welcome here.
My name is XXXXX XXXXX I will help you.
What is the deadline?
Customer: replied 11 months ago.

Tomorrow, Is that possible?

Expert:  LogicPro replied 11 months ago.
yes, I will provide you answer ASAP.
Customer: replied 11 months ago.

Thank you

Expert:  LogicPro replied 11 months ago.
Welcome
Customer: replied 11 months ago.

How's it going?


do you have an ETA? :)

Expert:  LogicPro replied 11 months ago.
Please check back in 5-6 hours.
Expert:  LogicPro replied 11 months ago.
If you have any file(s). Zip, upload the file to http://wikisend.com and post download link here.

Expert:  LogicPro replied 11 months ago.
Download answer from here: Automaton.java
Please let me know if anything else is required in this.

You can ask me again using "For LogicPro only" at the start of your questions like other customers to get instant answers.
It will ensure that question is for me.
Please bookmark my profile page:
http://www.justanswer.com/computer/expert-logicpro/
so you can come back and ask me a question anytime.
Remember, if you need anything else, we can continue the conversation until you’re satisfied and rate my answer as excellent. I can address follow up questions at no extra charge and I’m always here to help.
Thank you for using this site!
LogicPro, Engineer
Category: Homework
Satisfied Customers: 9541
Experience: Expert in Java C++ C C# VB Javascript Design SQL HTML
LogicPro and 6 other Homework Specialists are ready to help you
Customer: replied 11 months ago.

Hey thanks for the answer, my teacher also wants me to commentate what is happening i.e explain which commands we use. He wants a little text between 5-10 lines explaining how the program is structures. I hope you can help me with this last thing


 

Expert:  LogicPro replied 11 months ago.
please wait.
Expert:  LogicPro replied 11 months ago.
Download again from here: Automaton.java
Customer: replied 11 months ago.

Here is an example of what my teacher wants:


Program structure (detailed)
We used a number of static methods to structure the program.
Method main contains the main program control. It basically consists of a while-loop
that performs two steps: Fetching the next number to be factorized and initiating the
factorization. In order to initialize the loop condition, the rst integer is fetched before
the loop. Termination is achieved when a ceratin integer value is supplied (in our case
􀀀1 (actually, any number less than 2)).
1
Method int getNumber() fetches and returns the next integer from the standard input.
We use an instance of Scanner for this purpose. The method uses Scanner-class' look-
ahead capability (hasNextInt) to ensure that the user supplied an integer. If that is not
the case, a warning is issued and the termination value is returned.
Method factorize(int n) receives the number to be factorized as formal parameter. It
then performs the decomposition into prime factors described above. A while-loop is used
which terminates when the value of n drops under 2. The method also prints the factors.
The least factor is provided by method findFactor.
Method int findFactor(int n) receives a number as formal parameter and returns its
least factor. It nds the least factor as described above by checking the remainder of
the division. A while-loop is used which terminates when the remainder is 0 for the rst
time. This is guaranteed to happen, because: n  f = 2 at start, f is increased in each
iteration of the loop, the remainder becomes 0 at latest when f = n.


 


Thanks

Expert:  LogicPro replied 11 months ago.
I will review it and reply you ASAP.
Expert:  LogicPro replied 11 months ago.
Customer: replied 11 months ago.

Thanks :) one last thing and I will you give you the highest rating!


I can't seem to test the Vending Machine. Could you use some random number lets say we pick w and we have a 20 coin, could you fill out the variable so i can see where to input them ?


 


thanks alot

Expert:  LogicPro replied 11 months ago.
Will it be ok if I provide you an output screenshot?
Customer: replied 11 months ago.

I just need to know where to input the money and the type of drink so if you can provide that in a screen shot yes :)

Expert:  LogicPro replied 11 months ago.

Here is the output:
Enter W, C or J for Water, Cola or Juice: W
2
5
SELECT

Not paid enough . Balance 3
5
SELECT

Paid 10 change is 2
TERMINATE

Enter W, C or J for Water, Cola or Juice:

Entries in bold are the user input.

Customer: replied 11 months ago.

Where do I input 2 and 5 ?

Expert:  LogicPro replied 11 months ago.
After inputing item choice (W, C or J)
Customer: replied 11 months ago.

so in one line Enter W, C or J for Water, Cola or Juice: W,2,5 ?

Expert:  LogicPro replied 11 months ago.
No
Run in the same manner, as I provided you sample input/output.

Are you able to execute the program?
Customer: replied 11 months ago.

No,


t


 


his is what i did input then


 


while (true) {


/*PROMPT USER TO INPUT AN ITEM*/
System.out.print("Enter W, C or J for Water, Cola or Juice: w");
2
5
SELECT
Not paid enough . Balance 3
5
SELECT
Paid 10 change is 2
TERMINATE
String item = sc.nextLine();
/*FIND COST OF ITEM*/
int itemCost = 0;
if (item.equalsIgnoreCase("W")) {

Expert:  LogicPro replied 11 months ago.
Can you provide me output screenshot, how you are executing it?

Program is exactly as per the instructions.
Customer: replied 11 months ago.

here; http://tinypic.com/view.php?pic=dmqo05&s=5#.UlQu5VBmh8E


any chance you can upload a screenshot of how you have done it?


 

Expert:  LogicPro replied 11 months ago.
Do not write anything in the code, which I gave you.
You can submit code as it is, It is exactly as per the instructions.

Customer: replied 11 months ago.

ah thanks I feel so stupid now :)


really good and effective help you gave me thank you.

Expert:  LogicPro replied 11 months ago.
THIS ANSWER IS LOCKED!

You need to spend $3 to view this post. Add Funds to your account and buy credits.

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Last | Next >
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
  • He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX
 
 
 

Meet The Experts:

 
 
 
  • Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
< Last | Next >
  • http://ww2.justanswer.com/uploads/BU/BusinessTutor/2012-2-2_115741_Kouki2.64x64.jpg Manal Elkhoshkhany's Avatar

    Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4520
    More than 5000 online tutoring sessions.
  • http://ww2.justanswer.com/uploads/LI/lindaus/2012-6-10_04811_IMG20120609164157.64x64.jpg Linda_us's Avatar

    Linda_us

    Finance, Accounts & Homework Tutor

    Satisfied Customers:

    3121
    Post Graduate Diploma in Management (MBA)
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Engineer

    Satisfied Customers:

    3035
    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • http://ww2.justanswer.com/uploads/lanis/2009-4-1_233717_phput9xef_c1pm.jpg Lani S.'s Avatar

    Lani S.

    Tutor

    Satisfied Customers:

    2457
    Registered Nurse, Internet Researcher, Private Tutor
  • http://ww2.justanswer.com/uploads/chooser77/2009-08-18_162025_Chris.jpg Chris M.'s Avatar

    Chris M.

    M.S.W. Social Work

    Satisfied Customers:

    2341
    Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)
  • http://ww2.justanswer.com/uploads/JawaadAhmed/2009-6-27_12137_SIs_SHadi.jpg F. Naz's Avatar

    F. Naz

    Chartered Accountant

    Satisfied Customers:

    1975
    Experience with chartered accountancy
  • http://ww2.justanswer.com/uploads/JK/jkcpa/2011-1-16_182614_jkcpa.64x64.jpg Bizhelp's Avatar

    Bizhelp

    CPA

    Satisfied Customers:

    1873
    Bachelors Degree and CPA with Accounting work experience
 
 
 

Related Homework Questions