Output Not Fully Displaying When Running The Program in Java -
Output Not Fully Displaying When Running The Program in Java -
i using bluej
, reference.
the programme compiles , runs fine.
the problem output not output entire thing.
here current output:
h sanders,harlanddavid 277651 8.72 false s baron,james 368535 310236.0 s moran,blake 123456 260000.0 h bob,billy 654321 15.0 false h smith,will 345612 10.5 true 30 6) remove worker not in list employee not found 7) remove worker first in list h macdonald,ronald 386218 7.8 true 40 h walton,samuel 268517 8.21 false h thomas,david 131313 9.45 true 38 h sanders,harlanddavid 277651 8.72 false s baron,james 368535 310236.0 s moran,blake 123456 260000.0 h bob,billy 654321 15.0 false h smith,will 345612 10.5 true 30 8) find worker middle of list found @ 4 9) find worker not in list found @ -1 10) find weekly salary of worker salaried 5000.0 11) find weekly salary of hourly worker has no overtime allowed [50 hours] 750.0 12) find weekly salary of hourly worker has overtime allowed [50 hours] 630.0 13) find weekly salary of hourly worker has overtime allowed [20 hours] 210.0 14) print sorted list h macdonald,ronald 386218 7.8 true 40 h walton,samuel 268517 8.21 false h thomas,david 131313 9.45 true 38 h sanders,harlanddavid 277651 8.72 false s baron,james 368535 310236.0 s moran,blake 123456 260000.0 h bob,billy 654321 15.0 false h smith,will 345612 10.5 true 30 15) end process
as main class workerapp
shows, output has 3rd more it. instead, output starts in middle of 5) , shows rest without outputting before 5).
import java.io.*; import java.util.*; public class workerapp{ /** * reads infile, runs tests, , prints output. */ public static void main (string args[]){ company company = new company(); try{ scanner reader = new scanner (new file("employeedata.txt")); while(reader.hasnext()){ string line = reader.nextline(); string employee[] = line.split("\\s+"); string sorh = employee[0]; string name = employee[1]; string id = employee[2]; double salary = double.parsedouble(employee[3]); employee e; if (employee[0].equals("s")){ e = new salariedworker(sorh, name, id, salary);} else { boolean overtime = boolean.parseboolean(employee[4]); if(overtime){ int maxhours = integer.parseint(employee[5]); e = new hourlyworker(sorh, name, id, salary, maxhours); } else{ e = new hourlyworker(sorh, name, id, salary); } } company.add(e); } }catch (exception err){ //system.out.println(err); err.printstacktrace(); } //test number 1 system.out.println("1) add together salaried worker"); salariedworker sworker1 = new salariedworker("s", "moran,blake", "123456", 260000); company.add(sworker1); company.print(); //test number 2 system.out.println("2) add together hourly worker has no overtime allowed"); hourlyworker hworker1 = new hourlyworker("h", "bob,billy", "654321", 15); company.add(hworker1); company.print(); //test number 3 system.out.println("3) add together hourly worker has overtime allowed"); hourlyworker hworker2 = new hourlyworker("h", "smith,will", "345612", 10.5, 30); company.add(hworker2); company.print(); //test number 4 system.out.println("4) add together worker in database"); try{ company.add(sworker1); }catch(exception err){ system.out.println(err); system.out.println(); } //test number 5 system.out.println("5) print sorted list"); company.print(); //test number 6 system.out.println("6) remove worker not in list"); company.remove("brooks,phil"); system.out.println(); //test number 7 system.out.println("7) remove worker first in list "); company.remove("washington,george"); company.print(); system.out.println(); //test number 8 system.out.println("8) find worker middle of list"); int index = company.find("baron,james"); system.out.println("found @ "+ index); system.out.println(); //test number 9 system.out.println("9) find worker not in list"); index = company.find("harrison,ford"); system.out.println("found @ "+ index); system.out.println(); //test number 10 system.out.println("10) find weekly salary of worker salaried"); system.out.println(sworker1.findsalary()); system.out.println(); //test number 11 system.out.println("11) find weekly salary of hourly worker has no overtime allowed [50 hours]"); system.out.println(hworker1.findsalary(50)); system.out.println(); //test number 12 system.out.println("12) find weekly salary of hourly worker has overtime allowed [50 hours]"); system.out.println(hworker2.findsalary(50)); system.out.println(); //test number 13 system.out.println("13) find weekly salary of hourly worker has overtime allowed [20 hours]"); system.out.println(hworker2.findsalary(20)); system.out.println(); //test number 14 system.out.println("14) print sorted list"); company.print(); //test number 15 system.out.println("\n15) end process"); } }
if helps, text file reads:
s washington,george 000001 125000 h macdonald,ronald 386218 7.80 true 40 h walton,samuel 268517 8.21 false h thomas,david 131313 9.45 true 38 h sanders,harlanddavid 277651 8.72 false s baron,james 368535 310236
and 1 of major classes, company
:
import java.io.*; import java.util.*; public class company{ private employee[] employeearray; private final int initialcapacity = 7; private int employcount; /** * creates employee array , sets employcount 0. */ public company(){ employeearray = new employee[initialcapacity]; employcount = 0; } /** * finds employee in list. */ public int find(string name){ (int = 0; < employcount; i++){ if (employeearray[i].getname().equals(name)){ homecoming i; } } homecoming -1; } /** * adds employee list. */ public int add(employee employ){ int index; (index = 0; index < employcount; index++){ int result = employeearray[index].getname().compareto(employ.getname()); if(result == 0){ throw new runtimeexception ("the employee not new"); } } if (employeearray.length == employcount){ expand(); } employeearray[index] = employ; employcount++; homecoming index; } /** * removes employee list. */ public void remove(string name){ int index = find(name); if (index == -1){ system.out.println("the employee not found"); return; } (int = index; < employcount - 1; i++){ employeearray[i] = employeearray[i + 1]; } employcount--; } /** * prints list. */ public void print(){ if(employcount == 0){ system.out.println("the list empty"); return; } for(int = 0; < employcount; i++){ system.out.println(employeearray[i]); } } /** * expands list. */ private void expand(){ employee[] newarray = new employee[employeearray.length + initialcapacity]; (int = 0; < employeearray.length; i++){ newarray[i] = employeearray[i]; } employeearray = newarray; } }
thank in advance!
seems if have extend outputted line numbers in bluej as shown here.
"in bluej terminal window go options
, turn on unlimited buffering
. solve problem. may turn on clear screen @ method calls create each programme run on clear screen." - extreme coders
java output bluej
Comments
Post a Comment