I haven't programmed in Java in maybe 3 or 4 semesters. My data structures class isn't about Java programming, but Java is the language of choice to implement our programs. I feel so far behind because I don't remember a lot of it.
Oh the troubles of forgetfulness, haha. I can't even remember how to do copy constructors or what they are used for. Oh well, that's what the internet is for.
class Riel
{
private String height;
private int weight_pounds;
public Riel() //default constructor
{
height = "5'7"";
weight_pounds = 120;
}
public Riel(String new_height)
{
height = new_height;
weight_pounds = 120;
}
public Riel(int new_weight)
{
weight_pounds = new_weight;
height = "5'7"";
}
public Riel(int new_weight, String new_height)
{
weight_pounds = new_weight;
height = new_height;
}
public int getWeight()
{
return weight_pounds;
}
public String getHeight()
{
return height;
}
}
//main function
import java.util.*;
public class RielisCoolium
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
Riel info = new Riel();
String choice;
boolean coolness;
System.out.println("Riel's height is " + info.getHeight());
System.out.println("Riel's weight is " + info.getWeight());
System.out.println("Is Riel cool?");
choice = keyboard.nextLine();
if (choice == "Yes" || "yes")
{
coolness = true;
}
else if (choice == "No" || "no")
{
coolness = false;
}
else
{
System.out.println("You have entered an incorrect response. Please go away.");
}
}
}
//end
No comments:
Post a Comment