Untitled
unknown
plain_text
4 years ago
5.8 kB
19
Indexable
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.PrintWriter;
class CPTRusanth {
public static void main(String[] args) throws FileNotFoundException {
OpenSave opensave = new OpenSave();
Management manage = new Management();
opensave.invData();
opensave.cusData();
manage.InvManagement();
}// close main
}// close class
class Inventory { //begin Inventory class
Inventory(int id,double price, int quantity, String description)
{//begin constructor inventory
this.id = id;
this.price = price;
this.quantity = quantity;
this.description = description;
}//end constructor inventory
//attributes
private int id;
private double price;
private int quantity;
private String description;
//setters
public int getId(){
return id;
}
public int getQty(){
return quantity;
}
public double getPrice(){
return price;
}
public String getDesc(){
return description;
}
//getters
public void setId(int pid){
id = pid;
}
public void setQty(int quant){
quantity = quant;
}
public void setPrice(double money){
price = money;
}
public void setDesc(String about){
description = about;
}
} // end inventory class
class Customer { // begin customer class
Customer(int id, String firstName, String lastName, String phoneNumber)
{//begin constructor inventory
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.phoneNumber = phoneNumber;
}//end constructor inventory
//attributes
private int id;
private String firstName;
private String lastName;
private String phoneNumber;
//setters
public int getId(){
return id;
}
public String getfirstName(){
return firstName;
}
public String getlastName(){
return lastName;
}
public String phoneNumber(){
return phoneNumber;
}
//getters
public void setId(int Idenity){
id = Idenity;
}
public void setfirstName(String first){
firstName = first;
}
public void setlastName(String last){
lastName = last;
}
public void setphoneNumber(String numberPhone){
phoneNumber = numberPhone;
}
} // end customer class
class OpenSave {//begin OpenSave class
static ArrayList <Inventory> Inventoryarr = new ArrayList <> ();
static ArrayList <Customer> Customerarr = new ArrayList <> ();
public void invData() throws FileNotFoundException {// begin InvData() method
Scanner uI = new Scanner(System.in);
File inventory = new File("InventoryData.txt");
//Creates an object called fileName to deal with the file defined in its constructor.
Scanner fileContents = new Scanner (inventory); //Contents of fileName are placed in the scanner.
Scanner fileLine = new Scanner(fileContents.nextLine());
while (fileLine.hasNextLine())
{
Inventoryarr.add(new Inventory(fileLine.nextInt(),fileLine.nextDouble(),fileLine.nextInt(),fileLine.nextLine()));
}
} //end InvData () mehtod
public void cusData() throws FileNotFoundException {// begin cusData
Scanner uI = new Scanner(System.in);
int Id = 0;
int x = 0;
while (x == 0) {
System.out.printf("Please Enter your Id: ");
Id = uI.nextInt();
if (Id > 999 && Id < 10000) {
x++;
} else {
System.out.println("\n[<!>] ERROR! [<!>] Please Insure your Id is a 4 Digit Number\n");
}
}
System.out.printf("\nPlease Enter your First Name: ");
String firstName = uI.next();
System.out.printf("\nPlease Enter your Last Name: ");
String lastName = uI.next();
System.out.print("\nPlease Enter Your Phone Number: ");
String phoneNumber = uI.next();
File customerData = new File ("CustomerData.txt");
Scanner diskScanner = new Scanner (customerData);
PrintWriter diskWriter = new PrintWriter("DataTmp.txt");
File fileNameNew = new File ("DataTmp.txt");
String oldFileContents=new String();
while (diskScanner.hasNextLine()) {
oldFileContents= oldFileContents + diskScanner.nextLine()+"\n";
}//end while
diskWriter.println(oldFileContents + Id + " " +firstName+ " " +lastName+ " " +phoneNumber);
diskScanner.close();
diskWriter.close();
customerData.delete();
fileNameNew.renameTo(customerData);
File customer = new File("CustomerData.txt");
Scanner customerContents = new Scanner (customer); //Contents of fileName are placed in the scanner.
Scanner CustomerFileLine = new Scanner(customerContents.nextLine());
while (CustomerFileLine.hasNextLine())
{
Customerarr.add(new Customer(CustomerFileLine.nextInt(),CustomerFileLine.next(),CustomerFileLine.next(),CustomerFileLine.next()));
}
}// end CusData() Method
public static ArrayList<Inventory> getInventory () {
return Inventoryarr;
}
}// end OpenSave
class Management {// begin class InvManagement
public void InvManagement() {//begin Invmanagement
ArrayList <Inventory> Invman = OpenSave.getInventory();
Invman.add(new Inventory(2233,5.55,400,"la"));
System.out.printf(Invman.get(3).getDesc() );
}// close InvManagement
}// end InvManagementEditor is loading...