THIS IS THE QUESTION
public class Computer
{
private String brand; //asus, acer, hp etc
private double price; //1699.00
}
Using class definition above, write definition of following methods
-Normal constructor to initialize all attribute
-Accessor for each attribute
-Mutator for each attribute
-Method calDiscount(double) to calculate and return discount amount
method receives the discount percentage rate from the application program.
The discount computed as:
discount amount = price x discount percentage rate
-toString method to display the information of object
Using java, write main() to perform following task
-Declare an array of computer objects. Get size of array from user
-Get input values from user and create the objects
-Display the information of the objects
-Calculate and display total discount amount
-Count and display the number of "Acer" computers
THIS IS MY CLASS DEFINITION :
public class Computer
{
private String brand;
private double price;
//normal constructor
public Computer(String b, double p)
{
brand=b;
price=p;
}
//accessor
public String getBrand()
{
return brand;
}
public double price()
{
return price;
}
//mutator
public void setComputer(String b, double p)
{
brand=b;
price=p;
}
//processor
public double calDiscount()
{
double discount;
double dRate=0;
discount=price*dRate;
return discount;
}
//toString
public String toString()
{
return "The computer brand is: "+brand +"\nThe price is:RM "+price;
}
}//end class
THIS IS MY APPLICATION PROGRAM:
import javax.swing.*;
public class ComputerApp
{
public static void main(String[]args)
{
int n=0;
Computer comp[]=new Computer[n];
for(int i=0; i<n; i++)
{
String brand=JOptionPane.showInputDialog("Enter the computer's brand: ");
double price=Double.parseDouble(JOptionPane.showInputDial og("Enter the price:RM "));
double dRate=Double.parseDouble(JOptionPane.showInputDial og("Enter the discount rate: "));
comp[i].setComputer(brand, price);
}//end for
for(int i=0; i<n; i++)
{
comp[i].toString();
System.out.println(comp[i].toString());
}
double discount=0, dRate;
for(int i=0; i<n; i++)
{
discount=discount+comp[i].getCalDiscount;
}
}
}