People class and Printlns
I created the class and set it up to recive the values from the first portion of code. to test to see if the values are recived correctly i set up a print line. while this is not part of my code its just a test to make sure the values are right. When i try to set up the Printlns its asks me to make the name and age variables static. this will not work because they have to change. so how can i set it up to where i can print out the values???
First Part
Code:
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Vector;
public class People
{
enum Letter
{
A(1),J(1),S(1),
B(2),K(2),T(2),
C(3),L(3),U(3),
D(4),M(4),V(4),
E(5),N(5),W(5),
F(6),O(6),X(6),
G(7),P(7),Y(7),
H(8),Q(8),Z(8),
I(9),R(9);
int val;
Letter(int n)
{
this.val = n;
}
public int getValue(){return this.val;}
}
public static String aName;
public static int numberCount;
public static void main(String[] args)
{
ArrayList<int[]> list = new ArrayList<int[]>();
Vector names = new Vector();
System.out.print("Enter names: ");
System.out.print("When finished type done ");
Scanner input = new Scanner(System.in);
while (input.hasNext())
{
String aName = input.next();
if (aName.equalsIgnoreCase("done"))
break;
names.add(aName);
}
Iterator itr = names.iterator();
while(itr.hasNext())
{
String s = (String)itr.next();
char[] ca = s.toCharArray();
int[] temp = new int[ca.length];
int count = 0;
for(char c: ca)
{
temp[count++] = Letter.valueOf(Character.toUpperCase(c)+"").getValue();
}
list.add(temp);
}
int count = 0;
itr = names.iterator();
int numberCount=0;
while(itr.hasNext())
{
String s = (String)itr.next();
System.out.println("Name = "+s+"\n");
int[] temp = list.get(count++);
int letterCount = 0;
for(int i: temp)
{
System.out.print(s.charAt(letterCount++)+" = "+i+" , ");
numberCount =numberCount +i;
}
System.out.println("\n");
Vector bday = new Vector();
System.out.println("lifepath Number: "+ numberCount);
System.out.print("Enter birthday(mmddyyyy): ");
System.out.print("When finished type done ");
while (input.hasNext()) {
String birthDay = input.next();
if (birthDay.equalsIgnoreCase("done"))
break;
bday.add(birthDay);
}
System.out.println("how many birthdays?");
System.out.println(bday.size());
System.out.println("Birthdays");
System.out.println(bday);
Iterator<String> iter = bday.iterator();
int sum = 0;
while(iter.hasNext())
{
String element = iter.next();
sum = Integer.parseInt(element.substring(0,2)) + Integer.parseInt(element.substring(2,4)) + Integer.parseInt(element.substring(4,8));
System.out.println("lifepath Number: "+sum);
sum = 0;
}
}
System.out.println(Info.name+ Info.age);
}
}
Person Class
Code:
public class Info{
//Attributes
String name;{
name = People.aName;
}
int age;{
age= People.numberCount;
}
//Constructor
public void Person(String name, int age){
this.name = name;
this.age = age;
}
/**
* Method that return the name of the person
*/
public String getName(){
return name;
}
public int getBDay(){
return age;
}
}