Question
How to edit this code so that it can ignore the percent sign when reading a file. Also, if you could edit the main so
How to edit this code so that it can ignore the percent sign when reading a file. Also, if you could edit the main so that it can read the files without using a filepath, that would be great.
public class Customer {
// Member variables String first_name; String last_name; int guestID; double amountSpent; // Default constructor public Customer() { } // Parameterized custroctor public Customer(String first_name,String last_name,int guestID,double amountSpent) { this.first_name=first_name; this.last_name=last_name; this.guestID=guestID; this.amountSpent=amountSpent; } // Getters and setters public String getFirst_name() { return first_name; } public void setFirst_name(String first_name) { this.first_name = first_name; } public String getLast_name() { return last_name; } public void setLast_name(String last_name) { this.last_name = last_name; } public int getGuestID() { return guestID; } public void setGuestID(int guestID) { this.guestID = guestID; } public double getAmountSpent() { return amountSpent; } public void setAmountSpent(double amountSpent) { this.amountSpent = amountSpent; } }
ublic class PreferredCustomer extends Customer {
// Member variable discount double discountPercentage;
// Default constructor public PreferredCustomer() { super(); }
// Parameterized overloaded constructor // Constructor chaining calling parent class constructor public PreferredCustomer(String first_name, String last_name, int guestID, double amountSpent,double discountPercentage) { super(first_name, last_name, guestID, amountSpent); this.discountPercentage=discountPercentage; // TODO Auto-generated constructor stub }
// Getter and setter public double getDiscountPercentage() { return discountPercentage; }
public void setDiscountPercentage(double discountPercentage) { this.discountPercentage = discountPercentage; }
Main.java
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.io.InputStream; import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) { // TODO Auto-generated method stub
// Files to read files // Put files on your desktop and direct to those files, I couldnt find a way to get around this File preferredFile=new File("C:/Users/bobDesktop/preferred.dat"); File customersFile=new File("C:/Users/bob/Desktop/customer.dat"); File ordersFile=new File("C:/Users/bob/Desktop/orders.dat"); Customer[] customers; PreferredCustomer[] preferredCustomers; //Reading customers file // Readers and important variables BufferedReader br=null; BufferedWriter bw=null; String[] fileData=null; int count=0; // Checking weather the file exists or not if(customersFile.exists() && preferredFile.exists()) { try { br=new BufferedReader(new FileReader(customersFile)); // To count number of customers to declare array size while(br.readLine()!=null) { count++; } br.close(); br=new BufferedReader(new FileReader(customersFile)); // Array size; customers=new Customer[count]; count=0; String line; // Reading to array while((line=br.readLine())!=null) { fileData=line.split(" +"); customers[count]=new Customer(fileData[1],fileData[2],Integer.parseInt(fileData[0]),Double.parseDouble(fileData[3])); count++; } count=0; // Reading preferred customers file br.close(); br=new BufferedReader(new FileReader(preferredFile)); // Reading number of preferred customers while(br.readLine()!=null) { count++; } preferredCustomers=new PreferredCustomer[count]; br.close(); br=new BufferedReader(new FileReader(preferredFile)); count=0; while((line=br.readLine())!=null) { fileData=line.split(" +"); preferredCustomers[count]=new PreferredCustomer(fileData[1],fileData[2],Integer.parseInt(fileData[0]),Double.parseDouble(fileData[3]),Double.parseDouble(fileData[4])); count++; } count=0; int customerID; double radius; double height; double ounces; double ounceprice; double squareinchprice; int quantity; double totalCost; // Processing here based on the order of customers br.close(); br=new BufferedReader(new FileReader(ordersFile)); while((line=br.readLine())!=null) { fileData=line.split(" +"); customerID=Integer.parseInt(fileData[0]); radius=Double.parseDouble(fileData[1]); height=Double.parseDouble(fileData[2]); ounces=Double.parseDouble(fileData[3]); ounceprice=Double.parseDouble(fileData[4]); squareinchprice=Double.parseDouble(fileData[5]); quantity=Integer.parseInt(fileData[6]); totalCost=3.14*radius*radius*height*squareinchprice*ounces*ounceprice; if(totalCost>=150 && totalCost<200) { // Checkig customer existance in customers file for(int i=0;i } It need to read this data and ignore the precent sign in the customer.dat and the preferred.dat: customer.dat: 778234 Minnie Mouse 165.50 5% orders.dat: 26384 2.5 8 36 .25 .35 1 26384 2.5 10 40 .45 0 2 64297 3.25 12.5 64 .15 .03 10 preferred.dat 778234 Minnie Mouse 165.50 5% ALSO, please try to edit the main.java so that it can read the files without using a filepath. Thanks!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started