AngryHelpneed some really quick help

Posts 1–4 of 4 · Page 1 of 1
need some really quick help
1. Create a class called ValentinesDay

2. Declare the following 6 variables, choosing the appropriate data type. Must use at least one of each data type listed here: String, int, double, char, boolean [2 pts]

datesName
gender (must be single character, m=male, or f=female)
restaurauntName
numberOfRoses
totalSpent
feelingLucky

3. Using the Scanner class, prompt the user to enter the values for ALL the variables. [2 pt] (Note: If you decide to just hard-code the values only and not read keyboard input, then you can earn 1 point)

4. Print all the info about your Album to the screen, similarly as follows [1 pt]

Example Interaction with Program: (the blue text represents keyboard input)
What is your dates name?
Oprah
What gender is your date?
f
Where are you taking your date?
McDonalds
How many roses are you bringing?
1
How much do you plan on spending?
12.50
Are you feeling lucky?
true

Example Output:
------------------------------------
My Valentines Day Details:
-------------------------------------
Name: Oprah
Gender: f
Place: McDonalds
Number of Roses: 1
Total Spent: $12.50
Got Lucky: true
-------------------------------------

here is what i have so far....sorry i dont post in correct format


import java.util.Scanner;
import javax.swing.JOptionPane;

public class VelentinesDate {

public static void main(String[] args)
{

Scanner keyboard = new Scanner(System.in);
double totalSpent;
int numberOfRoses ;
char ;
String datesName1, restaurantName ;



System.out.println("What is your dates name?");
datesName1 = keyboard.next();
System.out.println("What gender is your date?");

System.out.println("Where are you taking your date?");
restaurantName = keyboard.next();
System.out.println("How many roses are you bringing?");
numberOfRoses = keyboard.nextInt();
System.out.println("How much do you plan on spending?");
totalSpent = keyboard.nextDouble();

Boolean lucky = true ;



System.out.println("Are you feeling lucky?");

}


}
Assuming that, that is homework, you should at least try to understand what that code does, well anyways,
here's teh codes

ValentinesDay.java
Code:
import java.util.Scanner;
//import javax.swing.JOptionPane;

public class ValentinesDate {

	public static void main(String[] args)
	{
		//using at least one of each type listed below:
		//String used 4 times
		//int used once
		//double used once
		//char used once
		//boolean used once
		Scanner keyboard = new Scanner(System.in);
		double totalSpent;
		int numberOfRoses ;
		char gender;
		boolean lucky;
		String datesName1, restaurantName, feelinglucky ;

		System.out.println("What is your dates name?");
		datesName1 = keyboard.next();
		System.out.println("What gender is your date?");
		String sGender = keyboard.next();
		gender = sGender.charAt(0);
		System.out.println("Where are you taking your date?");
		restaurantName = keyboard.next();
		System.out.println("How many roses are you bringing?");
		numberOfRoses = keyboard.nextInt();
		System.out.println("How much do you plan on spending?");
		totalSpent = keyboard.nextDouble();
		System.out.println("Are you feeling lucky?");
		feelinglucky = keyboard.next();
		
		if (feelinglucky.equals("true"))
			lucky=true;
		else
			lucky=false;
		
		System.out.println("Name: "+datesName1);
		System.out.println("Gender: "+gender);
		System.out.println("Place: "+restaurantName);
		System.out.println("Number of Roses: "+numberOfRoses);
		System.out.println("Total Spent: $"+totalSpent);
		System.out.println("Got Lucky: "+lucky);
	}
}
Example Usage:

Input:

What is your dates name?
Oprah
What gender is your date?
f
Where are you taking your date?
McDonalds
How many roses are you bringing?
1
How much do you plan on spending?
12,50 //had to use the comma , cuz in germany we have different conventions
Are you feeling lucky?
true

Output:

Name: Oprah
Gender: f
Place: McDonalds
Number of Roses: 1
Total Spent: $12.5
Got Lucky: true


---------- Post added at 08:04 PM ---------- Previous post was at 08:02 PM ----------

I do not like how it is programmed since it's forbidden to be more object oriented :S I would put all that input and output functions into seperate methods, but .. ye
thats pretty cool thanks man...but i figured it out before you got to it...
Good for you :=)
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us