DJ Emporium - Java Pt. 4

Chris Chen
/*
* Purpose: to create a class that holds information about a record
*/

import javax.swing.JOptionPane;

public class Record {

private int sku; //stores the SKU value of a record
private String artist; //stores the artist of a record
private String album; //stores the album of a record
private double price; //stores the price of a record
private int quan; //stores the quantity of the record in stock
private boolean valid; //represents the validity of the record

//creates an object representing a record
public Record(String skuNum, String art, String abm, String prc, String qnt){

valid = true;
artist = art;
album = abm;

//checks if the fields have data
if(artist.length() == 0 || album.length() == 0)
valid = false;

//determines if the numbers are valid format
try{

sku = Integer.parseInt(skuNum);
price = Double.parseDouble(prc);
quan = Integer.parseInt(qnt);

//checks if the numbers are in range
if(sku }catch(NumberFormatException e){

valid = false;

}//end try - catch

}//end Record constructor

//getter method for the record's SKU
public int getSku() {

return sku;

}//end getSku

//getter method for the record's album
public String getAlbum() {

return album;

}//end getAlbum

//getter method for the record's artist
public String getArtist() {

return artist;

}//end getArtist

//getter method for the record's price
public double getPrice() {

return price;

}//end getPrice

//getter method for the record's quantity in stock
public int getQuan() {

return quan;

}//end getQuan

//setter method for the quantity in stock
public void setQuan(int quan) {

this.quan = quan;

}//end setQuan

//getter method for the validity of the record (notifies the user as well)
public boolean getValidity(){

String message = "";

//checks validity of record and constructs a message to the user based on that
if(valid)
message = "Record Successfully Added";
else
message = "Invalid input, record not added";

JOptionPane.showMessageDialog(null, message, "Add Record", JOptionPane.PLAIN_MESSAGE);

return(valid);

}//end getValidity

}//end Record

Published by Chris Chen

Chris is currently attending the University of California, Berkeley seeking an undergraduate's degree in Electrical Engineering Computer Science. He enjoys playing basketball, practicing kendo, hanging out w...  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.