Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this assignment, we will used JOptonpane as the main method and an object or

ID: 3889751 • Letter: F

Question

For this assignment, we will used JOptonpane as the main method and an object oriented approach (Constructors, getters, setters, special purposes methods). Validation will be done in the data definition class and reinforce in the implementation class with try and catch. Use the work new to create an new object in the implementation class. Only one object will be created for this assignment.

You are about to create a car dealer company and you will like to create a program that will do the following:

-Ask for the name of the car to be sold (This information is mandotory and must enter. If left blank, the program should handle it)

- Ask for the number of agents that will be working at the dealership (If no information is provide, the default number of agent will be 1)

- Ask if the user will want a warranty for the car or not

- Request for the amount of sale of cars until the user chose not to enter more sale

- Totalize the number of of sale (counter)

Explanation / Answer

package primenumber;

import javax.swing.JOptionPane;

public class car {

private static final car object = new car();

public static String input;

public static String agent;

public static String warranty;

public static String amount;

public String getInput() {

return input;

}

public void setInput(String input) {

this.input = input;

}

public String getAgent() {

return agent;

}

public void setAgent(String agent) {

this.agent = agent;

}

public String getWarranty() {

return warranty;

}

public void setWarranty(String warranty) {

this.warranty = warranty;

}

private car() {}

public static car getInstance() {

return object;

}

public static void main( String [] args ) {

car c= car.getInstance();

int defaultagent=1;

String Request="Y";

int total=0;

do {

input = JOptionPane.showInputDialog( null,"Please enter name of a car" );

agent = JOptionPane.showInputDialog( null,"Please number of agents" );

warranty = JOptionPane.showInputDialog( null,"you want warranty or not? Enter y/Y or n/N" );

try

{

if(input==null || input.isEmpty())

{

input= "maruti";

c.setInput(input);

JOptionPane.showMessageDialog( null, "your Default car is " + input );

}

else

{

c.setInput(input);

JOptionPane.showMessageDialog( null, "your input car is " + input );

}

if(agent.isEmpty() || agent==null)

{

defaultagent=1;

c.setAgent(String.valueOf(defaultagent));

JOptionPane.showMessageDialog( null, "your agent number is " + defaultagent );

}

else

{

int agents=Integer.parseInt(agent);

c.setAgent(agent);

JOptionPane.showMessageDialog( null, "your agent numbers are " + agents );

}

if(warranty.equals("y")|| warranty.equals("Y"))

{

c.setWarranty(warranty);

JOptionPane.showMessageDialog( null, "you want warranty " );

}

else

{

c.setWarranty(warranty);

JOptionPane.showMessageDialog( null, "you don't want warranty " );

}}

catch(Exception e)

{

System.out.println(e);

}

total=total+1;

Request=JOptionPane.showInputDialog( null, "Do you want to sale more cars.Please enter Y otherwise N ");

} while(Request.equals("Y"));

  

JOptionPane.showMessageDialog( null, "Your total cars"+total );

  

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote