This is Calculator.m in view mode; [Download] [Up]
/* Generated by Interface Builder */ /* Modified by Eric Tremblay */ #import <AppKit/NSForm.h> #import "Calculator.h" @implementation Calculator #define CANADA 0 #define USA 1 int Country = USA; // Default country int dummy; // Use as you wish - init { [super init]; return self; } - (void)applicationDidFinishLaunching:(NSNotification *)notification; // This method is executed right after the application was initilized but // before the application receives it's first event. { // This will reset/display the proper default // rates for the country [self getDefaults:self]; } - (void)calculate:sender { [inputForm selectTextAtIndex:0]; { // Declare variables float CANADAdollar; float BritainPound; float FranceFranc; float GermanyMark; float ItalyLira; float JapanYen; float MexicoPeso; float SwitzerlandFranc; float GreeceDrachma; float OtherCurrency; // Do the conversion CANADAdollar = ([inputForm floatValue]/[canadarate floatValue]); BritainPound = ([inputForm floatValue]/[britainrate floatValue]); FranceFranc = ([inputForm floatValue]/[francerate floatValue]); GermanyMark = ([inputForm floatValue]/[germanyrate floatValue]); ItalyLira = ([inputForm floatValue]/[italyrate floatValue]); JapanYen = ([inputForm floatValue]/[japanrate floatValue]); MexicoPeso = ([inputForm floatValue]/[mexicorate floatValue]); SwitzerlandFranc = ([inputForm floatValue]/[switzerlandrate floatValue]); GreeceDrachma = ([inputForm floatValue]/[greecerate floatValue]); OtherCurrency = ([inputForm floatValue]/[otherrate floatValue]); // Display the result [[outputForm cellAtIndex:0] setFloatValue:CANADAdollar]; [[outputForm cellAtIndex:1] setFloatValue:BritainPound]; [[outputForm cellAtIndex:2] setFloatValue:FranceFranc]; [[outputForm cellAtIndex:3] setFloatValue:GermanyMark]; [[outputForm cellAtIndex:4] setFloatValue:ItalyLira]; [[outputForm cellAtIndex:5] setFloatValue:JapanYen]; [[outputForm cellAtIndex:6] setFloatValue:MexicoPeso]; [[outputForm cellAtIndex:7] setFloatValue:SwitzerlandFranc]; [[outputForm cellAtIndex:8] setFloatValue:GreeceDrachma]; [[outputForm cellAtIndex:9] setFloatValue:OtherCurrency]; } } - (void)getDefaults:sender // This method sets and displays all the values depending on what // Country was selected { if (Country == CANADA) { // open the If canada // Default values for Today's rates (April 25, 96) float CANADAdollar=1.3621; // In this case the CANADAdollar is a US dollar float BritainPound=2.0645; float FranceFranc=0.2654; float GermanyMark=0.8966; float ItalyLira=0.000878; float JapanYen=0.01278; float MexicoPeso=0.1838; float SwitzerlandFranc=1.1078; float GreeceDrachma=0.00562; float OtherCurrency=2; // This assigns the default values in their proper // form in the Today's Rates panel [canadarate setFloatValue:CANADAdollar]; [britainrate setFloatValue:BritainPound]; [francerate setFloatValue:FranceFranc]; [germanyrate setFloatValue:GermanyMark]; [italyrate setFloatValue:ItalyLira]; [japanrate setFloatValue:JapanYen]; [mexicorate setFloatValue:MexicoPeso]; [switzerlandrate setFloatValue:SwitzerlandFranc]; [greecerate setFloatValue:GreeceDrachma]; [otherrate setFloatValue:OtherCurrency]; // This displays the default values in their // proper form in the Today's Rates panel [canadarate display]; [britainrate display]; [francerate display]; [germanyrate display]; [italyrate display]; [japanrate display]; [mexicorate display]; [switzerlandrate display]; [greecerate display]; [otherrate display]; } // close the if canada if (Country == USA) { // open the If usa // Default values for Today's rates (April 25,96) // The rates below are for one american dollar in foreign currency // Example one US dollar equals = 106.60 Japanese Yen float CANADAdollar=0.73287; float BritainPound=1.5153; float FranceFranc=0.19450; float GermanyMark=0.65671; float ItalyLira=0.0006449; float JapanYen=0.009381; float MexicoPeso=0.1349; float SwitzerlandFranc=0.81142; float GreeceDrachma=0.004134; float OtherCurrency=2; // This assigns the default values in their // proper form in the Today's Rates panel [canadarate setFloatValue:CANADAdollar]; [britainrate setFloatValue:BritainPound]; [francerate setFloatValue:FranceFranc]; [germanyrate setFloatValue:GermanyMark]; [italyrate setFloatValue:ItalyLira]; [japanrate setFloatValue:JapanYen]; [mexicorate setFloatValue:MexicoPeso]; [switzerlandrate setFloatValue:SwitzerlandFranc]; [greecerate setFloatValue:GreeceDrachma]; [otherrate setFloatValue:OtherCurrency]; // Changes the labels in the Currency Converter // panel and in the Today's rates // panel when the COUNTRY is set to USA. // Changes the label in Currency Converter panel [[inputForm cellAtIndex:0] setTitle:@"U.S. Dollar :"]; // Changes the label in Currency Converter panel [[outputForm cellAtIndex:0] setTitle:@"Canada:"]; // Changes the label in the Today's rates panel [[canadarate cellAtIndex:0] setTitle:@"Canada:"]; [inputForm display]; [outputForm display]; [canadarate display]; } } - (void)setCanada:sender // This method changes the Country to CANADA and re-labels the panels { // Sets Country to Canada Country = CANADA; // Changes the labels to be used by a Canadian. [[inputForm cellAtIndex:0] setTitle:@"Canadian Dollar:"]; [[outputForm cellAtIndex:0] setTitle:@" U.S.A. :"]; [[canadarate cellAtIndex:0] setTitle:@" U.S.A. :"]; [inputForm display]; [outputForm display]; [canadarate display]; [self getDefaults:sender]; } - (void)setUSA:sender // This method changes the Country to USA and re-lables the panels { Country = USA; // Sets Country to USA // Changes the labels to be use by an American. [[inputForm cellAtIndex:0] setTitle:@"U.S. Dollar:"]; [[outputForm cellAtIndex:0] setTitle:@"Canada:"]; [[canadarate cellAtIndex:0] setTitle:@"Canada:"]; [inputForm display]; [outputForm display]; [canadarate display]; [self getDefaults:sender]; } - (void)findRate:sender // This method will find the exchange rate. When given X number // of one currency and X number of another currency { float findRate; // number variable // Calculate the exchange rate findRate = ([firstCurrency floatValue]/[anotherCurrency floatValue]); // Sets the value for the number findRate in the // "exchange is:" form in the FindRate panel [findRateOutput setFloatValue:findRate]; // Displays the result in the "exchange is:" form in // the FindRate panel [findRateOutput display]; } - (void)findValue:sender // This method will find the value of a currency when given // X number of currency and the exchange rate of this currency. { float findValue; // number variable // Calculate the value findValue = ([youHave floatValue]*[valueRate floatValue]); // Sets the value for the number findValue in the // "value is:" form in the findValue panel [findValueOutput setFloatValue:findValue]; // Displays the results in the "value is:" form in // the findValue panel [findValueOutput display]; } - (void)closeInfo:sender // This method closes the Info panel and opens // and displays the MoreInfo panel { [Info performClose:sender]; // This closes the Info panel [MoreInfo orderFront:sender]; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.