PROFESSORSPARKIE
Instructor
I have a weird problem in java. I am relatively new to java programming but have a lot of experience in several other languages & and need some guidance.
Below you see the commands to compile and run a java program, I wrote for command batch execution for a class of mine.
It all works on my home system with a beautiful report but on three other systems, at school, I have tested it on it fails as below. All of the systems are set up in almost identical structure with java installed in a JAVA_RUN folder. I take the program & data from computer to computer on a flash drive withe same failure except at home.
G:\JAVA>C:\JAVA_RUN\BIN\JAVAC G:\JAVA\Inv_rpt.java
(no return message)
G:\JAVA>C:\JAVA_RUN\BIN\JAVA G:\JAVA\Inv_rpt
Exception in thread “main” java.lang.NoClassDefFoundError: g:\java\Inv_rpt
I am looking for some guidance to solving this problem ASAP because I am on a deadline.
Here is the program listing:
//********************************************************************
// INVENTORY REPORT PROGRAM IN JAVA Author: Prof. Morris Sparks
//
// DEMONSTRATES THE READING OF A CHARACTER TEXT FILE
// USING A STANDARD INPUT DATA STREAM.
//********************************************************************
// THE INPUT DATA RECORD FORMAT IS:
// ---------------------------------
// part_id from actual input columns 1- 6 start relative 0
// part_desc from actual input columns 7-26 start relative 6
// unit_cost from actual input columns 27-30 start relative 26
// unit_sell from actual input columns 31-34 start relative 30
// on_hand from actual input columns 35-38 start relative 34
// on_order from actual input columns 39-42 start relative 38
// order_point from actual input columns 43-46 start relative 42
//
// THE OUTPUT PRINT RECORD FORMAT IS:
// ----------------------------------
// part_id from input record
// part_desc from input record
// on_hand from input record
// on_order from input record
// order_point from input record
// unit_cost from input record
// unit_sell from input record
// total_cost from calculation on_hand * unit_cost
// total_sell from calculation on_hand * unit_sell
// order_amount from calculation order_point - (on_hand + on_order)
// with selection (on_hand + on_order)/order_point>.50
// profit_ratio from calculation unit_sell / unit_cost
// with selection of < 1.32
//*********************************************************************
import java.io.*;
import java.util.StringTokenizer;
import java.util.Date;
import java.text.DecimalFormat;
//import java.util.Calendar;
public class Inv_rpt
{
//-----------------------------------------------------------------
// Reads data about a store inventory from an input file,
// creating an array of InventoryItem objects, then prints them.
//-----------------------------------------------------------------
public static void main (String[] args)
{
// **********************************************
// * Define the required variables & work areas *
// **********************************************
String Myfile = "\\JAVA\\inv_rpt.txt";
String line;
String part_id, part_desc, unit_cost, unit_sell;
String on_hand, on_order, order_point;
String Print_work, hold;
String work_pad = " ";
int uct, ust, oht, oot, opt, oh, oo, op;
int page_num = 1;
int work_length, work_size;
DecimalFormat fmt1, fmt2, fmt3, fmt4;
float total_cost = 0, total_sell = 0;
float final_cost = 0, final_sell = 0;
float uc, us, profit_ratio, order_amount, per_cent;
float work1, work2, work3, work4, work5;
float page_total_cost = 0, page_total_sell = 0;
float final_total_cost = 0, final_total_sell = 0;
Date current_time;
// set up hex-char strean to printer for landscape mode - 27 38 108 49 79
// set up hex-char strean to printer from landscape mode - 27 38 108 48 79
// byte b1 = 27, b2 = 38, b3 = 108, b4 = 49, b5 = 79;
byte b1 = 0x1B, b2 = 0x26, b3 = 0x6C, b4 = 0x31, b5 = 0x4F;
fmt1 = new DecimalFormat("####");
fmt2 = new DecimalFormat("00.00");
fmt3 = new DecimalFormat("##,###,##0.00");
fmt4 = new DecimalFormat("0.00");
current_time = new Date();
work_size = work_pad.length();
// **********************************************
// * DEFINE & OPEN THE INVENTORY DATA FILE. *
// **********************************************
try
{
FileReader fr = new FileReader (Myfile);
BufferedReader inFile = new BufferedReader (fr);
line = inFile.readLine();
// **********************************************
// * PRINT REPORT HEADINGS ON FIRST PAGE. *
// **********************************************
// System.out.print(b1 + b2 + b3 + b4 + b5);
System.out.print(" ");
System.out.print(" SPARKS CORP.");
System.out.println(" ");
System.out.print(" ");
System.out.print("INVENTORY STATUS REPORT");
System.out.println(" PAGE " + page_num);
System.out.print(" ");
System.out.print(" " + current_time);
System.out.println(" ");
System.out.print ("===================================================");
System.out.println("===================================================");
System.out.print(" PART PART ");
System.out.print(" ON ON ORDER UNIT UNIT");
System.out.println(" TOTAL TOTAL ORDER PROFIT");
System.out.print(" NO DESCRIPTION ");
System.out.print(" HAND ORDER POINT COST SELL");
System.out.println(" COST SELL POINT RATIO");
System.out.print ("===================================================");
System.out.println("===================================================");
// ************************************************
// * LOOP PROCESS TO READ EACH INPUT DATA RECORD. *
// ************************************************
while (line != null)
{
try
{
part_id = line.substring( 0, 6);
part_desc = line.substring( 6,26);
unit_cost = line.substring(26,30);
uct = Integer.parseInt(unit_cost);
work1 = uct;
work1 = work1 / 100;
unit_sell = line.substring(30,34);
ust = Integer.parseInt(unit_sell);
work2 = ust;
work2 = work2 / 100;
on_hand = line.substring(34,38);
oht = Integer.parseInt(on_hand);
work3 = oht;
on_order = line.substring(38,42);
oot = Integer.parseInt(on_order);
work4 = oot;
order_point = line.substring(42,46);
opt = Integer.parseInt(order_point);
work5 = opt;
total_cost = work1 * work3;
page_total_cost = page_total_cost + total_cost;
final_total_cost = final_total_cost + total_cost;
total_sell = work2 * work3;
page_total_sell = page_total_sell + total_sell;
final_total_sell = final_total_sell + total_sell;
final_cost = final_cost + total_cost;
final_sell = final_sell + total_sell;
order_amount = opt - (oht + oot);
per_cent = ((work3 + work4) * 100) / work5;
profit_ratio = work2 / work1 ;
//*********************************************************************
System.out.print(part_id + " ");
System.out.print(part_desc + " ");
Print_work = fmt1.format(oht);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-5+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt1.format(oot);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-5+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt1.format(opt);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-5+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt2.format(uct);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-6+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt2.format(ust);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-6+1,work_size);
System.out.print(Print_work + " ");
//*********************************************************************
Print_work = fmt3.format(total_cost);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
//*********************************************************************
Print_work = fmt3.format(total_sell);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
//*********************************************************************
if (per_cent > 50.0)
{System.out.print(" ");}
else
{Print_work = fmt1.format(order_amount);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-5+1,work_size);
System.out.print(Print_work + " ");
System.out.print(" ");
}
//*********************************************************************
if (profit_ratio < 1.32)
{System.out.print(fmt4.format(profit_ratio) + " ");}
else
{System.out.print(" ");}
//*********************************************************************
System.out.println(" *");
}
catch (NumberFormatException exception)
{
System.out.println ("Error in input. Line ignored:");
System.out.println (line);
}
line = inFile.readLine();
}
//*********************************************************************
// print page totals
System.out.print(" ");
System.out.print("PAGE TOTALS => ");
Print_work = fmt3.format(page_total_cost);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt3.format(page_total_sell);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
System.out.println(" ");
//*********************************************************************
// print final totals
System.out.print(" ");
System.out.print("FINAL TOTALS => ");
Print_work = fmt3.format(final_total_cost);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt3.format(final_total_sell);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
System.out.println(" ");
inFile.close();
}
catch (FileNotFoundException exception)
{
System.out.println ("The file " + Myfile + " was not found.");
}
catch (IOException exception)
{
System.out.println (exception);
}
}
}
Computer thought: I teach a lot of programming so I can learn. You can never learn it all.
Below you see the commands to compile and run a java program, I wrote for command batch execution for a class of mine.
It all works on my home system with a beautiful report but on three other systems, at school, I have tested it on it fails as below. All of the systems are set up in almost identical structure with java installed in a JAVA_RUN folder. I take the program & data from computer to computer on a flash drive withe same failure except at home.
G:\JAVA>C:\JAVA_RUN\BIN\JAVAC G:\JAVA\Inv_rpt.java
(no return message)
G:\JAVA>C:\JAVA_RUN\BIN\JAVA G:\JAVA\Inv_rpt
Exception in thread “main” java.lang.NoClassDefFoundError: g:\java\Inv_rpt
I am looking for some guidance to solving this problem ASAP because I am on a deadline.
Here is the program listing:
//********************************************************************
// INVENTORY REPORT PROGRAM IN JAVA Author: Prof. Morris Sparks
//
// DEMONSTRATES THE READING OF A CHARACTER TEXT FILE
// USING A STANDARD INPUT DATA STREAM.
//********************************************************************
// THE INPUT DATA RECORD FORMAT IS:
// ---------------------------------
// part_id from actual input columns 1- 6 start relative 0
// part_desc from actual input columns 7-26 start relative 6
// unit_cost from actual input columns 27-30 start relative 26
// unit_sell from actual input columns 31-34 start relative 30
// on_hand from actual input columns 35-38 start relative 34
// on_order from actual input columns 39-42 start relative 38
// order_point from actual input columns 43-46 start relative 42
//
// THE OUTPUT PRINT RECORD FORMAT IS:
// ----------------------------------
// part_id from input record
// part_desc from input record
// on_hand from input record
// on_order from input record
// order_point from input record
// unit_cost from input record
// unit_sell from input record
// total_cost from calculation on_hand * unit_cost
// total_sell from calculation on_hand * unit_sell
// order_amount from calculation order_point - (on_hand + on_order)
// with selection (on_hand + on_order)/order_point>.50
// profit_ratio from calculation unit_sell / unit_cost
// with selection of < 1.32
//*********************************************************************
import java.io.*;
import java.util.StringTokenizer;
import java.util.Date;
import java.text.DecimalFormat;
//import java.util.Calendar;
public class Inv_rpt
{
//-----------------------------------------------------------------
// Reads data about a store inventory from an input file,
// creating an array of InventoryItem objects, then prints them.
//-----------------------------------------------------------------
public static void main (String[] args)
{
// **********************************************
// * Define the required variables & work areas *
// **********************************************
String Myfile = "\\JAVA\\inv_rpt.txt";
String line;
String part_id, part_desc, unit_cost, unit_sell;
String on_hand, on_order, order_point;
String Print_work, hold;
String work_pad = " ";
int uct, ust, oht, oot, opt, oh, oo, op;
int page_num = 1;
int work_length, work_size;
DecimalFormat fmt1, fmt2, fmt3, fmt4;
float total_cost = 0, total_sell = 0;
float final_cost = 0, final_sell = 0;
float uc, us, profit_ratio, order_amount, per_cent;
float work1, work2, work3, work4, work5;
float page_total_cost = 0, page_total_sell = 0;
float final_total_cost = 0, final_total_sell = 0;
Date current_time;
// set up hex-char strean to printer for landscape mode - 27 38 108 49 79
// set up hex-char strean to printer from landscape mode - 27 38 108 48 79
// byte b1 = 27, b2 = 38, b3 = 108, b4 = 49, b5 = 79;
byte b1 = 0x1B, b2 = 0x26, b3 = 0x6C, b4 = 0x31, b5 = 0x4F;
fmt1 = new DecimalFormat("####");
fmt2 = new DecimalFormat("00.00");
fmt3 = new DecimalFormat("##,###,##0.00");
fmt4 = new DecimalFormat("0.00");
current_time = new Date();
work_size = work_pad.length();
// **********************************************
// * DEFINE & OPEN THE INVENTORY DATA FILE. *
// **********************************************
try
{
FileReader fr = new FileReader (Myfile);
BufferedReader inFile = new BufferedReader (fr);
line = inFile.readLine();
// **********************************************
// * PRINT REPORT HEADINGS ON FIRST PAGE. *
// **********************************************
// System.out.print(b1 + b2 + b3 + b4 + b5);
System.out.print(" ");
System.out.print(" SPARKS CORP.");
System.out.println(" ");
System.out.print(" ");
System.out.print("INVENTORY STATUS REPORT");
System.out.println(" PAGE " + page_num);
System.out.print(" ");
System.out.print(" " + current_time);
System.out.println(" ");
System.out.print ("===================================================");
System.out.println("===================================================");
System.out.print(" PART PART ");
System.out.print(" ON ON ORDER UNIT UNIT");
System.out.println(" TOTAL TOTAL ORDER PROFIT");
System.out.print(" NO DESCRIPTION ");
System.out.print(" HAND ORDER POINT COST SELL");
System.out.println(" COST SELL POINT RATIO");
System.out.print ("===================================================");
System.out.println("===================================================");
// ************************************************
// * LOOP PROCESS TO READ EACH INPUT DATA RECORD. *
// ************************************************
while (line != null)
{
try
{
part_id = line.substring( 0, 6);
part_desc = line.substring( 6,26);
unit_cost = line.substring(26,30);
uct = Integer.parseInt(unit_cost);
work1 = uct;
work1 = work1 / 100;
unit_sell = line.substring(30,34);
ust = Integer.parseInt(unit_sell);
work2 = ust;
work2 = work2 / 100;
on_hand = line.substring(34,38);
oht = Integer.parseInt(on_hand);
work3 = oht;
on_order = line.substring(38,42);
oot = Integer.parseInt(on_order);
work4 = oot;
order_point = line.substring(42,46);
opt = Integer.parseInt(order_point);
work5 = opt;
total_cost = work1 * work3;
page_total_cost = page_total_cost + total_cost;
final_total_cost = final_total_cost + total_cost;
total_sell = work2 * work3;
page_total_sell = page_total_sell + total_sell;
final_total_sell = final_total_sell + total_sell;
final_cost = final_cost + total_cost;
final_sell = final_sell + total_sell;
order_amount = opt - (oht + oot);
per_cent = ((work3 + work4) * 100) / work5;
profit_ratio = work2 / work1 ;
//*********************************************************************
System.out.print(part_id + " ");
System.out.print(part_desc + " ");
Print_work = fmt1.format(oht);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-5+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt1.format(oot);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-5+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt1.format(opt);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-5+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt2.format(uct);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-6+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt2.format(ust);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-6+1,work_size);
System.out.print(Print_work + " ");
//*********************************************************************
Print_work = fmt3.format(total_cost);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
//*********************************************************************
Print_work = fmt3.format(total_sell);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
//*********************************************************************
if (per_cent > 50.0)
{System.out.print(" ");}
else
{Print_work = fmt1.format(order_amount);
hold = work_pad + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-5+1,work_size);
System.out.print(Print_work + " ");
System.out.print(" ");
}
//*********************************************************************
if (profit_ratio < 1.32)
{System.out.print(fmt4.format(profit_ratio) + " ");}
else
{System.out.print(" ");}
//*********************************************************************
System.out.println(" *");
}
catch (NumberFormatException exception)
{
System.out.println ("Error in input. Line ignored:");
System.out.println (line);
}
line = inFile.readLine();
}
//*********************************************************************
// print page totals
System.out.print(" ");
System.out.print("PAGE TOTALS => ");
Print_work = fmt3.format(page_total_cost);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt3.format(page_total_sell);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
System.out.println(" ");
//*********************************************************************
// print final totals
System.out.print(" ");
System.out.print("FINAL TOTALS => ");
Print_work = fmt3.format(final_total_cost);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
Print_work = fmt3.format(final_total_sell);
hold = work_pad + "$" + Print_work;
work_size = hold.length();
Print_work = hold.substring(work_size-13+1,work_size);
System.out.print(Print_work + " ");
System.out.println(" ");
inFile.close();
}
catch (FileNotFoundException exception)
{
System.out.println ("The file " + Myfile + " was not found.");
}
catch (IOException exception)
{
System.out.println (exception);
}
}
}
Computer thought: I teach a lot of programming so I can learn. You can never learn it all.