Ai galera estou com duvidas nesse codigo…
trata-se de um programa basico com cadastro de funcionarios, fluxo de caixa, estoque e essas coisinhas mais…
o programa roda normal…mais na hora de calcular a comissao do vendedor ele nao calcula direito…
sai 0.000000…
sendo que o quando eu compilo eu coloco como se o vendedor tivesse vendido 10000 e a taxa e de 3%…
ai vai o codigo: A função que calcula as comissões esta la no final do codigo da classe Distribuidora…
-----------------------------------CLASSE DISTRIBUIDORA-------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package distribuidora;
import java.io.PrintStream;
import java.util.Scanner;
import java.lang.String;
import java.lang.System;
import javax.swing.JOptionPane;
/**
*
* @author Heladio
*/
public class Distribuidora {
int t;
int cod=0;
static Clientes[] cliente=new Clientes[1000];
static Funcionarios[] func=new Funcionarios[100];
static Vendedores[] vend=new Vendedores[50];
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
public void menu(){
int t;
System.out.println("----------Menu----------\n");
System.out.println("1 - Caixa");
System.out.println("2 - Estoque");
System.out.println("3 - Clientes");
System.out.println("4 - Funcionarios");
System.out.println("5 - Bonificacoes");
System.out.println("6 - Relatorios");
System.out.println("7 - Rotas");
System.out.println("8 - Sair\n");
System.out.println(">> ");
t=lerInt();
switch(t){
case 1:
break;
case 2:
break;
case 3:
System.out.println("----------CLIENTES----------");
System.out.println("1 - Cadastrar cliente");
System.out.println("2 - Listar clientes");
System.out.println("3 - Buscar clientes");
System.out.println("4 - Remover cliente");
System.out.println("5 - Sair\n");
System.out.println(">>");
t=lerInt();
switch(t){
case 1:
cadClientes();
break;
case 2:
listClientes();
break;
case 3:
busClientes();
break;
case 4:
removClientes();
break;
case 5:
menu();
default:
menu();
}
break;
case 4:
System.out.println("----------FUNCIONARIOS----------");
System.out.println("1 - Cadastrar");
System.out.println("2 - Buscar");
System.out.println("3 - Listar");
System.out.println("4 - Remover");
System.out.println("5 - Comissões");
System.out.println("6 - Sair\n");
System.out.println(">>");
t=lerInt();
switch(t){
case 1:
cadFunc();
break;
case 2:
busFunc();
break;
case 3:
listFunc();
break;
case 4:
removFunc();
break;
case 5:
comissionFunc();
break;
default:
menu();
}
break;
case 5:
break;
case 6:
break;
case 7:
break;
default:
System.exit(1);
}
}
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
public void busClientes(){
String y;
int c;
int t=0;
System.out.println("----------BUSCAR----------\n");
System.out.println("1 - Buscar por nome");
System.out.println("2 - Buscar por codigo\n");
System.out.printf(">> ");
switch(lerInt()){
case 1:
System.out.println("----------BUSCAR----------\n");
System.out.println("Nome do cliente: \n");
System.out.printf(">> ");
y=lerString().toUpperCase();
for(t=0;t<cliente.length;t++){
if(cliente[t]!=null){
if(y.equals(cliente[t].getNome())){
System.out.printf("Codigo: %d\n", cliente[t].getCod());
System.out.printf("Cliente: %s\n", cliente[t].getNome());
System.out.printf("Endereco: %s\n", cliente[t].getEnd());
System.out.printf("Numero: %d\n", cliente[t].getNumero());
System.out.printf("Vendedor: %s\n", cliente[t].getVend());
System.out.printf("Rota: %s\n", cliente[t].getRota());
System.out.printf("Telefone: %d\n", cliente[t].getTel());
System.out.printf("- - - - - - - - - - - - - -\n");
break;
}
}
}
break;
case 2:
System.out.println("----------BUSCAR-----------\n");
System.out.println("Codigo do cliente: \n");
System.out.printf(">> ");
c=lerInt();
for(t=0;t<cliente.length;t++){
if(cliente[t]!=null){
if(cliente[t].getCod()==c){
System.out.printf("Codigo: 00%d\n", cliente[t].getCod());
System.out.printf("Cliente: %s\n", cliente[t].getNome());
System.out.printf("Endereco: %s\n", cliente[t].getEnd());
System.out.printf("Numero: %d", cliente[t].getNumero());
System.out.printf("Vendedor: %s\n", cliente[t].getVend());
System.out.printf("Rota: %s\n", cliente[t].getRota());
System.out.printf("Telefone: %d\n", cliente[t].getTel());
System.out.printf("- - - - - - - - - - - - - -\n");
break;
}
}
}
break;
default:
System.out.println("Numero invalido.");
menu();
}
menu();
}
public void removClientes(){
String c;
int r=0;
int cod;
System.out.printf("----------REMOVER----------\n");
System.out.printf("1 - Remover por nome");
System.out.printf("2 - Remover por codigo\n");
System.out.printf(">> ");
switch(lerInt()){
case 1:
System.out.printf("----------REMOVER----------\n");
System.out.printf("Nome do cliente: \n");
System.out.printf(">> ");
c=lerString().toUpperCase();
for(r=0;r<cliente.length;r++){
if(cliente[r]!=null){
if(c.equals(cliente[r].getNome())){
cliente[r].setStatus(2);
break;
}
}
}
case 2:
System.out.printf("----------REMOVER----------\n");
System.out.printf("Codigo do cliente: \n");
System.out.printf(">> ");
cod=lerInt();
for(r=0;r<cliente.length;r++){
if(cliente[r]!=null){
if(cliente[r].getCod()==cod){
cliente[r].setStatus(2);
break;
}
}
}
break;
}
menu();
}
public void listClientes(){
System.out.println("----------LISTAR----------\n");
for(int i=0;i<cliente.length;i++){
if(cliente[i]!=null){
if(cliente[i].getStatus()==1){
System.out.printf("Codigo: %d\n", cliente[i].getCod());
System.out.printf("Cliente: %s\n", cliente[i].getNome());
System.out.printf("Endereco: %s\n", cliente[i].getEnd());
System.out.printf("Numero: %d\n", cliente[i].getNumero());
System.out.printf("Vendedor: %s\n", cliente[i].getVend());
System.out.printf("Rota: %s\n", cliente[i].getRota());
System.out.printf("Telefone: %d\n", cliente[i].getTel());
System.out.printf("- - - - - - - - - - - - - -\n");
}
}
}
menu();
}
public void cadClientes(){
int y;
System.out.println("----------CLIENTES----------\n");
System.out.println("Quantidade de cadastros: \n");
System.out.printf(">> ");
y=lerInt();
for(int post=0;post<y;post++){
cliente[post]=new Clientes();
System.out.printf("Codigo do cliente: 00%d\n", post+1);
cliente[post].setCod(post+1);
System.out.printf("Cliente: ");
cliente[post].setNome(lerString());
System.out.printf("Endereco: ");
cliente[post].setEnd(lerString());
System.out.printf("Numero: ");
cliente[post].setNumero(lerInt());
System.out.printf("Telefone: ");
cliente[post].setTel(lerInt());
System.out.printf("Vendedor: ");
cliente[post].setVend(lerString());
System.out.printf("Rota: ");
cliente[post].setRota(lerString());
System.out.printf("Status 1-Ativo 2-Inativo: ");
cliente[post].setStatus(lerInt());
System.out.printf("- - - - - - - - - - - - - -\n");
}
menu();
}
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
public void cadFunc(){
int q;
System.out.println("----------CADASTRAR----------");
System.out.printf("1 - Cadastrar vendedor\n");
System.out.printf("2 - Cadastrar funcionario\n");
System.out.printf(">>\n");
switch(lerInt()){
case 1:
System.out.println("Quantidade de cadastros: ");
q=lerInt();
for(int postf=0;postf<q;postf++){
vend[cod]=new Vendedores();
vend[cod].setCod(cod+1);
System.out.printf("Codigo do vendedor: %d\n", vend[cod].getCod());
System.out.println("Nome: ");
vend[cod].setNome(lerString());
System.out.println("Endereco: ");
vend[cod].setEnd(lerString());
System.out.println("Numero: ");
vend[cod].setNumero(lerInt());
System.out.println("Telefone: ");
vend[cod].setTelefone(lerInt());
System.out.println("Rota: ");
vend[cod].setRota(lerString());
System.out.printf("Vendas brutas: ");
vend[cod].setVendas(lerDouble());
System.out.println("Status: 1-Ativo 2-Inativo");
vend[cod].setStatus(lerInt());
System.out.printf("- - - - - - - - - - - - - -\n");
cod++;
}
break;
case 2:
System.out.println("Quantidade de cadastros: ");
q=lerInt();
for(int postf=0;postf<q;postf++){
func[cod]=new Funcionarios();
func[cod].setCod(cod+1);
System.out.printf("Codigo do funcionario: %d\n", func[cod].getCod());
System.out.println("Nome: ");
func[cod].setNome(lerString());
System.out.println("Endereco: ");
func[cod].setEnd(lerString());
System.out.println("Numero: ");
func[cod].setNumero(lerInt());
System.out.println("Telefone: ");
func[cod].setTelefone(lerInt());
System.out.println("Status: 1-Ativo 2-Inativo");
func[cod].setStatus(lerInt());
System.out.printf("- - - - - - - - - - - - - -\n");
cod++;
}
break;
}
menu();
}
public void busFunc(){
String n;
int c;
System.out.printf("----------BUSCAR----------\n");
System.out.printf("1 - Buscar por nome\n");
System.out.printf("2 - Buscar por codigo\n");
System.out.printf(">> \n");
switch(lerInt()){
case 1:
System.out.printf("----------BUSCAR----------\n");
System.out.printf("Nome: ");
n=lerString().toUpperCase();
for(int i=0;i<func.length;i++){
if(func[i]!=null){
if(n.equals(func[i].getNome())){
if(func[i].getStatus()!=2){
System.out.printf("Codigo: %d\n", func[i].getCod());
System.out.printf("Funcionario: %s\n", func[i].getNome());
System.out.printf("Endereco: %s - %d \n", func[i].getEnd(), func[i].getNumero());
System.out.printf("Telefone: %d\n", func[i].getTelefone());
System.out.printf("- - - - - - - - - - - - - -\n");
break;
}
}
}
}
for(int i=0;i<vend.length;i++){
if(vend[i]!=null){
if(n.equals(vend[i].getNome())){
if(vend[i].getStatus()!=2){
System.out.printf("Codigo: %d\n", vend[i].getCod());
System.out.printf("Vendedor: %s\n", vend[i].getNome());
System.out.printf("Endereco: %s - %d \n", vend[i].getEnd(), vend[i].getNumero());
System.out.printf("Telefone: %d\n", vend[i].getTelefone());
System.out.printf("Rota: %s\n", vend[i].getRota());
System.out.printf("Vendas brutas: %f\n", vend[i].getVendas());
System.out.printf("- - - - - - - - - - - - - -\n");
break;
}
}
}
}
break;
case 2:
System.out.printf("----------BUSCAR----------\n");
System.out.printf("Codigo: ");
c=lerInt();
for(int i=0;i<func.length;i++){
if(func[i]!=null){
if(func[i].getCod()==c){
System.out.printf("Codigo: %d\n", func[i].getCod());
System.out.printf("Funcionario: %s \n", func[i].getNome());
System.out.printf("Endereco: %S - %d\n", func[i].getEnd(), func[i].getNumero());
System.out.printf("Telefone: %d\n", func[i].getTelefone());
System.out.printf("- - - - - - - - - - - - - -\n");
break;
}
}
}
for(int i=0;i<vend.length;i++){
if(vend[i]!=null){
if(vend[i].getCod()==c){
System.out.printf("Codigo: %d\n", vend[i].getCod());
System.out.printf("Vendedor: %s \n", vend[i].getNome());
System.out.printf("Endereco: %S - %d\n", vend[i].getEnd(), vend[i].getNumero());
System.out.printf("Telefone: %d\n", vend[i].getTelefone());
System.out.printf("Rota: %s\n", vend[i].getRota());
System.out.printf("Vendas brutas: %f\n", vend[i].getVendas());
System.out.printf("- - - - - - - - - - - - - -\n");
break;
}
}
}
break;
}
menu();
}
public void listFunc(){
System.out.printf("----------LISTAR----------");
for(int i=0;i<func.length;i++){
if(func[i]!=null){
if(func[i].getStatus()==1){
System.out.printf("Codigo: %d\n", func[i].getCod());
System.out.printf("Funcionario: %s\n", func[i].getNome());
System.out.printf("Endereco: %s - %d\n", func[i].getEnd(), func[i].getNumero());
System.out.printf("Telefone: %d\n", func[i].getTelefone());
}
}
}
for(int t=0;t<vend.length;t++){
if(vend[t]!=null){
if(vend[t].getStatus()==1){
System.out.printf("Codigo: %d\n", vend[t].getCod());
System.out.printf("Vendedor: %s\n", vend[t].getNome());
System.out.printf("Endereco: %s - %d\n", vend[t].getEnd(), vend[t].getNumero());
System.out.printf("Telefone: %d\n", vend[t].getTelefone());
System.out.printf("Rota: %s\n", vend[t].getRota());
System.out.printf("Vendas brutas: %f\n", vend[t].getVendas());
}
}
}
menu();
}
public void removFunc(){
int cod;
String n;
System.out.printf("----------REMOVER----------\n");
System.out.printf("1 - Remover por nome\n");
System.out.printf("2 - Remover por codigo\n>>");
switch(lerInt()){
case 1:
System.out.printf("----------REMOVER----------\n");
System.out.printf("Funcionario: ");
n=lerString().toUpperCase();
for(int i=0;i<func.length;i++){
if(func[i]!=null){
if(n.equals(func[i].getNome())){
func[i].setStatus(2);
break;
}
}
}
break;
case 2:
System.out.printf("----------REMOVER----------\n");
System.out.printf("Codigo: ");
cod=lerInt();
for(int i=0;i<func.length;i++){
if(func[i]!=null){
if(func[i].getCod()==cod){
func[i].setStatus(2);
break;
}
}
}
break;
}
menu();
}
public void comissionFunc(){
String n;
System.out.printf("----------COMISSÕES----------\n");
System.out.printf("1 - Nome do vendedor\n");
System.out.printf("2 - Codigo do vendedor\n");
System.out.printf(">> ");
switch(lerInt()){
case 1:
System.out.printf("----------COMISSÕES----------\n");
System.out.printf("Vendedor: ");
n=lerString().toUpperCase();
for(int i=0;i<vend.length;i++){
if(vend[i]!=null){
if(n.equals(vend[i].getNome())){
System.out.printf("Codigo: %d\n", vend[i].getCod());
System.out.printf("Vendedor: %s\n", vend[i].getNome());
System.out.printf("Comissao: %f\n", vend[i].getComissao());
break;
}
}
}
break;
case 2:
break;
}
menu();
}
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------------------------------------------------
public static String lerString(){
Scanner ler=new Scanner(System.in);
return ler.nextLine();
}
public static Double lerDouble(){
Scanner ler=new Scanner(System.in);
return ler.nextDouble();
}
public static int lerInt(){
Scanner ler=new Scanner(System.in);
return ler.nextInt();
}
}
--------------------------------------CLASSE VENDEDORES---------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package distribuidora;
/**
*
* @author Heladio
*/
public class Vendedores extends Funcionarios {
double vendas=0;
double taxa=0.03;
double comissao;
Vendedores(){}
Vendedores(String name, String ender, int num, int tel, String rot, int stat, int cod, float sal, double vend, double tax){
super(name, ender, num, tel, rot, stat, cod, sal);
setVendas(vend);
setComissao(tax, vendas);
}
public void setVendas(double vend) {
vendas+=vend;
}
public void setComissao(double tax, double vendas){
comissao=vendas*tax;
}
public double getVendas(){
return vendas;
}
public double getTaxa(){
return taxa;
}
public double getComissao(){
return comissao;
}
}