Question: Why this 2 programs are not running? public class Stock { private String corporation; private String symbol; private double closing; private int volume; private Date

Why this 2 programs are not running?

public class Stock { private String corporation; private String symbol; private double closing; private int volume; private Date date; private static Date ipo; //constractor public Stock(String corporation, String symbol, String ipo) { this.corporation = corporation; this.symbol = symbol; this.ipo = new Date(ipo); this.closing = 0; this.volume = 0; this.date = null; } public Stock (String corporation, String symbol, String ipo, double closing, int volume, String date) { this(corporation, symbol, ipo); this.closing = closing; this.volume = volume; this.date = new Date(date); } public void setCorporation(String corporation){ this.corporation = corporation; } public void setSymbol(String symbol){ this.symbol = symbol; } public void setIPO(String ipo){ this.ipo = new Date(ipo); } public void setClosing(double closing){ this.closing = closing; } public void setVolume(int volume){ this.volume = volume; } public void setDate(String date){ this.date = new Date(date); } public String getCorporation(){ return this.corporation ; } public String getSymbol(){ return this.symbol; } public static String getIPO(boolean ordered){ return ipo.getDateString (ordered); } public double getClosing(){ return this.closing; } public int getVolume(){ return this.volume; } public String getDate(boolean ordered){ return this.date.getDateString (ordered); } public String toString() { String result=""; result += getCorporation() + "(" + getSymbol() + ") " ; if (date != null){ result += "Transacton: Date: " +getDate(true)+" "; result += "Closing Price: " +getClosing()+" "; result += "Volume Traded: " +getVolume()+" "; } if (ipo != null) result += "IPO Date: " +getIPO(true)+" "; return result; } public enum Weekdays {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday}; private class Date{ private int year; private int month; private int day; private Weekdays weekday; public Date(String date){ String temp; if (date.indexOf("(")>0) date = date.substring(0,date.indexOf("(")); date = date.trim(); temp = date.substring(0,date.indexOf("(")); month = Integer.parseInt(temp); date = date.substring(date.indexOf("(")); temp = date.substring(0,date.indexOf("(")); day = Integer.parseInt(temp); date = date.substring(date.indexOf("(")); year = Integer.parseInt(date); setWeekday(month,day, year); }

public void setWeekday(int month, int day, int year) { int wdValue = 0; int m; if (month > 2) { m = month - 2; } else { m = month + 10; year--; } int d = year%100; int c = year/100; wdValue = (day + (13*m-1)/5 + d + d/4 + c/4 - 2*c); wdValue = wdValue%7; switch (wdValue){ case 0: weekday = Weekdays.Sunday; break; case 1: weekday = Weekdays.Monday; break; case 2: weekday = Weekdays.Tuesday; break; case 3: weekday = Weekdays.Wednesday; break; case 4: weekday = Weekdays.Thursday; break; case 5: weekday = Weekdays.Friday; break; case 6: weekday = Weekdays.Saturday; } } public String getDateString(boolean ordered){ String dateStr=""; if (ordered) dateStr = String.format("%04d/%02d/%02d (%s)", year, month,day,weekday.toString()); else dateStr = String.format("%02d/%02d/%04d (%s)", year, month,day,weekday.toString()); return dateStr; } public String toString(){ return getDateString(true); } }

}

import java.util.Scanner; public class NewTechCorp { public static void main(String[] args) { String corp, sym, ipoDate, date; int volume; double price; Scanner key = new Scanner(System.in); System.out.print("What is the name of the corporation?"); corp = key.nextLine(); System.out.print("What is the stock market symbol for" + corp +"?"); sym = key.nextLine(); System.out.print("What was the date (mm/dd/yyyy) of thr initial public stock offering?"); ipoDate = key.nextLine(); Stock ipo = new Stock(corp, sym, ipoDate); System.out.println("IPO: " + ipo +"n "); //Trade 1 System.out.print("What was the date (mm/dd/yyyy) of the first trade?"); date = key.nextLine(); System.out.print("What was the closing price of "+sym+" on "+date+"?"); price = Double.parseDouble(key.nextLine()); System.out.print("What was the trading volume of "+sym+" on "+date+"?"); volume = Integer.parseInt(key.nextLine()); Stock trade1 = new Stock(corp, sym, ipoDate, price, volume, date); //Trade 2 System.out.print("What was the date (mm/dd/yyyy) of the second trade?"); date = key.nextLine(); System.out.print("What was the closing price of "+sym+" on "+date+"?"); price = Double.parseDouble(key.nextLine()); System.out.print("What was the trading volume of "+sym+" on "+date+"?"); volume = Integer.parseInt(key.nextLine()); Stock trade2 = new Stock(corp, sym, ipoDate, price, volume, date); //Trade 3 System.out.print("What was the date (mm/dd/yyyy) of the third trade?"); date = key.nextLine(); System.out.print("What was the closing price of "+sym+" on "+date+"?"); price = Double.parseDouble(key.nextLine()); System.out.print("What was the trading volume of "+sym+" on "+date+"?"); volume = Integer.parseInt(key.nextLine()); Stock trade3 = new Stock(corp, sym, ipoDate, price, volume, date); //output the three trades using toString() automatically to print the object contents System.out.println("------------------Trade 1---------------------"); System.out.println(trade1); System.out.println("------------------Trade 2---------------------"); System.out.println(trade2); System.out.println("------------------Trade3---------------------"); System.out.println(trade3); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!