473,473 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need some help getting started with my assigment...

6 New Member
Part one of mye assignment is:

The method must be declared public static, accept a string as a parameter, and return a string. The method receives a name on the form "Firstname [Middlename(s)] Lastname" and should return the same name on the form "Lastname, FirstName Middlename(s)". The method must additionally correct lowercase/uppercase errors and return names with only the first letter of each part in uppercase.

Example: The input "Per petTer Pettersen" must be returned as "Pettersen, Per Petter".
I've started with this, but don't know if it's the right start at all..
I'm VERY new to Java..

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class NameUtil {
  3.  
  4.     public static String normalize(String String){
  5.  
  6.  
  7.         return String;
  8.     }
  9.  
  10.  
  11. }
  12.  
Jan 31 '07 #1
8 1761
Pinko
6 New Member
Part two of my assignment

Person class
Create the class Person in package oving2 with the following fields:
public String name
The name field holds the person's name.
public Person mother
The mother field holds a reference to the person's mother.
public Person father
The father field holds a reference to the person's father.
public Person[] children
The children field holds a reference to an array of the person's children.

This one is ok I think...
Expand|Select|Wrap|Line Numbers
  1. public class Person {
  2.     public String name;
  3.     public Person mother;
  4.     public Person father;
  5.     public Person[]children;
Part 2.2: The Royal Family
Implement the following method in the Person class:
public static Person createRoyalFamily()
This method should create an object graph corresponding to the royal family descending from King Harald and Queen Sonja.

The royal family consists of Harald, Sonja, their children Haakon and Martha. Haakon has two children with Mette-Marit named Ingrid Alexandra and Sverre Magnus, and Martha has two children with Ari named Maud Angelica and Leah Isadora.

The createRoyalFamily method must create Person objects corresponding to all member of the Royal family, and correctly set their name, mother, father, and children fields. Finally, the Person object corresponding to King Harald must be returned.

Note that the createRoyalFamily method must be declared static, since it will be called without any reference to any Person object.

Part 2.3: Family relations
Implement the following methods in the Person class:
public boolean isMotherOf(Person)
a method returns whether this Person is the mother of the Person given as parameter.
public boolean isFatherOf(Person)
a method returns whether this Person is the father of the Person given as parameter.
public boolean isSiblingOf(Person)
a method returns whether this Person is a sibling of the Person given as parameter.
public boolean isHalfSiblingOf(Person)
a method returns whether this Person is a half sibling of the Person given as parameter. A person is another person's half sibling if they have the same mother or father but not both.

Would be nice with som tips and hints on the different parts of this one..
Jan 31 '07 #2
Pinko
6 New Member
Par three:

Create a class named Card with the following fields (variables) and method:
public String suit

holds a String of either "S", "H", "D", or "C" (Spades, Hearts, Diamonds, or Clubs).

public int face

holds an integer number in the range 1-13.
public String toString()


a method that takes no parameters and returns a string consisting of the suit and face of the card, eg. "S2", "H3", or "C5". This method is convenient for printing out a card, e.g. using System.out.println(card).

I've started with this:
Expand|Select|Wrap|Line Numbers
  1. public class Card {
  2.     public String suit;
  3.         String suit1 = new String ("S");
  4.         String suit2 = new String ("H");
  5.         String suit3 = new String ("D");
  6.         String suit4 = new String ("C");
  7.     public int face;
  8.  
  9.  
  10.     public String toString();
  11. }
  12.  
  13.  

Part 3.2: A deck of cards

Create a class named CardDeck with the following field and methods:
public Card[] cards
an array that holds references to 52 different cards
public void buildDeck()
a method that builds a correct deck of cards (in the cards array) with the following order: 1-13 of spades, 1-13 of hearts, 1-13 of diamonds, and finally 1-13 of clubs.
public Card getCard(int)
a method that takes an int as a parameter and returns the card at the given index in the card array.

Part 3.3: Shuffling and dealing of cards
Implement the following methods in the CardDeck class:
public void shuffle()
a method that shuffles the cards in the cards array, returns nothing.
public Card[] deal(int)
a method that deals a number of cards from the top of the deck (takes an int as a parameter and returns an array of cards). If called several times the method continues to deal from the same deck of cards until the deck is empty. Dealing should be implemented by returning elements from the array, and you need to keep track of what cards that have been dealt by the use of a counter. If there is not enough cards in the deck, or if the deck is empty, the method should return an empty array of cards.
public int getCardCount()
a method that returns the number of cards left in the deck. E.g. if 5 cards are dealt, it should return 47.

As I've said in post 1, I really am new to Java, and I need all the help I can get...
Jan 31 '07 #3
Ganon11
3,652 Recognized Expert Specialist
What work have you done so far? What code do you have? If you have no code, what are your ideas about the problem?
Jan 31 '07 #4
Pinko
6 New Member
What work have you done so far? What code do you have? If you have no code, what are your ideas about the problem?
Well, that's the problem... I don't have more than the small fractions of code I've put in my resent posts..
I really don't know where to start...
I could need som pointers to where I should start..
Jan 31 '07 #5
r035198x
13,262 MVP
Part one of mye assignment is:

The method must be declared public static, accept a string as a parameter, and return a string. The method receives a name on the form "Firstname [Middlename(s)] Lastname" and should return the same name on the form "Lastname, FirstName Middlename(s)". The method must additionally correct lowercase/uppercase errors and return names with only the first letter of each part in uppercase.

Example: The input "Per petTer Pettersen" must be returned as "Pettersen, Per Petter".
I've started with this, but don't know if it's the right start at all..
I'm VERY new to Java..

Expand|Select|Wrap|Line Numbers
  1.  
  2. public class NameUtil {
  3.  
  4.     public static String normalize(String String){
  5.  
  6.  
  7.         return String;
  8.     }
  9.  
  10.  
  11. }
  12.  
One part at a time.

Start by splitting the name into an array using the string.split method e.g

Expand|Select|Wrap|Line Numbers
  1.  String s = "r0 35 19  8x"; 
  2. String[] name = s.split(" ");
  3.  
Splits s on " "(space) into an array.

You should now be able to see how to complete it.
Feb 1 '07 #6
Pinko
6 New Member
One part at a time.

Start by splitting the name into an array using the string.split method e.g

Expand|Select|Wrap|Line Numbers
  1.  String s = "r0 35 19  8x"; 
  2. String[] name = s.split(" ");
  3.  
Splits s on " "(space) into an array.

You should now be able to see how to complete it.
I've done this now:
Expand|Select|Wrap|Line Numbers
  1. public class NameUtil {
  2.  
  3.     public static String normalize(String string){
  4.  
  5.         String[] name = string.split(" ");
  6.         String capital = name[name.length-1].substring(0, 1).toUpperCase();
  7.         String rest =name[name.length-1].substring(1).toLowerCase();
  8.         String done = "";
  9.         for(int i=0; i<name.length-1; i++){
  10.             String fo = name[i].substring(0, 1).toUpperCase();
  11.             String re =name[i].substring(1).toLowerCase();
  12.             done = done + " " + fo + re;
  13.         }
  14.         done = capital + rest + "," + done;
  15.         return done;
  16.     }
  17.  
  18.  
  19. }
  20.  
Feb 2 '07 #7
r035198x
13,262 MVP
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. public class Test2 {
  4.  public static void main(String[] args) {
  5.  
  6.   System.out.println(normalize(\"Per petTer Pettersen\"));
  7.  }
  8.  public static String normalize(String string) {
  9.  
  10.   String[] name = string.split(\" \"); 
  11.  
  12.   //proper case everything
  13.  
  14.   for(int i = 0; i < name.length;i++) {
  15.    name[i] = name[i].toLowerCase();
  16.    name[i] = upperFirstChar(name[i]);
  17.   }
  18.  
  19.   //now get the first name and lastname.
  20.  
  21.   String firstName = name[0];
  22.  
  23.   String lastName = name[name.length - 1];
  24.  
  25.   String middleNames = \"\";
  26.   for(int i = 1; i < (name.length - 1); i++) {
  27.    middleNames = middleNames + \" \"+ name[i];
  28.   }
  29.   return lastName + \" \" + firstName + \" \" + middleNames;
  30.  
  31.  
  32.  
  33.  }
  34.  public static String upperFirstChar(String word) {
  35.   char c = word.charAt(0);
  36.   String s = \"\"+c;
  37.   s = s.toUpperCase();
  38.   s = s + word.substring(1, word.length());
  39.   return s;
  40.  }
  41.  
  42. }
  43.  
  44.  


P.S at this rate you won\'t finish the rest of the assignments.
Feb 2 '07 #8
Pinko
6 New Member
I got some help from a classmate this weekend, so I got my assignment done in due time. Thank you for helping though
Feb 5 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Y2KYZFR1 | last post by:
need some help getting started, it is just a "little" confusing on where to actually start. I want to write a turn based board game using Twisted as the networking layer. I just need a kind of...
2
by: yopwojtek | last post by:
Hello All, i know from some tutorials, that copy constructor and assigment operator is not inherited from base to derived class. i think it make sense but i wrote a little example: class Base {...
2
by: Rick Shaw | last post by:
Hi. I am just getting started with C# and I need a lot of help. Can anyone here show me a sample database application written in C#? I figure that I learn better looking at actual codes and...
6
by: Jack Duijf | last post by:
Hello, I am looking for a person in The Netherlands that is willing to help me getting started with Vb.net. Please send a message to jack@aicn.nl if you can help me getting started with the...
5
by: HotRod | last post by:
I am new to this so please go easy. We currently have some students doing some work on some web based tracking documents for us. They are currently using VB .net to develop what we requested....
16
by: negrito | last post by:
I need help to create this program: This program will take user input in the folowing order: 1.number of tickets sold. 2.percentage of ticket revenue which goes to administrative costs.This input...
0
by: didebugs | last post by:
Hi All, I started this VB project pretty close to a month ago. Truthfully, I feel I had no business doing it because it was way over my head, but I have accomplished much since I started. I am...
7
by: Chad | last post by:
The program: #include <stdio.h> void hello(void) { printf("hello \n"); } void hi(void) { printf("hi \n");
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.