import java.util.*;
public class Hallmark
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
Card userCard;
boolean isInt = true;
int iUserInput;
int iInputCounter = 1;
String sSender = toPerson();
String sRecipient = fromPerson();
//menu
String sMenu = "Please select your card:" +
"\n\t1) Christmas" +
"\n\t2) Valentines" +
"\n\t3) Birthday" +
"\n\t4) Get well soon" +
"\n\t5) Anniversary" +
"\n\t6) New Baby" +
"\n\t7) Thank You" +
"\n\t8) Congratulations" +
"\n\t9) Blank Card\n";
//print menu
System.out.print(sMenu);
//confirm input
do
{
System.out.println("Please enter a valid choice");
try
{
iUserInput = console.nextInt();
if ((iUserInput >= 0) && (iUserInput <= 9))
{
//counter
iInputCounter--;
switch(iUserInput)
{
//christmas card
case 1: userCard = new Christmas();
break;
//valentines card
case 2: userCard = new Valentines();
break;
//birthday card
case 3: userCard = new Birthday();
break;
//getwellsoon card
case 4: userCard = new GetWellSoon();
break;
//anniversary card
case 5: userCard = new Anniversary();
break;
//newbaby card
case 6: userCard= new NewBaby();
break;
//thankyou card
case 7: userCard = new ThankYou();
break;
//congratulations card
case 8: userCard = new Congratulations();
break;
//blank card
default: userCard = new BlankCard();
break;
}
//generic information
userCard.make(sSender, sRecipient);
}
else
{
System.out.println("You have not entered a valid choice");
continue;
}
}
catch (InputMismatchException e)
{
System.out.println("You have entered an invalid input");
console.next();
continue;
}
}while(iInputCounter > 0);
}
public String toPerson()
{
System.out.println("Please enter your name");
String sSender = console.nextLine();
return sSender;
}
public String fromPerson()
{
System.out.println("Please enter recipients name");
String sRecipient = console.nextLine();
return sRecipient;
}
}
35 Replies - 1318 Views - Last Post: 02 February 2013 - 12:13 PM
#16
Re: Hallmark Problem [Please help]
Posted 31 January 2013 - 02:14 PM
#17
Re: Hallmark Problem [Please help]
Posted 31 January 2013 - 02:17 PM
#18
Re: Hallmark Problem [Please help]
Posted 31 January 2013 - 02:22 PM
*change Valentines with whatever card you want
public class Valentines extends Card
{
Birthday(String sSender, String sRecipient)
{
sRecipient = sRecipient;
sSender = sFrom;
}
public void makeCard()
{
System.out.println("christmas");
}
}
This is now giving me the error
Quote
File: G:\CISS111\Homework 2\Code\Valentines.java [line: 3]
Error: invalid method declaration; return type required
I tried switching it to void but then I realized that, would result in no value being returned would I want to return a String? Also, how the hello kitty would I go about making a semi-card like looking Sring to go along with this(a loop of some type)? Maybe my variables are wrong or something?
This post has been edited by k3y: 31 January 2013 - 02:26 PM
#19
Re: Hallmark Problem [Please help]
Posted 31 January 2013 - 02:24 PM
#20
Re: Hallmark Problem [Please help]
Posted 31 January 2013 - 02:33 PM
Quote
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 11]
Error: non-static method toPerson() cannot be referenced from a static context
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 12]
Error: non-static method fromPerson() cannot be referenced from a static context
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 45]
Error: constructor Christmas in class Christmas cannot be applied to given types;
required: java.lang.String,java.lang.String
found: no arguments
reason: actual and formal argument lists differ in length
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 53]
Error: constructor Birthday in class Birthday cannot be applied to given types;
required: java.lang.String,java.lang.String
found: no arguments
reason: actual and formal argument lists differ in length
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 57]
Error: constructor GetWellSoon in class GetWellSoon cannot be applied to given types;
required: java.lang.String,java.lang.String
found: no arguments
reason: actual and formal argument lists differ in length
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 61]
Error: constructor Anniversary in class Anniversary cannot be applied to given types;
required: java.lang.String,java.lang.String
found: no arguments
reason: actual and formal argument lists differ in length
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 65]
Error: constructor NewBaby in class NewBaby cannot be applied to given types;
required: java.lang.String,java.lang.String
found: no arguments
reason: actual and formal argument lists differ in length
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 69]
Error: constructor ThankYou in class ThankYou cannot be applied to given types;
required: java.lang.String,java.lang.String
found: no arguments
reason: actual and formal argument lists differ in length
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 73]
Error: constructor Congratulations in class Congratulations cannot be applied to given types;
required: java.lang.String,java.lang.String
found: no arguments
reason: actual and formal argument lists differ in length
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 77]
Error: constructor BlankCard in class BlankCard cannot be applied to given types;
required: java.lang.String,java.lang.String
found: no arguments
reason: actual and formal argument lists differ in length
File: G:\CISS111\Homework 2\Code\Hallmark.java [line: 81]
Error: cannot find symbol
symbol: method make(java.lang.String,java.lang.String)
location: variable userCard of type Card
File: G:\CISS111\Homework 2\Code\Valentines.java [line: 6]
Error: cannot find symbol
symbol: variable sFrom
location: class Valentines
Hallmark/Main
import java.util.*;
public class Hallmark
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
Card userCard;
boolean isInt = true;
int iUserInput;
int iInputCounter = 1;
String sSender = toPerson();
String sRecipient = fromPerson();
//menu
String sMenu = "Please select your card:" +
"\n\t1) Christmas" +
"\n\t2) Valentines" +
"\n\t3) Birthday" +
"\n\t4) Get well soon" +
"\n\t5) Anniversary" +
"\n\t6) New Baby" +
"\n\t7) Thank You" +
"\n\t8) Congratulations" +
"\n\t9) Blank Card\n";
//print menu
System.out.print(sMenu);
//confirm input
do
{
System.out.println("Please enter a valid choice");
try
{
iUserInput = console.nextInt();
if ((iUserInput >= 0) && (iUserInput <= 9))
{
//counter
iInputCounter--;
switch(iUserInput)
{
//christmas card
case 1: userCard = new Christmas();
break;
//valentines card
case 2: userCard = new Valentines();
break;
//birthday card
case 3: userCard = new Birthday();
break;
//getwellsoon card
case 4: userCard = new GetWellSoon();
break;
//anniversary card
case 5: userCard = new Anniversary();
break;
//newbaby card
case 6: userCard= new NewBaby();
break;
//thankyou card
case 7: userCard = new ThankYou();
break;
//congratulations card
case 8: userCard = new Congratulations();
break;
//blank card
default: userCard = new BlankCard();
break;
}
//generic information
userCard.make(sSender, sRecipient);
}
else
{
System.out.println("You have not entered a valid choice");
continue;
}
}
catch (InputMismatchException e)
{
System.out.println("You have entered an invalid input");
console.next();
continue;
}
}while(iInputCounter > 0);
}
public String toPerson()
{
System.out.println("Please enter your name");
String sSender = console.nextLine();
return sSender;
}
public String fromPerson()
{
System.out.println("Please enter recipients name");
String sRecipient = console.nextLine();
return sRecipient;
}
}
Card
public abstract class Card
{
String sRecipient;
String sSender;
public abstract void makeCard();
}
Sample card class
public class Christmas extends Card
{
Christmas(String sSender, String sRecipient)
{
sRecipient = sRecipient;
sSender = sSender;
}
public void makeCard()
{
System.out.println("christmas");
}
}
Maybe I am assigning the wrong value here?
sRecipient = sRecipient;
sSender = sSender;
Maybe I need to pass some value to the object?
case 1: userCard = new Christmas(value?);
break;
Also to show that you really have been helping me learn, after I frankenstein this code together, I will break it down and explain how it works to show that I truly do know what is happening(as best as I can
This post has been edited by k3y: 31 January 2013 - 02:45 PM
#21
Re: Hallmark Problem [Please help]
Posted 31 January 2013 - 02:45 PM
The compiler output for the other errors is pretty clear, you can probably dope it out.
(I'll be glad to help out, but I'm going to be tied up from now until quite late tonight)
#22
Re: Hallmark Problem [Please help]
Posted 01 February 2013 - 11:33 AM
Hallmark/Main
import java.util.*;
public class Hallmark
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
Card userCard;
boolean isInt = true;
int iUserInput;
int iInputCounter = 1;
String sSender = toPerson();
String sRecipient = fromPerson();
//menu
String sMenu = "Please select your card:" +
"\n\t1) Christmas" +
"\n\t2) Valentines" +
"\n\t3) Birthday" +
"\n\t4) Get well soon" +
"\n\t5) Anniversary" +
"\n\t6) New Baby" +
"\n\t7) Thank You" +
"\n\t8) Congratulations" +
"\n\t9) Blank Card\n";
//print menu
System.out.print(sMenu);
//confirm input
do
{
System.out.println("Please enter a valid choice");
try
{
iUserInput = console.nextInt();
if ((iUserInput >= 0) && (iUserInput <= 9))
{
//counter
iInputCounter--;
switch(iUserInput)
{
//christmas card
case 1: userCard = new Christmas(sSender, sRecipient);
break;
//valentines card
case 2: userCard = new Valentines(sSender, sRecipient);
break;
//birthday card
case 3: userCard = new Birthday(sSender, sRecipient);
break;
//getwellsoon card
case 4: userCard = new GetWellSoon(sSender, sRecipient);
break;
//anniversary card
case 5: userCard = new Anniversary(sSender, sRecipient);
break;
//newbaby card
case 6: userCard= new NewBaby(sSender, sRecipient);
break;
//thankyou card
case 7: userCard = new ThankYou(sSender, sRecipient);
break;
//congratulations card
case 8: userCard = new Congratulations(sSender, sRecipient);
break;
//blank card
default: userCard = new BlankCard(sSender, sRecipient);
break;
}
//generic information
userCard.makeCard();
}
else
{
System.out.println("You have not entered a valid choice");
continue;
}
}
catch (InputMismatchException e)
{
System.out.println("You have entered an invalid input");
console.next();
continue;
}
}while(iInputCounter > 0);
}
public static String toPerson()
{
System.out.println("Please enter your name");
String sSender = console.nextLine();
return sSender;
}
public static String fromPerson()
{
System.out.println("Please enter recipients name");
String sRecipient = console.nextLine();
return sRecipient;
}
}
Card
public abstract class Card
{
String sRecipient;
String sSender;
public abstract void makeCard();
}
Sample christmas card (replace w/ whatever)
public class Christmas extends Card
{
Christmas(String sSender, String sRecipient)
{
sRecipient = sRecipient;
sSender = sSender;
}
public void makeCard()
{
System.out.println("christmas");
System.out.println(sRecipient);
System.out.println(sSender);
}
}
The code seems to run however; If I enter a christmas card it returns 2 null strings. I'm not sure where I am assigning the wrong values to the class, any ideas?
This post has been edited by k3y: 01 February 2013 - 02:47 PM
#23
Re: Hallmark Problem [Please help]
Posted 01 February 2013 - 02:50 PM
Any hints, suggestions are welcome. Thank you.
public class Valentines extends Card
{
Valentines(String sSender, String sRecipient)
{
sRecipient = sRecipient;
sSender = sSender;
}
public void makeCard()
{
System.out.println("Happy Valentines Day <3!");
System.out.println("to " + sRecipient);
int iStringLength = sRecipient.length();
for(int x = 0; x < iStringLength; x++)
{
if(x % 2 == 0)
{
System.out.print("x");
}
else
{
System.out.print("o");
}
}
System.out.println("from" + sSender);
System.out.println("to" + sRecipient);
}
}
Maybe I need more parameters?
This post has been edited by k3y: 01 February 2013 - 02:57 PM
#24
Re: Hallmark Problem [Please help]
Posted 01 February 2013 - 03:06 PM
The local variables will get garbage collected some time after the constructor has returned
public class Christmas extends Card
{
Christmas(String sSender, String sRecipient) //Local variables are sSender and sRecipient
{
sRecipient = sRecipient; //Setting the variable to itself
sSender = sSender; //Setting the variable to itself
this.sRecipient = sRecipient; //Using the instance variable inherited from Card
this.sSender = sSender; //Using the instance variable inherited from Card
}
public void makeCard()
{
System.out.println("christmas");
System.out.println(sRecipient);
System.out.println(sSender);
}
}
#25
Re: Hallmark Problem [Please help]
Posted 01 February 2013 - 03:12 PM
#26
Re: Hallmark Problem [Please help]
Posted 01 February 2013 - 04:08 PM
/*
* 1) Your program should have at least 9 classes in it that inherit from the abstract card class. (1 for each type of card) x
* 2) Your program should asks the user who the card is for and who it is from. x
* 3) It should also ask them what type of card they would like to create, by giving the user a menu to choose from? x
* 4) If it is a birthday card, it also asks how old the recipient is. x
* 5) If it is a blank card then it asks what personal message the sender would like to include. x
* 6) If it is a Valentine's day card it personalizes the card by adding XOs to the end of the card (hugs and kisses) based on the length of the recipient's name. x
*/
import java.util.*;
public class Hallmark
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
// variable declaration
boolean isInt = true;
Card userCard;
int iUserInput;
int iInputCounter = 1;
String sSender = toPerson();
String sRecipient = fromPerson();
//menu, point 3
String sMenu = "Please select your card:" +
"\n\t1) Christmas" +
"\n\t2) Valentines" +
"\n\t3) Birthday" +
"\n\t4) Get well soon" +
"\n\t5) Anniversary" +
"\n\t6) New Baby" +
"\n\t7) Thank You" +
"\n\t8) Congratulations" +
"\n\t9) Blank Card\n";
//print menu
System.out.print(sMenu);
//confirm input
do
{
System.out.println("Please enter a valid choice");
try
{
iUserInput = console.nextInt();
if ((iUserInput >= 0) && (iUserInput <= 9))
{
//counter
iInputCounter--;
switch(iUserInput)
{
//christmas card, point 1
case 1:
userCard = new Christmas(sSender, sRecipient);
break;
//valentines card, point 1
case 2:
userCard = new Valentines(sSender, sRecipient);
break;
//birthday card, point 1
case 3:
int iAge = agePerson();
userCard = new Birthday(sSender, sRecipient, iAge);
break;
//getwellsoon card, point 1
case 4:
userCard = new GetWellSoon(sSender, sRecipient);
break;
//anniversary card, point 1
case 5:
userCard = new Anniversary(sSender, sRecipient);
break;
//newbaby card, point 1
case 6:
userCard= new NewBaby(sSender, sRecipient);
break;
//thankyou card, point 1
case 7:
userCard = new ThankYou(sSender, sRecipient);
break;
//congratulations card, point 1
case 8:
userCard = new Congratulations(sSender, sRecipient);
break;
//blank card, point 1
default:
String sMessageToRecipient = sMessage();
userCard = new BlankCard(sSender, sRecipient, sMessageToRecipient);
break;
}
//generic information
userCard.makeCard();
}
else
{
System.out.println("You have not entered a valid choice");
continue;
}
}
catch (InputMismatchException e)
{
System.out.println("You have entered an invalid input");
console.next();
continue;
}
}while(iInputCounter > 0);
}
//point 2
public static String toPerson()
{
System.out.println("Please enter your name");
String sSender = console.nextLine();
return sSender;
}
//point 2
public static String fromPerson()
{
System.out.println("Please enter recipients name");
String sRecipient = console.nextLine();
return sRecipient;
}
//point 4
public static int agePerson()
{
System.out.println("Please enter recipients age");
int iAge = console.nextInt();
return iAge;
}
//point 5
public static String sMessage()
{
System.out.println("Please enter your message to the recipient: ");
String sMessageToRecipient = console.nextLine();
return sMessageToRecipient;
}
}
blankcard class
public class BlankCard extends Card
{
BlankCard(String sSender, String sRecipient, String sMessageToRecipient)
{
this.sRecipient = sRecipient;
this.sSender = sSender;
this.sMessageToRecipient = sMessageToRecipient;
}
public void makeCard()
{
System.out.println("to " + sRecipient);
System.out.print("\n\n\n\n");
System.out.println("from: " + sSender);
System.out.println("MESSAGE:\n" + sMessageToRecipient);
}
}
Card class
public abstract class Card
{
String sRecipient;
String sSender;
String sMessageToRecipient;
int iAge;
public abstract void makeCard();
}
Is it because String is technically not a primitive data type?
EDIT: Message ** not method
This post has been edited by k3y: 01 February 2013 - 04:19 PM
#27
Re: Hallmark Problem [Please help]
Posted 01 February 2013 - 04:14 PM
Quote
What exactly are you talking about? You are not having a user generate a method (wtf), and you are certainly not returning a method anywhere
#28
Re: Hallmark Problem [Please help]
Posted 01 February 2013 - 04:19 PM
#29
Re: Hallmark Problem [Please help]
Posted 01 February 2013 - 05:11 PM
Quote
It will read "9" when you do nextInt() but there is still a newline character to be read
Your next nextLine() will therefore return an empty String because it will read the "\n" that was left over in the buffer
This post has been edited by CasiOo: 01 February 2013 - 05:11 PM
#30
Re: Hallmark Problem [Please help]
Posted 01 February 2013 - 05:28 PM
This post has been edited by k3y: 01 February 2013 - 05:34 PM
|
|

New Topic/Question
Reply





MultiQuote



|