Hello, I am currently doing an assignment where i was given 3 java codes that was similarly to my assignment. I changed those codes to fit my needs and i was wondering if anyone had any better ideas that i can do with my code.
We had to make a .txt file that bascially defined a game you put in .
We had to include price, manufacturer, quantity, discount price, discount quantity, then two other programs to read and pull up the .txt file.
So.... here is my code thus far , I am open to suggestions to include more things in this code to better define the game. Also, I was wondering why the .txt file when i create it it reads a bunch of weird characters for instance "¬í sr EmployeeÔ½ªÿŸˆ; D QOHD QOH2I idNumD priceD price2L namet Ljava/lang/String;L name2q ~ L name3q ~ xp@. @. @N @K€ t Lawlst Lawlst C" this was the file it made when i viewed it from notepad using Lawls as game name and manufacturer just for example. I thought it would just list the names, prices, quantities in the txt file. If someone could explain this to me that would be cool.
import java.io.*; public class Employee implements Serializable { int idNum; String name; String name2; String name3; double price; double price2; double QOH; double QOH2; public Employee(int num, String name, String name2, String name3, double price, double price2, double QOH, double QOH2) { idNum = num; this.name = name; this.name2 = name2; this.name3 = name3; this.price = price; this.price2 = price2; this.QOH = QOH; this.QOH2 = QOH2; } public void display() { System.out.println("serial # " + idNum ); System.out.println(" Game name:" + name); System.out.println(" Manufacturer/publisher: " + name2); System.out.println(" Original price: " + price ); System.out.println(" Quantity: " + QOH ); System.out.println(" Discounted price: " + price2); System.out.println( " Quantity: " + QOH2); System.out.println(" Game rating: " + name3); } }import java.io.*; import java.util.*; public class CreateEmployeeObjectFile { public static void main(String[] args) throws IOException { ObjectOutputStream output = new ObjectOutputStream (new FileOutputStream("game.txt")); Employee emp; int num = 0; final int QUIT = 1337; String name; String name2; String name3; double price; double QOH; double price2; double QOH2; Scanner in = new Scanner(System.in); System.out.print("Assign the games serial number: " + QUIT + " to quit "); num = in.nextInt(); while(num != QUIT) { System.out.print("Enter the game name: "); name = in.next(); System.out.print("Enter the game manufacturer/publisher: "); name2 = in.next(); System.out.print("Please type the rating of the game (C,E,E+,T,M,Ao,RP): "); name3 = in.next(); System.out.print("Enter the price of the game: "); price = in.nextDouble(); System.out.print("Enter how many are available in stock: "); QOH = in.nextDouble(); System.out.print("Enter the discounted price of the game: "); price2 = in.nextDouble(); System.out.print("Enter how many are available in stock discounted: "); QOH2 = in.nextDouble(); emp = new Employee(num, name, name2, name3, price, price2, QOH, QOH2); output.writeObject(emp); System.out.print("Assign the game a number: " + QUIT + " to quit "); num = in.nextInt(); } output.close(); } }import java.io.*; public class ReadEmployeeObjectFile { public static void main(String[] args) throws IOException, ClassNotFoundException { ObjectInputStream in = new ObjectInputStream (new FileInputStream("Game.txt")); Employee emp; try { while(true) { emp = (Employee)in.readObject(); emp.display(); } } catch(EOFException e) { in.close(); } } }