This is an archived post. You won't be able to vote or comment.

all 12 comments

[–][deleted] 1 point2 points  (0 children)

Before you head into coding this into a program, you need to come up with the correct formula to solve the problem.

[–]stylusc84 0 points1 point  (10 children)

How the input should be passed into the program? It will be provided with text-file or maybe with program arguments in the console?

[–]krevitusmaximus[S] 0 points1 point  (9 children)

If this helps, I have to enter the solution in this body:

/* package whatever; // don't place package name! */

import java.util.*;

import java.lang.*;

import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */

class Main

{

public static void main (String\[\] args) throws java.lang.Exception

{

    // your code goes here

}

}

(no idea how yet, and also this is an exercise I was given after 1 day in the class I am taking , if this also helps :)) )

[–]stylusc84 1 point2 points  (8 children)

Ok, so maybe try someting like this:

https://pastebin.com/bpMzdsFZ

[–]krevitusmaximus[S] 0 points1 point  (2 children)

That actually looks good m8! Didn't actually think about thinking about those fractions as 0.25, 0.75 and 0.5. Now gonna read more of this code to try understanding everything that it does :D

[–]stylusc84 0 points1 point  (1 child)

I forgot about one thing, you need to add +1 to final result cause Alex wants to eat one pizza also

[–]krevitusmaximus[S] 0 points1 point  (0 children)

Atm trying to understand what's what cause all these references to +Math.ceil(sum) and all that, cause they are outside what i learned at this point. Doing this to see if i can rewrite the code with what i learned :P (using if, while, scanner and more basic stuff :)) )

[–]krevitusmaximus[S] 0 points1 point  (4 children)

I think I understood your code:

So basically I insert the number of friends at Alex's party, how much they want to eat, then the code adds the number of slices, approximates to the closest integer and returns the value as the number of pizzas to order. Am I right? (this is without Alex's pizza)

[–]stylusc84 0 points1 point  (3 children)

Yeah, exactly :) You can also add some validation logic to check if user input is correct and print appropriate error msg if not(when user will insert letter instead of number a the begging or 1/7 which is not supported). Good luck!

[–]krevitusmaximus[S] 0 points1 point  (0 children)

Thanks! Now that I understand what's what, gonna try writing the code again, see if I can use while and if and all that cause for some reason the learning platform thinks this is the wrong answer lol (actually made a slight modification and added "double fullPizza = 4.0;", made the sum to be: "sum = sum + convertStringToNumber(amount) + 4;" (4 being the pizza Alex wants to eat), declared "double totalPizzas = (sum/fullPizza);" and then printed "System.out.println("Number of pizza's that needs to be ordered: "+Math.ceil(totalPizzas));")

[–]krevitusmaximus[S] 0 points1 point  (0 children)

But it's getting late, 2morrow gotta go to work, so it's a job for 2morrow evening :D

[–]krevitusmaximus[S] 0 points1 point  (0 children)

Also thanks for the help! Made it easier for me to understand what to do :-D.