Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Vending Machine plese

  1. #1
    Junior Member
    Join Date
    Nov 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Vending Machine plese

    Good afternoon, I'm having trouble with my code. I wanted to cut and put in a new class what it says int CHOOSE until} while (CHOOSE! = 11); so that in the main you can call the class and run the code and I would like to know the solution to my problem.
    I would like to know how to make a credit card payment for a vending machine product
    Thanks

    Main

    package com.company;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Scanner;

    public class Main {

    public static void main(String args[]) {

    Scanner in = new Scanner(System.in);
    MaquinaVendas maquina = new MaquinaVendas();
    Produto[] main = maquina.darProdutos();
    int ESCOLHA;
    do {
    System.out.println(“Menu da máquina”);
    for (int i = 0; i < main.length; i++) {
    System.out.println("Digite " + (i + 1) + " para " + main[i].darNome());
    }
    System.out.println(“Digite 11 para desligar a máquina”);
    System.out.println(“Digite 12 para ligar a máquina”);
    System.out.println(“Digite 13 Ver Stock Produtos?”);
    System.out.print("Digite a sua escolha: ");
    ESCOLHA = in.nextInt();

    if (ESCOLHA < 1 || ESCOLHA > 13) {
    System.out.println("Escolha Incorreta");
    } else if (ESCOLHA == 12) {
    System.out.println("Ligando a máquina");
    } else if (ESCOLHA == 11) {
    System.out.println("Desligando a máquina");

    } else if (ESCOLHA == 13){
    maquina.MenuMaquina();
    }else {
    maquina.descontarProduto(ESCOLHA - 1);
    }
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    try {
    System.out.println("Prima enter!");
    br.readLine();
    } catch (IOException e) {
    e.printStackTrace();
    }
    } while (ESCOLHA != 11);

    }
    }

    MaquinaVendas

    package com.company;
    import java.text.DecimalFormat;
    import java.util.Scanner;

    public class MaquinaVendas {

    public Produto produtos;
    public Produto[] MaqP;
    public MaquinaVendas() {

    MaqP= new Produto[10];
    MaqP[0] = new Produto("Água 50 cl", 1.50, 10);
    MaqP[1] = new Produto("Coca Cola 50 cl ", 2.00, 10);
    MaqP[2] = new Produto("Ice-Tea 50 cl ", 1.80, 10);
    MaqP[3] = new Produto("Bolo Madalena", 1.10, 10);
    MaqP[4] = new Produto("Bolacha Maria", 1.00, 10);
    MaqP[5] = new Produto("Batata Frita-Lays", 1.50, 10);
    MaqP[6] = new Produto("Kinder-Bueno", 1.70, 10);
    MaqP[7] = new Produto("Kinder-Delice", 1.70, 10);
    MaqP[8] = new Produto("Pastilhas", 1.00, 10);
    MaqP[9] = new Produto("Máscaras", 3.00, 20);

    }

    public void MenuMaquina() {
    for (int i = 0; i < MaqP.length; i++) {
    System.out.print(MaqP[i].darNome());
    System.out.print('\t');
    System.out.print(MaqP[i].darStock());
    System.out.println();
    }
    }
    Classe - Produto

    package com.company;
    import java.util.Scanner;

    public class Produto{

    private String nome;
    private double preco;
    private int stock;

    public Produto(String nomeProduto,double precoProduto,int stockProduto) {
    nome = nomeProduto;
    preco = precoProduto;
    stock = stockProduto;
    }

    public String darNome() {
    return nome;
    }

    public double darPreco() {
    return preco;
    }

    public int darStock() {
    return stock;
    }

    public void reducaoStock() {
    if (stock > 0)
    stock -= 1;
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Vending Machine plese

    how to make a credit card payment for a vending machine product
    Would that be more than just getting the credit card number from the customer?
    For example submitting the number to the credit card company and waiting for approval before finalizing the purchase.


    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Vending Machine plese

    not work the link. can you send the code to email??

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Vending Machine plese

    Sorry, I do not have any code.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Nov 2020
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Vending Machine plese

    can you try help me please?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Vending Machine plese

    can you try help me please?
    I need many more details about the program to be able to suggest what needs to be done.
    Can you explain what you want the program to do?
    Make a detailed list of the steps that the program must take to solve the problem.
    Once you have the details, then work on writing the code to implement them.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Making a vending machine, trouble asking user to insert more money.
    By Mons in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 23rd, 2014, 06:25 PM
  2. Vending Machine
    By javaStooge in forum What's Wrong With My Code?
    Replies: 7
    Last Post: January 26th, 2014, 02:56 PM
  3. Java vending machine, minor thing.
    By Aprok in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 5th, 2011, 02:35 PM
  4. vending machine submit button help
    By maybach230 in forum Java Applets
    Replies: 3
    Last Post: April 23rd, 2010, 10:16 AM
  5. need help with Vending Machine code...
    By mia_tech in forum Loops & Control Statements
    Replies: 3
    Last Post: April 20th, 2009, 05:24 AM