Lecture notes for the Introduction to Computer Science II by James Tam | Return to the course web page |
char data = 'A';
System.out.println(data + " " + (byte) data);
data++;
System.out.println(data + " " + (byte) data);
data = (char) ~data;
System.out.println(data + " " + (byte) data);
byte num = 127;
num++;
System.out.println(num);
For the above statements explain why the program produces the output that it does. (Hint: some source material could come from the sections on numeric representations, the introduction to Java programming as well the UNIX manual pages on ASCII representations).
The requirements for this assignment are identical to the ones for Assignment 1, except that you must now employ two classes: 1) A "Driver" class (that contains the 'main' method) 2) Another class, "Fun", that implements the features described in the previous assignment. In Assignment 1 it was likely that your main method contained all of your program code. For the second assignment it is likely that your main method will now just instantiate an instance of class Fun and perhaps include a method call or two to an instance of class Fun:
public class Driver
{
public static void main (String [] args)
{
Fun generator = new Fun ();
generator.start();
}
}With this assignment the main loop for the program and the calls to the different methods of class Fun are contained in the "start" method of class Fun.
public class Fun
{
public final int AGE_QUOTIENT = 100;
public final int ADDRESS_QUOTIENT = 100;
: :
private Scanner aScanner = new Scanner (System.in);
public int calculateAddressModifier (int addressNumber)
{
int addressModifier;
: :
return addressModifier;
}
public int determineFundex (int ageModifier,
int addressModifier,
int petModifier)
{
int fundex;
: :
return fundex;
}
public int getAddress ()
{
int address;
: :
return address;
}
: : :
public char getPet ()
{
String pet;
char petType;
// Read the user input as a String of length 1, the first character of the String to determines the pet type of the user.
: : :
petType = pet.charAt(0);
return petType;
}
public void intro ()
{
: :
}
public void start ()
{
introduction ();
// The loop that asks the user if they want to re-run the program will be in method 'start' and it will encompass all/most of
}
// the calls to the methods of class Fun.
Method name |
Inputs |
Return Type |
Description |
Introduction |
None |
Void |
Provides a brief overview of what the program does. |
calculateAddressModifier |
Int |
Int |
Given the address number, it will determine and return the address modifier. It should also deal with an invalid address. |
calculateAgeModifier |
Int |
Int |
Given the age, it will determine and return the age modifier. It should also deal with an invalid age. |
determineFundex |
Int, Int, Int |
Int |
Given the information for the 3 modifiers, this method will determine and return the numeric fundex. |
determinePetModifier |
Char |
Int |
Given the pet information, it will determine and return the pet modifier. It should check that the pet information is one of the allowable types. |
displayFundex |
Int |
Void |
Given the numeric fundex, this method will determine and display the fundex category. It should check for fundex values outside of the allowable ranges (too high or low). |
getAddress |
None |
Int |
Prompt for and get as input the address number. |
getAge | None | Int | Prompt for and get as input the age. |
getPet | None | Char | Prompt for and get as input the pet information. |
start | None | None | Makes the variable declarations for the necessary variables, calls the other methods, determines if the program re-runs itself. |