Luigi-Vivian Postado Outubro 19, 2017 Denunciar Compartilhar Postado Outubro 19, 2017 Olá pessoas, estou disponibilizando a parte pratica da prova de programação orientada a objetos(Curso Analise e Desenvolvimento de Sistemas) para que quem quiser resolver o problema para questões didáticas, exercitar seila, enfim.... Prova da disciplina de Programação Orientada a Objetos - Parte Prática Dada as classes para implementação a seguir:-----Veiculo------placa : String-modelo : String-valor : Double-marcha : Integer-aceleracao : Integer -----Metodos-----+Veiculo(placa : String, modelo : String, valor : Double){}+LigarDesligar() : void+incMarcha() : void+ decMarcha() : void+ getters( ) : type;+setters(value: type) : void 1- (Peso 3) No projeto implemente a classe Veiculo conforme a definição acima. Implemente os métodos conforme as definições abaixo.Gerar exceções se alguma regra for quebrada, com mensagem personalizada para cada tipo de erro.a) Ao instanciar um veiculo este deve ficar com ligado = false, aceleracao = 0 e marcha = 0b) Ao ligar deve ficar com aceleracao = 1000 RPMc) Ao desligar deve ficar com aceleracao = 0 RPMd) Ao trocar de marcha, deve incrementar ou decrementar marcha uma a uma, sendo o mínimo 0 (neutro) e o máximo 6(a) marchae) Somente permitir ligar ou desligar estando em marcha neutraf) Somente permitir trocar de marcha se o veiculo estiver ligado 2.1 (Peso 1) Instanciar um objeto da classe Veiculo. O objeto deve ser inicializado usando o método construtor e os dados que devem ser lidos do usuário são: placa, modelo,valor.2- Crie uma classe de UI ( console) ou GUI (grafica) chamada "ControlarVeiculo" em um pacote separado. Nesta classe faça implementações para:2.2 (Peso 1) Permitir o usuario ligar,desligar, e fazer trocar de marcha.2.3 (Peso 1) Mostrar mensagens adequadas caso alguma exceção ocorra2.4 (Peso 1) Permitir o usuário visualizar o estado atual do objeto. Code Classe veiculo: /** * * @author luigi */ public class Veiculo { private String placa; private String modelo; private Double valor; private Boolean ligado; private Integer marcha; private Integer aceleracao; Veiculo(String placa, String modelo, Double valor){ this.placa = placa; this.modelo = modelo; this.valor = valor; this.aceleracao = 0; this.marcha = 0; this.ligado = false; } public void ligarDesligar() throws Exception{ if(this.marcha != 0){ throw new Exception("O carro só pode ligar ou desligar na marcha neutra !"); } if(this.ligado){ this.ligado = false; this.aceleracao = 0; }else{ this.ligado = true; this.aceleracao = 1000; } } public void incMarcha() throws Exception{ if(!ligado){ throw new Exception("O carro deve estar ligado para realizar trocas de marchas"); } if(this.marcha < 6){ this.marcha++; }else{ throw new Exception("O carro só vai até a sexta marcha"); } } public void decMarcha() throws Exception{ if(!ligado){ throw new Exception("O carro deve estar ligado para realizar trocas de marchas"); } if(this.marcha > 0){ this.marcha--; }else{ throw new Exception("O carro só vai até a marcha 0 (neutra)"); } } public String getPlaca() { return placa; } public void setPlaca(String placa) { this.placa = placa; } public String getModelo() { return modelo; } public void setModelo(String modelo) { this.modelo = modelo; } public Double getValor() { return valor; } public void setValor(Double valor) { this.valor = valor; } public Boolean getLigado() { return ligado; } public void setLigado(Boolean ligado) { this.ligado = ligado; } public Integer getMarcha() { return marcha; } public void setMarcha(Integer marcha) { this.marcha = marcha; } public Integer getAceleracao() { return aceleracao; } public void setAceleracao(Integer aceleracao) { this.aceleracao = aceleracao; } } Code Classe GUI: import javax.swing.JOptionPane; /** * * @author luigi */ public class GUI extends javax.swing.JFrame { Veiculo v; public GUI() { initComponents(); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); cpPlaca = new javax.swing.JTextField(); btCriar = new javax.swing.JButton(); cpModelo = new javax.swing.JTextField(); cpValor = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); cpAceleracao = new javax.swing.JTextField(); jLabel5 = new javax.swing.JLabel(); cpLigado = new javax.swing.JTextField(); jLabel6 = new javax.swing.JLabel(); cpMarcha = new javax.swing.JTextField(); btPower = new javax.swing.JButton(); jLabel7 = new javax.swing.JLabel(); btIncMarcha = new javax.swing.JButton(); btDecMarcha = new javax.swing.JButton(); jLabel8 = new javax.swing.JLabel(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setBackground(new java.awt.Color(93, 254, 54)); jLabel1.setText("Placa:"); jLabel2.setText("Valor:"); jLabel3.setText("Modelo:"); cpPlaca.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cpPlacaActionPerformed(evt); } }); btCriar.setText("Criar"); btCriar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btCriarActionPerformed(evt); } }); cpModelo.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cpModeloActionPerformed(evt); } }); cpValor.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cpValorActionPerformed(evt); } }); jLabel4.setText("Ligado:"); jLabel5.setText("Aceleração:"); jLabel6.setText("Marcha:"); btPower.setText("POWER"); btPower.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btPowerActionPerformed(evt); } }); jLabel7.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N jLabel7.setForeground(new java.awt.Color(255, 0, 68)); jLabel7.setText("Cambio:"); btIncMarcha.setText("+"); btIncMarcha.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btIncMarchaActionPerformed(evt); } }); btDecMarcha.setText("-"); btDecMarcha.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btDecMarchaActionPerformed(evt); } }); jLabel8.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N jLabel8.setForeground(new java.awt.Color(255, 0, 0)); jLabel8.setText("Liga/Desliga"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel4) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(jLabel6))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(cpAceleracao, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 0, Short.MAX_VALUE)) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(cpLigado, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cpMarcha, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel8) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(12, 12, 12) .addComponent(btPower))) .addGap(18, 18, 18) .addComponent(jLabel7)))) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cpPlaca, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(21, 21, 21) .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cpModelo, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(33, 33, 33) .addComponent(jLabel2))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(cpValor) .addComponent(btIncMarcha, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btDecMarcha, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)) .addGap(18, 18, 18) .addComponent(btCriar) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(jLabel3) .addComponent(cpPlaca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btCriar) .addComponent(cpModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(cpValor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(33, 33, 33) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(cpLigado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btIncMarcha)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cpMarcha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel6) .addComponent(btDecMarcha))) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(27, 27, 27) .addComponent(jLabel8) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel7) .addComponent(btPower)))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cpAceleracao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel5)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) ); pack(); }// </editor-fold> private void cpPlacaActionPerformed(java.awt.event.ActionEvent evt) { } private void cpModeloActionPerformed(java.awt.event.ActionEvent evt) { } private void cpValorActionPerformed(java.awt.event.ActionEvent evt) { } private void btPowerActionPerformed(java.awt.event.ActionEvent evt) { if(v instanceof Veiculo){ try { v.ligarDesligar(); AtualizarVisor(); } catch (Exception ex) { JOptionPane.showMessageDialog(rootPane, ex.getMessage()); } } else{ return; } } private void btCriarActionPerformed(java.awt.event.ActionEvent evt) { if(cpValor.getText().equals("") || cpModelo.getText().equals("") || cpPlaca.getText().equals("")){ JOptionPane.showMessageDialog(rootPane, "Prencha os campos !"); return; }else{ v = new Veiculo(cpPlaca.getText(), cpModelo.getText(), Double.parseDouble(cpValor.getText())); } AtualizarVisor(); } private void btIncMarchaActionPerformed(java.awt.event.ActionEvent evt) { try { v.incMarcha(); } catch (Exception ex) { JOptionPane.showMessageDialog(rootPane, ex.getMessage()); } AtualizarVisor(); } private void btDecMarchaActionPerformed(java.awt.event.ActionEvent evt) { try { v.decMarcha(); } catch (Exception ex) { JOptionPane.showMessageDialog(rootPane, ex.getMessage()); } AtualizarVisor(); } public void AtualizarVisor(){ cpLigado.setText(v.getLigado().toString()); cpMarcha.setText(v.getMarcha().toString()); cpAceleracao.setText(v.getAceleracao().toString()); } /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new GUI().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btCriar; private javax.swing.JButton btDecMarcha; private javax.swing.JButton btIncMarcha; private javax.swing.JButton btPower; private javax.swing.JTextField cpAceleracao; private javax.swing.JTextField cpLigado; private javax.swing.JTextField cpMarcha; private javax.swing.JTextField cpModelo; private javax.swing.JTextField cpPlaca; private javax.swing.JTextField cpValor; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JPanel jPanel1; // End of variables declaration } 1 Link para o comentário Compartilhar em outros sites More sharing options...
ExtraPlays Postado Outubro 19, 2017 Denunciar Compartilhar Postado Outubro 19, 2017 Achei legal a ideia do projeto, Estou voltando a mexer com java vou ver se ainda consigo fazer isso kk 1 Link para o comentário Compartilhar em outros sites More sharing options...
zAth Postado Outubro 19, 2017 Denunciar Compartilhar Postado Outubro 19, 2017 Sempre quus saber como era uma prova dessas ;-; pensei que fossem maiores. Será que aceitariam se fizesse o GUI em javafx usando scene builder? Link para o comentário Compartilhar em outros sites More sharing options...
Luigi-Vivian Postado Outubro 19, 2017 Autor Denunciar Compartilhar Postado Outubro 19, 2017 Sempre quus saber como era uma prova dessas ;-; pensei que fossem maiores. Será que aceitariam se fizesse o GUI em javafx usando scene builder? A prova em si é simples, porem envolve varios conceitos de POO. Aceitariam sim, o professor até deixou escolher a forma que queria fazer a interface do usuario, isso é de menos uahuahuah Link para o comentário Compartilhar em outros sites More sharing options...
lucakiksd07 Postado Junho 29, 2019 Denunciar Compartilhar Postado Junho 29, 2019 Seu tópico foi marcado como Inativo. Para reverter esta ação, entre em contato com a equipe de Moderação. OBS: Essa mensagem é automática. Link para o comentário Compartilhar em outros sites More sharing options...
Posts Recomendados