ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 103 Weeks Ago, 2 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 02 May 2017 My Price 13.00

Write a class named RetailItem

1. Write a class named RetailItem that holds data about an item in a retail store, include the following fields:
-description: references a String object that holds a brief description of the item.
-unitsOnHand: an int variable that holds the number of units currently in inventory.

-price: a double variable that holds the item's retail price.
-DISCOUNT: a constant static attribute double and set to 0.20 or 20%

2. Write the following for each field (description, unitsOnHand, price):

Constructor. Accepts arguments for each field
Mutator methods. Stores values in each field.
Accessor methods. Returns values in each field.
applyDiscount() - Computes the new price of the item using the constant (DISCOUNT) as above.
toString() - Displays the description, unitsOnHand, price, and the new price after the discount is applied.

3. Write a separate class named RetailItemDriver (which includes main() )

- Reads in 3 RetailItem objects (this is read in from the "circleData.txt" ) and stores their data..
- Create a getRetailItem() method to read data for the 3 RetailItem objects and the create the objects one at a time while returning the object reference.
- Write a display() method that displays one object at a time, that is display the current state of the object. In the display method, display a new price of the item after the discount is applied using the
applyDiscount() method, one at a time.

---
I'm having trouble reading the data in from a file.  I got a little lost trying to write this Java program.  I have attached my RetailItem.java & RetailItemDriver.java files, as well as the retailItem.txt data file.RetailItem.java

public class RetailItem {
private String description;
private int units;
private double price;
private static final double DISCOUNT = 0.20;
public RetailItem() {
description = "";
units = 0;
price = 0.0;
}
public RetailItem(String description, int unit, double price)
{
this.description = description;
this.units = units;
this.price = price;
}
public void setDescription(String description)
{
this.description = description;
}
public void setPrice(double price)
{
this.price = price;
}
public void setUnits(int units) //Accessor for units on hand
{
this.units = units;
}
public int getUnits() {
return units;
}
public String getDescription() {
return description;
}
public double getPrice() {
return price;
}
public double applyDiscount(double getPrice) {
double amountDiscount = getPrice * DISCOUNT;
return (getPrice - amountDiscount);
}
public String toString() {
String str = "";
str += "Description: " + description;
str += "\nUnits: " + units;
str += "\nPrice: $" + price;
str += "\nPrice after Discount: $" + applyDiscount(price) + "\n";
return str;
}
}//end class

import java.io.*;
import java.util.Scanner;
class RetailItemDriver{
public static void main(String args) throws IOException {
File infile = new File("retailItems.txt");
if(!infile.exists()) {
System.out.println("File not found. Exiting...");
System.exit(0);
}//end find file
String readIn = "";
Scanner scan = new Scanner(infile);
//RetailItem w/ 3 objects
r1 = new RetailItem();
r2 = new RetailItem();
r3 = new RetailItem();
while(scan.hasNext()) {
readIn = scan.next();
//??? I'm so lost
}
//function call to set values
r3.setDescription();
r3.setUnits();
r3.setPrice();
//output data
System.out.println(r1 + "\n" + r2
}//end main + "\n" + r3); public static void displayAll(RetailItem items) {
for(RetailItem item: items)
System.out.println(item);
}
public static RetailItem getRetailObject() {
String des = scan.next();
int unit = scan.nextInt();
double price = scan.nextDouble();
} }//end class

Attachments:

Answers

(11)
Status NEW Posted 02 May 2017 03:05 AM My Price 13.00

-----------

Attachments

file 1493695207-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)