Hello, I\'m fairly new to the Java language and I\'m trying to write code for th
ID: 3915306 • Letter: H
Question
Hello, I'm fairly new to the Java language and I'm trying to write code for the scenario below:
//Senario: "Deciding What To Have For Dinner."
//Author: xxxxx
//Date: xxxxx
//Pseudo Code:
//If the date is January 31st is true (boolean): "I'll let my friends take me out to //dinner!" If boolean returns false, continue on to delivery times.
//Else If delivery time of pizza is less than delivery time of burgers is true (boolean): "I think I'll //order pizza!" If boolean returns false, continue to print final string.
//Else If delivery time of burgers is less than delivery time of pizza is true (boolean): "I think I'll //order pizza!" If boolean returns false, the last
//Else delivery time of pizza and delivery time of burgers is exactly the same is true //(boolean): "I'll order both!"
I tried doing some code for Processing (Java). I'm sure this is all wrong, but I think it might help out somehow.
PImage pizza;
PImage burgers;
PImage pizzaAndBurgers;
int month;
int day of month;
int birthday ('month' and 'day of month')
int pizza;
int burger;
int minutes;
int delivery time (in minutes (0 to 60 minutes)) of pizza;
int delivery time (in minutes (0 to 60 minutes)) of burgers;
void setup() {
clear();
size (800,600);
PImage: pizza;
PImage: burgers;
PImage: pizzaAndBurgers;
month=int(random(months 1 through 12));
dayOfMonth=(random(1 through 31));
birthday=month(1(January)) AND dayOfMonth(31);
pizza=p;
burger=b;
minutes=min;
pizzaDelivery=min(random(0 through 60);
burgerDelivery=min(random(0 through 60);
if birthday; {
return "I'll let me friends take me out to dinner!"}
else if pizzaDelivery < burgerDelivery {
return "I'll order pizza!"}
else if burgerDelivery < pizzaDelivery {
return "I'll order burgers!"}
else pizzaDelivery == burgerDelivery{
return "I'll order both!"}
Wondering if you can help!
Thank you!
Explanation / Answer
Please find the code below in Java.
CODE
=================
import java.util.Calendar;
import java.util.Date;
public class tester
{
public static void main(String[] args) {
int pizzaDeliveryTime = 30;
int burgerDeliveryTime = 20;
Date todayDate = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(todayDate);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH);
if (month == 1 && day == 31) {
System.out.println("I'll let my friends take me out to dinner!");
} else {
if(pizzaDeliveryTime < burgerDeliveryTime) {
System.out.println("I think I'll order pizza!");
} else if(pizzaDeliveryTime > burgerDeliveryTime) {
System.out.println("I think I'll order burger!");
} else {
System.out.println("I think I'll order both!");
}
}
}
}
NOTE: I have hardcoded the burger and pizza delivery time. Youcan change it as per your wish. Moreover, you can also input their values from users using Scanner object in Java.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.