Привет, ребята, я создал два разных класса, которые являются классом shopitem и классом shopuser. Мне нужно создать два метода: hirerequest() и processhirerequest: ниже моя попытка кодирования, которая был несовместим и не скомпилирован:java hirerequest() и методы processhirerequest()
/**
* Accessor method hireRequest
*
* @return shopuser and shopitem object's
*/
public String hireRequest()
{
return shop item object;
return shop user object;
}
/**
* Accessor method processHireRequest
*
* @return name
*/
public String processHireRequest()
{
return hireRequest;
}
это код выше, правильный и должен ли он работать?
любые ответы или помощь были бы весьма полезными.
код Shopitem:
public abstract class ShopItem
{
private ArrayList<Tool> toolsList;
Shop shop;
private int toolCount;
private String toolName;
private int power;
private int timesBorrowed;
private boolean rechargeable;
private int itemCode;
private int cost;
private double weight;
private boolean onLoan;
private static JFrame myFrame;
private String Tool;
private String ElectricTool;
private String HandTool;
private String Perishable;
private String Workwear;
private boolean ShopUserID;
public void ReadToolData (String data) throws FileNotFoundException,NoSuchElementException
{
// shows the directory of the text file
File file = new File("E:/LEWIS BC 2/java project/project 1 part 3/ElectricToolData.txt");
Scanner S = new Scanner (file);
// prints out the data
System.out.println();
// prints out the
System.out.println();
S.nextLine();
S.nextLine();
S.nextLine();
S.nextLine();
S.nextInt();
}
/**
* Creates a collection of tools to be stored in a tool list
*/
public ShopItem(String toolName, int power,int timesborrowed,boolean rechargeable,int itemCode,int cost,double weight,int toolcount,boolean onLoan,boolean ShopUserID)
{
toolsList = new ArrayList<Tool>();
toolName = new String();
power = 0;
timesborrowed = 0;
rechargeable = true;
itemCode = 001;
cost = 100;
weight = 0.0;
toolCount = 0;
onLoan = true;
// ShopUserID = null;
}
/**
* Default Constructor for Testing
*/
public ShopItem()
{
// initialise instance variables
toolName = "Spanner";
itemCode = 001;
timesBorrowed = 0;
power = 0;
onLoan = true;
rechargeable = true;
itemCode = 001;
cost = 100;
weight = 0.0;
toolCount = 0;
}
/**
* Reads ElectronicToolData data from a text file
*
* @param <code>fileName</code> a <code>String</code>, the name of the
* text file in which the data is stored.
*
* @throws FileNotFoundException
*/
public void readData(String fileName) throws FileNotFoundException
{
//
// while (there are more lines in the data file)
// {
// lineOfText = next line from scanner
// if(line starts with //)
// { // ignore }
// else if(line is blank)
// { // ignore }
// else
// { code to deal with a line of ElectricTool data }
// }
myFrame = new JFrame("Testing FileDialog Box");
myFrame.setBounds(200, 200, 800, 500);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setVisible(true);
{
FileDialog fileBox = new FileDialog(myFrame,
"Open", FileDialog.LOAD);
fileBox.setVisible(true);
}
{
File dataFile = new File(fileName);
Scanner scanner = new Scanner(dataFile);
while(scanner.hasNext())
{
String info = scanner.nextLine();
System.out.println(info);
}
scanner.close();
}
}
/**
* Default Constructor for Testing
*/
public void extractTokens(Scanner scanner) throws IOException, FileNotFoundException
{
// extracts tokens from the scanner
File text = new File("E:/LEWIS BC 2/java project/project 1 part 3/items_all.txt");
String ToolName = scanner.next();
int itemCode = scanner.nextInt();
int cost = scanner.nextInt();
int weight = scanner.nextInt();
int timesBorrowed = scanner.nextInt();
boolean rechargeable = scanner.nextBoolean();
boolean onLoan = scanner.nextBoolean();
extractTokens(scanner);
// System.out.println(parts.get(1)); // "en"
}
/**
* Creates a tool collection and populates it using data from a text file
*/
public ShopItem(String fileName) throws FileNotFoundException
{
this();
ReadToolData(fileName);
}
/**
* Adds a tool to the collection
*
* @param <code>tool</code> an <code>Tool</code> object, the tool to be added
*/
public void storeTool(Tool tool)
{
toolsList.add(tool);
}
/**
* Shows a tool by printing it's details. This includes
* it's position in the collection.
*
* @param <code>listPosition</code> the position of the animal
*/
public void showTool(int listPosition)
{
Tool tool;
if(listPosition < toolsList.size())
{
tool = toolsList.get(listPosition);
System.out.println("Position " + listPosition + ": " + tool);
}
}
/**
* Returns how many tools are stored in the collection
*
* @return the number of tools in the collection
*/
public int numberOfToolls()
{
return toolsList.size();
}
/**
* Displays all the tools in the collection
*
*/
public void showAllTools()
{
System.out.println("Shop");
System.out.println("===");
int listPosition = 0;
while(listPosition<toolsList.size()) //for each loop
{
showTool(listPosition);
listPosition++;
}
System.out.println(listPosition + " tools shown"); // display number of tools shown
}
public void printAllDetails()
{
// The name of the file to open.
String fileName = "ElectricToolDataNew.txt";
// This will reference one line at a time
String line = null;
try {
// FileReader reads text files in the default encoding.
FileReader fileReader =
new FileReader(fileName);
// Always wrap FileReader in BufferedReader.
BufferedReader bufferedReader =
new BufferedReader(fileReader);
while((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
// Always close files.
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
// Or we could just do this:
// ex.printStackTrace();
}
}
}
код Shopuser
public abstract class ShopUser
{
private String name;
Shop shop;
private String shopUserID;
private String itemCode;
/**
* Constructor for objects of class ShopUser
*/
public ShopUser(String name, String shopUserID)
{
this.name = name;
this.shopUserID = shopUserID;
this.itemCode = itemCode;
}
// /**
// * Accessor method hireRequest
// *
// * @return shopuser and shopitem object's
// */
// public void hireRequest(String shopItem, String shopUser)
// {
// return shopItem;
// return shopUser;
// }
/**
* Accessor method getName
*
* @return name
*/
public String getName()
{
return name;
}
/**
* Accessor method getShopUserID
*
* @return shopUserID
*/
public String getShopUserID()
{
return shopUserID;
}
/**
* Method extractTokens that extracts tokens for a ShopUser object from a
* line of text that has been passed to the scanner
*
*/
public void extractTokens(Scanner scanner)
{
// data is name, shopUserID
name = scanner.next();
shopUserID = scanner.next();
}
/**
* Accessor method printDetails
*/
public void printDetails()
{
System.out.printf("%-15s %s %n", "name:", name);
System.out.printf("%-15s %s %n", "shop user ID:", shopUserID);
}
}
Это, безусловно, не скомпилируется. Не могли бы вы опубликовать код для самих классов, чтобы мы могли лучше понять, что происходит? –
отредактированный пост, чтобы включить код – user3289955
, чего вы хотите достичь? –